@bento/checkbox 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ import {
2
+ Meta,
3
+ ArgTypes,
4
+ Story,
5
+ Controls,
6
+ Source,
7
+ } from '@storybook/addon-docs/blocks';
8
+
1
9
  # Checkbox
2
10
 
3
11
  The `@bento/checkbox` package provides accessible and customizable checkbox inputs. It exports the **CheckboxGroup** and **Checkbox** primitives, enabling you to build individual or groups of checkboxes with consistent keyboard navigation, focus management, and ARIA support. React Aria is used to ensure that the checkboxes are accessible to all users.
@@ -31,13 +39,15 @@ but is not available in that circumstance. |
31
39
  | `autoFocus` | `boolean` | No | Whether the element should receive focus on render. |
32
40
  | `isIndeterminate` | `boolean` | No | Whether the checkbox is in an indeterminate state. |
33
41
  | `isSelected` | `boolean` | No | Whether the checkbox is in a selected state. |
34
- | `label` | `ReactNode` | No | The label for the control. |
35
42
  | `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
36
43
  The exposed slot names of a component are available in the components documentation. |
37
- | `inputProps` | `DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>` | No | Props to pass to the underlying input element. |
38
- | `labelProps` | `DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>` | No | Props to pass to the label element. |
39
44
  | `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
40
45
  The main way you interact with the slot system as a consumer. |
46
+ | `ref` | `Ref<HTMLDivElement> \| LegacyRef<Component<CheckboxProps & Slots, any, any>>` | No | Allows getting a ref to the component instance.
47
+ Once the component unmounts, React will set `ref.current` to `null`
48
+ (or call the ref with `null` if you passed a callback ref).
49
+ @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
50
+ | `as` | `"div"` | No | |
41
51
 
42
52
  ### CheckboxGroup
43
53
 
@@ -50,19 +60,18 @@ The main way you interact with the slot system as a consumer. |
50
60
  | `isRequired` | `boolean` | No | Whether user input is required on the input before form submission. |
51
61
  | `isInvalid` | `boolean` | No | Whether the input value is invalid. |
52
62
  | `name` | `string` | No | The name of the input element, used when submitting an HTML form. |
53
- | `form` | `string` | No | The <form> element to associate the input with.
54
- The value of this attribute must be the id of a <form> in the same document. |
55
- | `description` | `string` | No | Description for the checkbox group. |
63
+ | `form` | `string` | No | The `<form>` element to associate the input with.
64
+ The value of this attribute must be the id of a `<form>` in the same document. |
56
65
  | `children` | `ReactNode` | No | Checkbox children. |
57
- | `errorMessage` | `ReactNode \| ((val: ValidationResult) => ReactNode)` | No | Error message for the checkbox group. |
58
66
  | `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
59
67
  The exposed slot names of a component are available in the components documentation. |
60
- | `labelProps` | `DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>` | No | Props to pass to the label element. |
61
- | `descriptionProps` | `DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>` | No | Props to pass to the description element. |
62
- | `errorMessageProps` | `DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>` | No | Props to pass to the error message element. |
63
- | `contentProps` | `DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>` | No | The props passed to the content element. |
64
68
  | `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
65
69
  The main way you interact with the slot system as a consumer. |
70
+ | `ref` | `Ref<HTMLDivElement> \| LegacyRef<Component<CheckboxGroupProps & Slots, any, any>>` | No | Allows getting a ref to the component instance.
71
+ Once the component unmounts, React will set `ref.current` to `null`
72
+ (or call the ref with `null` if you passed a callback ref).
73
+ @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
74
+ | `as` | `"div"` | No | |
66
75
 
67
76
  ## Data Attributes, Slot Map and Props
68
77
 
@@ -72,48 +81,43 @@ The following data attributes can be used to style and customize the `CheckboxGr
72
81
 
73
82
  #### `CheckboxGroup` Data Attributes
74
83
 
75
- | Attribute | Description |
76
- | --------------- | ------------------------------- |
77
- | `data-disabled` | Indicates the checkbox group is disabled |
78
- | `data-read-only` | Indicates the checkbox group is readonly |
79
- | `data-required` | Indicates the checkbox group is required |
80
- | `data-invalid` | Indicates the checkbox group is invalid |
84
+ | Attribute | Description | Example Values |
85
+ | ---------------- | ---------------------------------------- | -------------- |
86
+ | `data-disabled` | Indicates the checkbox group is disabled | "true" |
87
+ | `data-readonly` | Indicates the checkbox group is readonly | "true" |
88
+ | `data-required` | Indicates the checkbox group is required | "true" |
89
+ | `data-invalid` | Indicates the checkbox group is invalid | "true" |
81
90
 
82
91
  #### `Checkbox` Data Attributes
83
92
 
84
- | Attribute | Description |
85
- | --------------- | ------------------------------- |
86
- | `data-disabled` | Indicates the checkbox is disabled |
87
- | `data-read-only` | Indicates the checkbox is readonly |
88
- | `data-required` | Indicates the checkbox is required |
89
- | `data-invalid` | Indicates the checkbox is invalid |
90
- | `data-indeterminate` | Indicates the checkbox is in an indeterminate state |
91
- | `data-pressed` | Indicates the checkbox is being pressed |
92
- | `data-hovered` | Indicates the checkbox is hovered |
93
- | `data-focused` | Indicates the checkbox has focus |
94
- | `data-focus-visible` | Indicates focus should be visible |
95
- | `data-selected` | Indicates the checkbox is selected |
96
-
97
- ### Slot Map
98
-
99
- The `CheckboxGroup` and `Checkbox` primitives are built off of the `Control` and `ControlGroup` primitives, which provide a consisten set of slot values, as shown below.
100
-
101
- #### `CheckboxGroup` Slot Map
102
-
103
- | Slot Name | Description |
104
- | ------------------- | ---------------------------- |
105
- | `group.label` | Label for checkbox group |
106
- | `group.description` | Description for checkbox group|
107
- | `group.error` | Error message for checkbox group|
108
-
109
- #### `Checkbox` Slot Map
110
-
111
- | Slot Name | Description |
112
- | --------------- | -------------- |
113
- | `control.icon-checked` | Icon for checked checkbox |
114
- | `control.icon-unchecked` | Icon for unchecked checkbox |
115
- | `control.icon-indeterminate` | Icon for indeterminate checkbox |
116
- | `control.label` | Text for checkbox |
93
+ | Attribute | Description | Example Values |
94
+ | -------------------- | --------------------------------------------------- | -------------- |
95
+ | `data-disabled` | Indicates the checkbox is disabled | "true" |
96
+ | `data-readonly` | Indicates the checkbox is readonly | "true" |
97
+ | `data-required` | Indicates the checkbox is required | "true" |
98
+ | `data-invalid` | Indicates the checkbox is invalid | "true" |
99
+ | `data-indeterminate` | Indicates the checkbox is in an indeterminate state | "true" |
100
+ | `data-pressed` | Indicates the checkbox is being pressed | "true" |
101
+ | `data-hovered` | Indicates the checkbox is hovered | "true" |
102
+ | `data-focused` | Indicates the checkbox has focus | "true" |
103
+ | `data-focus-visible` | Indicates focus should be visible | "true" |
104
+ | `data-selected` | Indicates the checkbox is selected | "true" |
105
+
106
+ ### `CheckboxGroup` Slot Map
107
+
108
+ | Slot Name | Description |
109
+ | ------------- | ------------------------------ |
110
+ | `label` | Label for checkbox group |
111
+ | `description` | Description for checkbox group |
112
+ | `error` | Error for checkbox group |
113
+
114
+ ### `Checkbox` Slot Map
115
+
116
+ | Slot Name | Description |
117
+ | -------------------- | ------------------------------- |
118
+ | `icon-checked` | Icon for checked checkbox |
119
+ | `icon-unchecked` | Icon for unchecked checkbox |
120
+ | `icon-indeterminate` | Icon for indeterminate checkbox |
117
121
 
118
122
  ## Examples
119
123
 
@@ -168,12 +172,17 @@ The `CheckboxGroup` allows a user to select multiple items from a list of `Check
168
172
  /* v8 ignore next */
169
173
  import React from 'react';
170
174
  import { Checkbox, CheckboxGroup } from '@bento/checkbox';
175
+ import { Text } from '@bento/text';
176
+ import { FieldError } from '@bento/field-error';
171
177
 
172
178
  export function CheckboxGroupExample(args: React.ComponentProps<typeof CheckboxGroup>) {
173
179
  return (
174
- <CheckboxGroup label="Checkbox Group" name="checkbox-group-example" {...args}>
180
+ <CheckboxGroup name="checkbox-group-example" {...args}>
181
+ <Text slot="label">Checkbox Group</Text>
175
182
  <Checkbox value="checkbox-1">Checkbox 1</Checkbox>
176
183
  <Checkbox value="checkbox-2">Checkbox 2</Checkbox>
184
+ <Text slot="description">Select your options</Text>
185
+ <FieldError slot="error">This is an error message</FieldError>
177
186
  </CheckboxGroup>
178
187
  );
179
188
  }
@@ -187,12 +196,14 @@ The `CheckboxGroup` can also be used in a controlled manner, where you manage th
187
196
  /* v8 ignore next */
188
197
  import React, { useState } from 'react';
189
198
  import { Checkbox, CheckboxGroup } from '@bento/checkbox';
199
+ import { Text } from '@bento/text';
190
200
 
191
201
  export function CheckboxGroupControlledExample() {
192
202
  const [selectedValues, setSelectedValues] = useState<string[]>([]);
193
203
 
194
204
  return (
195
- <CheckboxGroup label="Checkbox Group" value={selectedValues} onChange={setSelectedValues}>
205
+ <CheckboxGroup value={selectedValues} onChange={setSelectedValues}>
206
+ <Text slot="label">Checkbox Group</Text>
196
207
  <Checkbox value="option1">Option 1</Checkbox>
197
208
  <Checkbox value="option2">Option 2</Checkbox>
198
209
  <Checkbox value="option3">Option 3</Checkbox>
@@ -209,6 +220,7 @@ The `CheckboxGroup` can also support an indeterminate state, which is useful whe
209
220
  /* v8 ignore next */
210
221
  import React, { useState } from 'react';
211
222
  import { Checkbox, CheckboxGroup } from '@bento/checkbox';
223
+ import { Text } from '@bento/text';
212
224
 
213
225
  export function CheckboxGroupIndeterminateExample() {
214
226
  const [checkedItems, setCheckedItems] = useState<Set<string>>(new Set());
@@ -254,7 +266,8 @@ export function CheckboxGroupIndeterminateExample() {
254
266
  }
255
267
 
256
268
  return (
257
- <CheckboxGroup label="Select Items" value={Array.from(checkedItems)}>
269
+ <CheckboxGroup value={Array.from(checkedItems)} data-value={Array.from(checkedItems)}>
270
+ <Text slot="label">Select Items</Text>
258
271
  <Checkbox
259
272
  name="select-all"
260
273
  value="select-all"
package/README.mdx CHANGED
@@ -1,4 +1,10 @@
1
- import { Meta, ArgTypes, Story, Controls, Source } from '@storybook/addon-docs/blocks';
1
+ import {
2
+ Meta,
3
+ ArgTypes,
4
+ Story,
5
+ Controls,
6
+ Source,
7
+ } from '@storybook/addon-docs/blocks';
2
8
  import * as Stories from './checkbox.stories.tsx';
3
9
  import CheckboxControlledExample from './examples/checkbox-controlled.tsx?raw';
4
10
  import CheckboxExample from './examples/checkbox.tsx?raw';
@@ -42,48 +48,43 @@ The following data attributes can be used to style and customize the `CheckboxGr
42
48
 
43
49
  #### `CheckboxGroup` Data Attributes
44
50
 
45
- | Attribute | Description |
46
- | --------------- | ------------------------------- |
47
- | `data-disabled` | Indicates the checkbox group is disabled |
48
- | `data-read-only` | Indicates the checkbox group is readonly |
49
- | `data-required` | Indicates the checkbox group is required |
50
- | `data-invalid` | Indicates the checkbox group is invalid |
51
+ | Attribute | Description | Example Values |
52
+ | ---------------- | ---------------------------------------- | -------------- |
53
+ | `data-disabled` | Indicates the checkbox group is disabled | "true" |
54
+ | `data-readonly` | Indicates the checkbox group is readonly | "true" |
55
+ | `data-required` | Indicates the checkbox group is required | "true" |
56
+ | `data-invalid` | Indicates the checkbox group is invalid | "true" |
51
57
 
52
58
  #### `Checkbox` Data Attributes
53
59
 
54
- | Attribute | Description |
55
- | --------------- | ------------------------------- |
56
- | `data-disabled` | Indicates the checkbox is disabled |
57
- | `data-read-only` | Indicates the checkbox is readonly |
58
- | `data-required` | Indicates the checkbox is required |
59
- | `data-invalid` | Indicates the checkbox is invalid |
60
- | `data-indeterminate` | Indicates the checkbox is in an indeterminate state |
61
- | `data-pressed` | Indicates the checkbox is being pressed |
62
- | `data-hovered` | Indicates the checkbox is hovered |
63
- | `data-focused` | Indicates the checkbox has focus |
64
- | `data-focus-visible` | Indicates focus should be visible |
65
- | `data-selected` | Indicates the checkbox is selected |
66
-
67
- ### Slot Map
68
-
69
- The `CheckboxGroup` and `Checkbox` primitives are built off of the `Control` and `ControlGroup` primitives, which provide a consisten set of slot values, as shown below.
70
-
71
- #### `CheckboxGroup` Slot Map
72
-
73
- | Slot Name | Description |
74
- | ------------------- | ---------------------------- |
75
- | `group.label` | Label for checkbox group |
76
- | `group.description` | Description for checkbox group|
77
- | `group.error` | Error message for checkbox group|
78
-
79
- #### `Checkbox` Slot Map
80
-
81
- | Slot Name | Description |
82
- | --------------- | -------------- |
83
- | `control.icon-checked` | Icon for checked checkbox |
84
- | `control.icon-unchecked` | Icon for unchecked checkbox |
85
- | `control.icon-indeterminate` | Icon for indeterminate checkbox |
86
- | `control.label` | Text for checkbox |
60
+ | Attribute | Description | Example Values |
61
+ | -------------------- | --------------------------------------------------- | -------------- |
62
+ | `data-disabled` | Indicates the checkbox is disabled | "true" |
63
+ | `data-readonly` | Indicates the checkbox is readonly | "true" |
64
+ | `data-required` | Indicates the checkbox is required | "true" |
65
+ | `data-invalid` | Indicates the checkbox is invalid | "true" |
66
+ | `data-indeterminate` | Indicates the checkbox is in an indeterminate state | "true" |
67
+ | `data-pressed` | Indicates the checkbox is being pressed | "true" |
68
+ | `data-hovered` | Indicates the checkbox is hovered | "true" |
69
+ | `data-focused` | Indicates the checkbox has focus | "true" |
70
+ | `data-focus-visible` | Indicates focus should be visible | "true" |
71
+ | `data-selected` | Indicates the checkbox is selected | "true" |
72
+
73
+ ### `CheckboxGroup` Slot Map
74
+
75
+ | Slot Name | Description |
76
+ | ------------- | ------------------------------ |
77
+ | `label` | Label for checkbox group |
78
+ | `description` | Description for checkbox group |
79
+ | `error` | Error for checkbox group |
80
+
81
+ ### `Checkbox` Slot Map
82
+
83
+ | Slot Name | Description |
84
+ | -------------------- | ------------------------------- |
85
+ | `icon-checked` | Icon for checked checkbox |
86
+ | `icon-unchecked` | Icon for unchecked checkbox |
87
+ | `icon-indeterminate` | Icon for indeterminate checkbox |
87
88
 
88
89
  ## Examples
89
90
 
package/dist/index.cjs CHANGED
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var React2 = require('react');
4
- var control = require('@bento/control');
4
+ var container = require('@bento/container');
5
+ var useDataAttributes = require('@bento/use-data-attributes');
5
6
  var icon = require('@bento/icon');
6
7
  var slots = require('@bento/slots');
7
8
  var useProps = require('@bento/use-props');
8
- var reactAria = require('react-aria');
9
+ var visuallyHidden = require('@bento/visually-hidden');
9
10
  var utils = require('@react-aria/utils');
11
+ var reactAria = require('react-aria');
10
12
  var reactStately = require('react-stately');
11
- var useDataAttributes = require('@bento/use-data-attributes');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
15
 
@@ -20,17 +21,11 @@ var CheckboxGroupStateContext = React2__default.default.createContext(null);
20
21
  // src/checkbox.tsx
21
22
  var Checkbox = slots.withSlots("BentoCheckbox", function Checkbox2(args) {
22
23
  const { props, apply } = useProps.useProps(args);
23
- const {
24
- isRequired = false,
25
- isIndeterminate = false,
26
- isDisabled: isDisabledProp = false,
27
- isSelected: isSelectedProp = false,
28
- isReadOnly: isReadOnlyProp = false
29
- } = props;
30
24
  const groupState = React2.useContext(CheckboxGroupStateContext);
31
25
  const ref = React2.useRef(null);
32
26
  const inputRef = utils.useObjectRef(React2.useMemo(() => utils.mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
33
- let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState ? reactAria.useCheckboxGroupItem(
27
+ const { isFocused, isFocusVisible, focusProps } = reactAria.useFocusRing();
28
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? reactAria.useCheckboxGroupItem(
34
29
  {
35
30
  ...props,
36
31
  // Value is optional for standalone checkboxes, but required for CheckboxGroup items;
@@ -39,80 +34,62 @@ var Checkbox = slots.withSlots("BentoCheckbox", function Checkbox2(args) {
39
34
  },
40
35
  groupState,
41
36
  inputRef
42
- ) : reactAria.useCheckbox(
43
- {
44
- ...props
45
- },
46
- reactStately.useToggleState(props),
47
- inputRef
48
- );
49
- const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;
37
+ ) : reactAria.useCheckbox(props, reactStately.useToggleState(props), inputRef);
38
+ const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
50
39
  const { hoverProps, isHovered } = reactAria.useHover({
51
40
  ...props,
52
41
  isDisabled: interactionDisabled
53
42
  });
54
- const { isFocused, isFocusVisible, focusProps } = reactAria.useFocusRing();
55
43
  return /* @__PURE__ */ React2__default.default.createElement(
56
- control.Control,
44
+ container.Container,
57
45
  {
58
- slot: "control",
59
- labelProps: utils.mergeProps(labelProps, hoverProps),
60
- inputProps: utils.mergeProps(inputProps, focusProps),
61
- label: props.children,
62
- inputRef,
63
- "aria-checked": isIndeterminate ? "mixed" : void 0,
64
- ...apply(props, ["isReadOnly", "isSelected", "isIndeterminate", "isDisabled", "value", "autoFocus"]),
46
+ as: "label",
47
+ "aria-checked": props.isIndeterminate ? "mixed" : void 0,
48
+ ...apply(utils.mergeProps(labelProps, hoverProps)),
65
49
  ...useDataAttributes.useDataAttributes({
66
- selected: isSelected || isSelectedProp,
50
+ selected: isSelected,
67
51
  pressed: isPressed,
68
52
  hovered: isHovered,
69
53
  focused: isFocused,
70
54
  focusVisible: isFocusVisible,
71
55
  disabled: interactionDisabled,
72
- readOnly: isReadOnly || isReadOnlyProp,
56
+ readonly: isReadOnly,
73
57
  invalid: isInvalid,
74
- required: isRequired,
75
- indeterminate: isIndeterminate
58
+ required: props.isRequired,
59
+ indeterminate: props.isIndeterminate
76
60
  })
77
61
  },
78
- isIndeterminate ? /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-indeterminate", icon: "checkboxIndeterminate" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2__default.default.createElement("rect", { x: "6", y: "11", width: "12", height: "2", fill: "currentColor" }))) : isSelected ? /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-checked", icon: "checkboxChecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2__default.default.createElement("path", { d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z", fill: "currentColor" }))) : /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-unchecked", icon: "checkboxUnchecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { width: 24, height: 24, "aria-hidden": "true" }, /* @__PURE__ */ React2__default.default.createElement("rect", { x: 4, y: 4, width: 16, height: 16, rx: 3, fill: "none", stroke: "gray", strokeWidth: 2 })))
62
+ /* @__PURE__ */ React2__default.default.createElement(visuallyHidden.VisuallyHidden, null, /* @__PURE__ */ React2__default.default.createElement("input", { ...utils.mergeProps(inputProps, focusProps), ref: inputRef })),
63
+ props.isIndeterminate ? /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-indeterminate", icon: "checkboxIndeterminate" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2__default.default.createElement("rect", { x: "6", y: "11", width: "12", height: "2", fill: "currentColor" }))) : isSelected ? /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-checked", icon: "checkboxChecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2__default.default.createElement("path", { d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z", fill: "currentColor" }))) : /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-unchecked", icon: "checkboxUnchecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { width: 24, height: 24 }, /* @__PURE__ */ React2__default.default.createElement("rect", { x: 4, y: 4, width: 16, height: 16, rx: 3, fill: "none", stroke: "gray", strokeWidth: 2 }))),
64
+ props.children
79
65
  );
80
66
  });
81
67
  var CheckboxGroup = slots.withSlots("BentoCheckboxGroup", function CheckboxGroup2(args) {
82
- const { errorMessage, ...restArgs } = args;
83
- const { props, apply } = useProps.useProps(restArgs);
68
+ const { props, apply } = useProps.useProps(args);
84
69
  const state = reactStately.useCheckboxGroupState(props);
85
- const { children } = props;
86
70
  const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = reactAria.useCheckboxGroup(
87
- props,
71
+ { ...props, label: props.label ?? "Checkbox Group", description: props.description ?? "Description" },
88
72
  state
89
73
  );
90
- const displayedErrorMessage = React2.useMemo(
91
- function getErrorMessage() {
92
- return typeof errorMessage === "function" ? errorMessage(validationResult) : errorMessage || validationResult.validationErrors.join(", ");
93
- },
94
- [errorMessage, validationResult]
95
- );
96
- return /* @__PURE__ */ React2__default.default.createElement(
97
- control.ControlGroup,
74
+ return /* @__PURE__ */ React2__default.default.createElement(CheckboxGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2__default.default.createElement(
75
+ container.Container,
98
76
  {
99
- slot: "group",
100
- labelProps,
101
- descriptionProps,
102
- errorMessage: displayedErrorMessage,
103
- errorMessageProps,
104
- ...groupProps,
105
- ...apply(props, ["isInvalid", "isDisabled", "isReadOnly", "isRequired", "validationBehavior"]),
77
+ ...apply(groupProps),
106
78
  ...useDataAttributes.useDataAttributes({
107
79
  orientation: props.orientation || "vertical",
108
80
  invalid: state.isInvalid,
109
81
  disabled: state.isDisabled,
110
82
  readonly: state.isReadOnly,
111
83
  required: state.isRequired
112
- })
84
+ }),
85
+ slots: {
86
+ label: labelProps,
87
+ description: descriptionProps,
88
+ error: reactAria.mergeProps(errorMessageProps, validationResult)
89
+ }
113
90
  },
114
- /* @__PURE__ */ React2__default.default.createElement(CheckboxGroupStateContext.Provider, { value: state }, children)
115
- );
91
+ props.children
92
+ ));
116
93
  });
117
94
 
118
95
  exports.Checkbox = Checkbox;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/checkbox-group-state.tsx","../src/checkbox.tsx","../src/checkbox-group.tsx"],"names":["React","withSlots","Checkbox","useProps","useContext","useRef","useObjectRef","useMemo","mergeRefs","useCheckboxGroupItem","useCheckbox","useToggleState","useHover","useFocusRing","Control","mergeProps","useDataAttributes","Icon","CheckboxGroup","useCheckboxGroupState","useCheckboxGroup","ControlGroup"],"mappings":";;;;;;;;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4BA,uBAAA,CAAM,aAAA,CAAyC,IAAI,CAAA;;;ACmDrF,IAAM,QAAA,GAAWC,eAAA,CAAU,eAAA,EAAiB,SAASC,UAAS,IAAA,EAAqB;AACxF,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAIC,kBAAS,IAAI,CAAA;AACtC,EAAA,MAAM;AAAA,IACJ,UAAA,GAAa,KAAA;AAAA,IACb,eAAA,GAAkB,KAAA;AAAA,IAClB,YAAY,cAAA,GAAiB,KAAA;AAAA,IAC7B,YAAY,cAAA,GAAiB,KAAA;AAAA,IAC7B,YAAY,cAAA,GAAiB;AAAA,GAC/B,GAAI,KAAA;AAEJ,EAAA,MAAM,UAAA,GAAaC,kBAAW,yBAAyB,CAAA;AAEvD,EAAA,MAAM,GAAA,GAAMC,cAAyB,IAAI,CAAA;AACzC,EAAA,MAAM,QAAA,GAAWC,kBAAA,CAAaC,cAAA,CAAQ,MAAMC,gBAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAElG,EAAA,IAAI,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,YAAY,UAAA,EAAY,SAAA,EAAW,SAAA,EAAU,GAAI,UAAA,GACvFC,8BAAA;AAAA,IACE;AAAA,MACE,GAAG,KAAA;AAAA;AAAA;AAAA,MAGH,OAAQ,KAAA,CAAgD;AAAA,KAC1D;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACF,GACAC,qBAAA;AAAA,IACE;AAAA,MACE,GAAG;AAAA,KACL;AAAA,IACAC,4BAAe,KAAK,CAAA;AAAA,IACpB;AAAA,GACF;AAEJ,EAAA,MAAM,mBAAA,GAAsB,cAAA,IAAkB,UAA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zC,EAAA,MAAM,EAAE,UAAS,GAAI,KAAA;AACrB,EAAA,MAAM,EAAE,UAAA,EAAY,UAAA,EAAY,kBAAkB,iBAAA,EAAmB,GAAG,kBAAiB,GAAIC,0BAAA;AAAA,IAC3F,KAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,qBAAA,GAAwBb,cAAAA;AAAA,IAC5B,SAAS,eAAA,GAAkB;AACzB,MAAA,OAAO,OAAO,YAAA,KAAiB,UAAA,GAC3B,YAAA,CAAa,gBAAgB,IAC7B,YAAA,IAAgB,gBAAA,CAAiB,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAA;AAAA,IACjE,CAAA;AAAA,IACA,CAAC,cAAc,gBAAgB;AAAA,GACjC;AAEA,EAAA,uBACEP,uBAAAA,CAAA,aAAA;AAAA,IAACqB,oBAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,OAAA;AAAA,MACL,UAAA;AAAA,MACA,gBAAA;AAAA,MACA,YAAA,EAAc,qBAAA;AAAA,MACd,iBAAA;AAAA,MACC,GAAG,UAAA;AAAA,MACH,GAAG,MAAM,KAAA,EAAO,CAAC,aAAa,YAAA,EAAc,YAAA,EAAc,YAAA,EAAc,oBAAoB,CAAC,CAAA;AAAA,MAC7F,GAAGL,mCAAAA,CAAkB;AAAA,QACpB,WAAA,EAAa,MAAM,WAAA,IAAe,UAAA;AAAA,QAClC,SAAS,KAAA,CAAM,SAAA;AAAA,QACf,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM;AAAA,OACjB;AAAA,KAAA;AAAA,oBAEDhB,wBAAA,aAAA,CAAC,yBAAA,CAA0B,UAA1B,EAAmC,KAAA,EAAO,SAAQ,QAAS;AAAA,GAC9D;AAEJ,CAAC","file":"index.cjs","sourcesContent":["import React from 'react';\nimport { CheckboxGroupState } from 'react-stately';\n\nexport const CheckboxGroupStateContext = React.createContext<CheckboxGroupState | null>(null);\n","import React, { useContext, useRef, useMemo } from 'react';\nimport { Control, ControlProps } from '@bento/control';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { useFocusRing, useHover, type AriaCheckboxProps, useCheckboxGroupItem, useCheckbox } from 'react-aria';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useToggleState } from 'react-stately';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\n\nexport interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, keyof AriaCheckboxProps>> {\n /** The value of the checkbox, used when submitting an HTML form. */\n value?: string;\n\n /** The name of the checkbox. */\n name?: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the checkbox. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /** Whether the checkbox is required or not. */\n isRequired?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /**\n * Whether the checkbox is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n\n /** Whether the checkbox is in an indeterminate state. */\n isIndeterminate?: boolean;\n\n /** Whether the checkbox is in a selected state. */\n isSelected?: boolean;\n}\n\n/**\n * The `Checkbox` is a single checkbox option that can be selected by the user.\n *\n * @component\n * @param args - The props {@link CheckboxProps} passed to the Checkbox component.\n *\n * @public\n */\nexport const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: CheckboxProps) {\n const { props, apply } = useProps(args);\n const {\n isRequired = false,\n isIndeterminate = false,\n isDisabled: isDisabledProp = false,\n isSelected: isSelectedProp = false,\n isReadOnly: isReadOnlyProp = false\n } = props;\n\n const groupState = useContext(CheckboxGroupStateContext);\n\n const ref = useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n\n let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState\n ? useCheckboxGroupItem(\n {\n ...props,\n // Value is optional for standalone checkboxes, but required for CheckboxGroup items;\n // it's passed explicitly here to avoid typescript error (requires ignore)(recommendation from React Aria).\n value: (props as Required<Pick<typeof props, 'value'>>).value\n },\n groupState,\n inputRef\n )\n : useCheckbox(\n {\n ...props\n },\n useToggleState(props),\n inputRef\n );\n\n const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n\n return (\n <Control\n slot=\"control\"\n labelProps={mergeProps(labelProps, hoverProps)}\n inputProps={mergeProps(inputProps, focusProps)}\n label={props.children}\n inputRef={inputRef}\n aria-checked={isIndeterminate ? 'mixed' : undefined}\n {...apply(props, ['isReadOnly', 'isSelected', 'isIndeterminate', 'isDisabled', 'value', 'autoFocus'])}\n {...useDataAttributes({\n selected: isSelected || isSelectedProp,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: interactionDisabled,\n readOnly: isReadOnly || isReadOnlyProp,\n invalid: isInvalid,\n required: isRequired,\n indeterminate: isIndeterminate\n })}\n >\n {isIndeterminate ? (\n <Icon slot=\"icon-indeterminate\" icon=\"checkboxIndeterminate\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"6\" y=\"11\" width=\"12\" height=\"2\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"checkboxChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"checkboxUnchecked\">\n <svg width={24} height={24} aria-hidden=\"true\">\n <rect x={4} y={4} width={16} height={16} rx={3} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n </Control>\n );\n});\n","import React, { useMemo } from 'react';\nimport { useProps } from '@bento/use-props';\nimport { ControlGroup, ControlGroupProps } from '@bento/control';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { type ValidationResult } from '@react-types/shared';\nimport { AriaCheckboxGroupProps, useCheckboxGroup } from 'react-aria';\nimport { useCheckboxGroupState } from 'react-stately';\nimport { withSlots } from '@bento/slots';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\n\nexport interface CheckboxGroupProps\n extends AriaCheckboxGroupProps,\n Partial<Omit<ControlGroupProps, keyof AriaCheckboxGroupProps>> {\n /** The current value of the checkbox group (controlled). */\n value?: string[];\n\n /** The default value of the checkbox group (uncontrolled). */\n defaultValue?: string[];\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The <form> element to associate the input with.\n * The value of this attribute must be the id of a <form> in the same document.\n */\n form?: string;\n\n /** Description for the checkbox group. */\n description?: string;\n\n /** Checkbox children. */\n children?: React.ReactNode;\n\n /** Error message for the checkbox group. */\n errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);\n}\n\n/**\n * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.\n *\n * @component\n * @param {CheckboxGroupProps} args - The props passed to the CheckboxGroup component.\n *\n * @public\n */\nexport const CheckboxGroup = withSlots('BentoCheckboxGroup', function CheckboxGroup(args: CheckboxGroupProps) {\n const { errorMessage, ...restArgs } = args;\n const { props, apply } = useProps(restArgs);\n const state = useCheckboxGroupState(props);\n const { children } = props;\n const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(\n props,\n state\n );\n\n const displayedErrorMessage = useMemo(\n function getErrorMessage() {\n return typeof errorMessage === 'function'\n ? errorMessage(validationResult)\n : errorMessage || validationResult.validationErrors.join(', ');\n },\n [errorMessage, validationResult]\n );\n\n return (\n <ControlGroup\n slot=\"group\"\n labelProps={labelProps}\n descriptionProps={descriptionProps}\n errorMessage={displayedErrorMessage}\n errorMessageProps={errorMessageProps}\n {...groupProps}\n {...apply(props, ['isInvalid', 'isDisabled', 'isReadOnly', 'isRequired', 'validationBehavior'])}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n >\n <CheckboxGroupStateContext.Provider value={state}>{children}</CheckboxGroupStateContext.Provider>\n </ControlGroup>\n );\n});\n"]}
1
+ {"version":3,"sources":["../src/checkbox-group-state.tsx","../src/checkbox.tsx","../src/checkbox-group.tsx"],"names":["React","withSlots","Checkbox","useProps","useContext","useRef","useObjectRef","useMemo","mergeRefs","useFocusRing","useCheckboxGroupItem","useCheckbox","useToggleState","useHover","Container","mergeProps","useDataAttributes","VisuallyHidden","Icon","CheckboxGroup","useCheckboxGroupState","useCheckboxGroup"],"mappings":";;;;;;;;;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4BA,uBAAA,CAAM,aAAA,CAAyC,IAAI,CAAA;;;AC+CrF,IAAM,QAAA,GAAWC,eAAA,CAAU,eAAA,EAAiB,SAASC,UAAS,IAAA,EAAqB;AACxF,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAIC,kBAAS,IAAI,CAAA;AACtC,EAAA,MAAM,UAAA,GAAaC,kBAAW,yBAAyB,CAAA;AACvD,EAAA,MAAM,GAAA,GAAMC,cAAyB,IAAI,CAAA;AACzC,EAAA,MAAM,QAAA,GAAWC,kBA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AAgB;AAAA;AACvD,KAAA;AAAA,IAEC,KAAA,CAAM;AAAA,GAEX,CAAA;AAEJ,CAAC","file":"index.cjs","sourcesContent":["import React from 'react';\nimport { CheckboxGroupState } from 'react-stately';\n\nexport const CheckboxGroupStateContext = React.createContext<CheckboxGroupState | null>(null);\n","import React, { useContext, useRef, useMemo } from 'react';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { VisuallyHidden } from '@bento/visually-hidden';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useFocusRing, useHover, useCheckbox, useCheckboxGroupItem, type AriaCheckboxProps } from 'react-aria';\nimport { useToggleState } from 'react-stately';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\n\nexport interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {\n /** The value of the checkbox, used when submitting an HTML form. */\n value?: string;\n\n /** The name of the checkbox. */\n name?: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the checkbox. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /** Whether the checkbox is required or not. */\n isRequired?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /**\n * Whether the checkbox is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n\n /** Whether the checkbox is in an indeterminate state. */\n isIndeterminate?: boolean;\n\n /** Whether the checkbox is in a selected state. */\n isSelected?: boolean;\n}\n\n/**\n * The `Checkbox` is a single checkbox option that can be selected by the user.\n */\nexport const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: CheckboxProps) {\n const { props, apply } = useProps(args);\n const groupState = useContext(CheckboxGroupStateContext);\n const ref = useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n\n const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState\n ? useCheckboxGroupItem(\n {\n ...props,\n // Value is optional for standalone checkboxes, but required for CheckboxGroup items;\n // it's passed explicitly here to avoid typescript error (requires ignore)(recommendation from React Aria).\n value: (props as Required<Pick<typeof props, 'value'>>).value\n },\n groupState,\n inputRef\n )\n : useCheckbox(props, useToggleState(props), inputRef);\n\n const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n\n return (\n <Container\n as=\"label\"\n aria-checked={props.isIndeterminate ? 'mixed' : undefined}\n {...apply(mergeProps(labelProps, hoverProps))}\n {...useDataAttributes({\n selected: isSelected,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: interactionDisabled,\n readonly: isReadOnly,\n invalid: isInvalid,\n required: props.isRequired,\n indeterminate: props.isIndeterminate\n })}\n >\n <VisuallyHidden>\n <input {...mergeProps(inputProps, focusProps)} ref={inputRef} />\n </VisuallyHidden>\n\n {props.isIndeterminate ? (\n <Icon slot=\"icon-indeterminate\" icon=\"checkboxIndeterminate\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"6\" y=\"11\" width=\"12\" height=\"2\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"checkboxChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"checkboxUnchecked\">\n <svg width={24} height={24}>\n <rect x={4} y={4} width={16} height={16} rx={3} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n {props.children}\n </Container>\n );\n});\n","import React from 'react';\nimport { withSlots } from '@bento/slots';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useProps } from '@bento/use-props';\nimport { useCheckboxGroup, mergeProps, type AriaCheckboxGroupProps } from 'react-aria';\nimport { useCheckboxGroupState } from 'react-stately';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\nimport { useDataAttributes } from '@bento/use-data-attributes';\n\nexport interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {\n /** The current value of the checkbox group (controlled). */\n value?: string[];\n\n /** The default value of the checkbox group (uncontrolled). */\n defaultValue?: string[];\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n */\n form?: string;\n\n /** Checkbox children. */\n children?: React.ReactNode;\n}\n\n/**\n * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.\n */\nexport const CheckboxGroup = withSlots('BentoCheckboxGroup', function CheckboxGroup(args: CheckboxGroupProps) {\n const { props, apply } = useProps(args);\n const state = useCheckboxGroupState(props);\n const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(\n { ...props, label: props.label ?? 'Checkbox Group', description: props.description ?? 'Description' },\n state\n );\n\n return (\n <CheckboxGroupStateContext.Provider value={state}>\n <Container\n {...apply(groupProps)}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n slots={{\n label: labelProps,\n description: descriptionProps,\n error: mergeProps(errorMessageProps, validationResult)\n }}\n >\n {props.children}\n </Container>\n </CheckboxGroupStateContext.Provider>\n );\n});\n"]}
package/dist/index.d.cts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as _bento_slots from '@bento/slots';
2
2
  import React from 'react';
3
- import { ControlProps, ControlGroupProps } from '@bento/control';
3
+ import { ContainerProps } from '@bento/container';
4
4
  import { AriaCheckboxProps, AriaCheckboxGroupProps } from 'react-aria';
5
- import { ValidationResult } from '@react-types/shared';
6
5
 
7
- interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, keyof AriaCheckboxProps>> {
6
+ interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
8
7
  /** The value of the checkbox, used when submitting an HTML form. */
9
8
  value?: string;
10
9
  /** The name of the checkbox. */
@@ -31,15 +30,10 @@ interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, ke
31
30
  }
32
31
  /**
33
32
  * The `Checkbox` is a single checkbox option that can be selected by the user.
34
- *
35
- * @component
36
- * @param args - The props {@link CheckboxProps} passed to the Checkbox component.
37
- *
38
- * @public
39
33
  */
40
- declare const Checkbox: React.NamedExoticComponent<CheckboxProps & _bento_slots.Slots>;
34
+ declare const Checkbox: React.MemoExoticComponent<React.ComponentType<CheckboxProps & _bento_slots.Slots>>;
41
35
 
42
- interface CheckboxGroupProps extends AriaCheckboxGroupProps, Partial<Omit<ControlGroupProps, keyof AriaCheckboxGroupProps>> {
36
+ interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
43
37
  /** The current value of the checkbox group (controlled). */
44
38
  value?: string[];
45
39
  /** The default value of the checkbox group (uncontrolled). */
@@ -55,25 +49,16 @@ interface CheckboxGroupProps extends AriaCheckboxGroupProps, Partial<Omit<Contro
55
49
  /** The name of the input element, used when submitting an HTML form. */
56
50
  name?: string;
57
51
  /**
58
- * The <form> element to associate the input with.
59
- * The value of this attribute must be the id of a <form> in the same document.
52
+ * The `<form>` element to associate the input with.
53
+ * The value of this attribute must be the id of a `<form>` in the same document.
60
54
  */
61
55
  form?: string;
62
- /** Description for the checkbox group. */
63
- description?: string;
64
56
  /** Checkbox children. */
65
57
  children?: React.ReactNode;
66
- /** Error message for the checkbox group. */
67
- errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);
68
58
  }
69
59
  /**
70
60
  * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
71
- *
72
- * @component
73
- * @param {CheckboxGroupProps} args - The props passed to the CheckboxGroup component.
74
- *
75
- * @public
76
61
  */
77
- declare const CheckboxGroup: React.NamedExoticComponent<CheckboxGroupProps & _bento_slots.Slots>;
62
+ declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<CheckboxGroupProps & _bento_slots.Slots>>;
78
63
 
79
64
  export { Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as _bento_slots from '@bento/slots';
2
2
  import React from 'react';
3
- import { ControlProps, ControlGroupProps } from '@bento/control';
3
+ import { ContainerProps } from '@bento/container';
4
4
  import { AriaCheckboxProps, AriaCheckboxGroupProps } from 'react-aria';
5
- import { ValidationResult } from '@react-types/shared';
6
5
 
7
- interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, keyof AriaCheckboxProps>> {
6
+ interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
8
7
  /** The value of the checkbox, used when submitting an HTML form. */
9
8
  value?: string;
10
9
  /** The name of the checkbox. */
@@ -31,15 +30,10 @@ interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, ke
31
30
  }
32
31
  /**
33
32
  * The `Checkbox` is a single checkbox option that can be selected by the user.
34
- *
35
- * @component
36
- * @param args - The props {@link CheckboxProps} passed to the Checkbox component.
37
- *
38
- * @public
39
33
  */
40
- declare const Checkbox: React.NamedExoticComponent<CheckboxProps & _bento_slots.Slots>;
34
+ declare const Checkbox: React.MemoExoticComponent<React.ComponentType<CheckboxProps & _bento_slots.Slots>>;
41
35
 
42
- interface CheckboxGroupProps extends AriaCheckboxGroupProps, Partial<Omit<ControlGroupProps, keyof AriaCheckboxGroupProps>> {
36
+ interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
43
37
  /** The current value of the checkbox group (controlled). */
44
38
  value?: string[];
45
39
  /** The default value of the checkbox group (uncontrolled). */
@@ -55,25 +49,16 @@ interface CheckboxGroupProps extends AriaCheckboxGroupProps, Partial<Omit<Contro
55
49
  /** The name of the input element, used when submitting an HTML form. */
56
50
  name?: string;
57
51
  /**
58
- * The <form> element to associate the input with.
59
- * The value of this attribute must be the id of a <form> in the same document.
52
+ * The `<form>` element to associate the input with.
53
+ * The value of this attribute must be the id of a `<form>` in the same document.
60
54
  */
61
55
  form?: string;
62
- /** Description for the checkbox group. */
63
- description?: string;
64
56
  /** Checkbox children. */
65
57
  children?: React.ReactNode;
66
- /** Error message for the checkbox group. */
67
- errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);
68
58
  }
69
59
  /**
70
60
  * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
71
- *
72
- * @component
73
- * @param {CheckboxGroupProps} args - The props passed to the CheckboxGroup component.
74
- *
75
- * @public
76
61
  */
77
- declare const CheckboxGroup: React.NamedExoticComponent<CheckboxGroupProps & _bento_slots.Slots>;
62
+ declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<CheckboxGroupProps & _bento_slots.Slots>>;
78
63
 
79
64
  export { Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps };
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import React2, { useContext, useRef, useMemo } from 'react';
2
- import { Control, ControlGroup } from '@bento/control';
2
+ import { Container } from '@bento/container';
3
+ import { useDataAttributes } from '@bento/use-data-attributes';
3
4
  import { Icon } from '@bento/icon';
4
5
  import { withSlots } from '@bento/slots';
5
6
  import { useProps } from '@bento/use-props';
6
- import { useCheckboxGroupItem, useCheckbox, useHover, useFocusRing, useCheckboxGroup } from 'react-aria';
7
+ import { VisuallyHidden } from '@bento/visually-hidden';
7
8
  import { useObjectRef, mergeRefs, mergeProps } from '@react-aria/utils';
9
+ import { useFocusRing, useCheckboxGroupItem, useCheckbox, useHover, useCheckboxGroup, mergeProps as mergeProps$1 } from 'react-aria';
8
10
  import { useToggleState, useCheckboxGroupState } from 'react-stately';
9
- import { useDataAttributes } from '@bento/use-data-attributes';
10
11
 
11
12
  // src/checkbox.tsx
12
13
  var CheckboxGroupStateContext = React2.createContext(null);
@@ -14,17 +15,11 @@ var CheckboxGroupStateContext = React2.createContext(null);
14
15
  // src/checkbox.tsx
15
16
  var Checkbox = withSlots("BentoCheckbox", function Checkbox2(args) {
16
17
  const { props, apply } = useProps(args);
17
- const {
18
- isRequired = false,
19
- isIndeterminate = false,
20
- isDisabled: isDisabledProp = false,
21
- isSelected: isSelectedProp = false,
22
- isReadOnly: isReadOnlyProp = false
23
- } = props;
24
18
  const groupState = useContext(CheckboxGroupStateContext);
25
19
  const ref = useRef(null);
26
20
  const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
27
- let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState ? useCheckboxGroupItem(
21
+ const { isFocused, isFocusVisible, focusProps } = useFocusRing();
22
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? useCheckboxGroupItem(
28
23
  {
29
24
  ...props,
30
25
  // Value is optional for standalone checkboxes, but required for CheckboxGroup items;
@@ -33,80 +28,62 @@ var Checkbox = withSlots("BentoCheckbox", function Checkbox2(args) {
33
28
  },
34
29
  groupState,
35
30
  inputRef
36
- ) : useCheckbox(
37
- {
38
- ...props
39
- },
40
- useToggleState(props),
41
- inputRef
42
- );
43
- const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;
31
+ ) : useCheckbox(props, useToggleState(props), inputRef);
32
+ const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
44
33
  const { hoverProps, isHovered } = useHover({
45
34
  ...props,
46
35
  isDisabled: interactionDisabled
47
36
  });
48
- const { isFocused, isFocusVisible, focusProps } = useFocusRing();
49
37
  return /* @__PURE__ */ React2.createElement(
50
- Control,
38
+ Container,
51
39
  {
52
- slot: "control",
53
- labelProps: mergeProps(labelProps, hoverProps),
54
- inputProps: mergeProps(inputProps, focusProps),
55
- label: props.children,
56
- inputRef,
57
- "aria-checked": isIndeterminate ? "mixed" : void 0,
58
- ...apply(props, ["isReadOnly", "isSelected", "isIndeterminate", "isDisabled", "value", "autoFocus"]),
40
+ as: "label",
41
+ "aria-checked": props.isIndeterminate ? "mixed" : void 0,
42
+ ...apply(mergeProps(labelProps, hoverProps)),
59
43
  ...useDataAttributes({
60
- selected: isSelected || isSelectedProp,
44
+ selected: isSelected,
61
45
  pressed: isPressed,
62
46
  hovered: isHovered,
63
47
  focused: isFocused,
64
48
  focusVisible: isFocusVisible,
65
49
  disabled: interactionDisabled,
66
- readOnly: isReadOnly || isReadOnlyProp,
50
+ readonly: isReadOnly,
67
51
  invalid: isInvalid,
68
- required: isRequired,
69
- indeterminate: isIndeterminate
52
+ required: props.isRequired,
53
+ indeterminate: props.isIndeterminate
70
54
  })
71
55
  },
72
- isIndeterminate ? /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-indeterminate", icon: "checkboxIndeterminate" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("rect", { x: "6", y: "11", width: "12", height: "2", fill: "currentColor" }))) : isSelected ? /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-checked", icon: "checkboxChecked" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("path", { d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z", fill: "currentColor" }))) : /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-unchecked", icon: "checkboxUnchecked" }, /* @__PURE__ */ React2.createElement("svg", { width: 24, height: 24, "aria-hidden": "true" }, /* @__PURE__ */ React2.createElement("rect", { x: 4, y: 4, width: 16, height: 16, rx: 3, fill: "none", stroke: "gray", strokeWidth: 2 })))
56
+ /* @__PURE__ */ React2.createElement(VisuallyHidden, null, /* @__PURE__ */ React2.createElement("input", { ...mergeProps(inputProps, focusProps), ref: inputRef })),
57
+ props.isIndeterminate ? /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-indeterminate", icon: "checkboxIndeterminate" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("rect", { x: "6", y: "11", width: "12", height: "2", fill: "currentColor" }))) : isSelected ? /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-checked", icon: "checkboxChecked" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("path", { d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z", fill: "currentColor" }))) : /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-unchecked", icon: "checkboxUnchecked" }, /* @__PURE__ */ React2.createElement("svg", { width: 24, height: 24 }, /* @__PURE__ */ React2.createElement("rect", { x: 4, y: 4, width: 16, height: 16, rx: 3, fill: "none", stroke: "gray", strokeWidth: 2 }))),
58
+ props.children
73
59
  );
74
60
  });
75
61
  var CheckboxGroup = withSlots("BentoCheckboxGroup", function CheckboxGroup2(args) {
76
- const { errorMessage, ...restArgs } = args;
77
- const { props, apply } = useProps(restArgs);
62
+ const { props, apply } = useProps(args);
78
63
  const state = useCheckboxGroupState(props);
79
- const { children } = props;
80
64
  const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(
81
- props,
65
+ { ...props, label: props.label ?? "Checkbox Group", description: props.description ?? "Description" },
82
66
  state
83
67
  );
84
- const displayedErrorMessage = useMemo(
85
- function getErrorMessage() {
86
- return typeof errorMessage === "function" ? errorMessage(validationResult) : errorMessage || validationResult.validationErrors.join(", ");
87
- },
88
- [errorMessage, validationResult]
89
- );
90
- return /* @__PURE__ */ React2.createElement(
91
- ControlGroup,
68
+ return /* @__PURE__ */ React2.createElement(CheckboxGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2.createElement(
69
+ Container,
92
70
  {
93
- slot: "group",
94
- labelProps,
95
- descriptionProps,
96
- errorMessage: displayedErrorMessage,
97
- errorMessageProps,
98
- ...groupProps,
99
- ...apply(props, ["isInvalid", "isDisabled", "isReadOnly", "isRequired", "validationBehavior"]),
71
+ ...apply(groupProps),
100
72
  ...useDataAttributes({
101
73
  orientation: props.orientation || "vertical",
102
74
  invalid: state.isInvalid,
103
75
  disabled: state.isDisabled,
104
76
  readonly: state.isReadOnly,
105
77
  required: state.isRequired
106
- })
78
+ }),
79
+ slots: {
80
+ label: labelProps,
81
+ description: descriptionProps,
82
+ error: mergeProps$1(errorMessageProps, validationResult)
83
+ }
107
84
  },
108
- /* @__PURE__ */ React2.createElement(CheckboxGroupStateContext.Provider, { value: state }, children)
109
- );
85
+ props.children
86
+ ));
110
87
  });
111
88
 
112
89
  export { Checkbox, CheckboxGroup };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/checkbox-group-state.tsx","../src/checkbox.tsx","../src/checkbox-group.tsx"],"names":["React","Checkbox","withSlots","CheckboxGroup","useProps","useMemo","useDataAttributes"],"mappings":";;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4BA,MAAA,CAAM,aA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BC,OAAAA;AAAA,IAC5B,SAAS,eAAA,GAAkB;AACzB,MAAA,OAAO,OAAO,YAAA,KAAiB,UAAA,GAC3B,YAAA,CAAa,gBAAgB,IAC7B,YAAA,IAAgB,gBAAA,CAAiB,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAA;AAAA,IACjE,CAAA;AAAA,IACA,CAAC,cAAc,gBAAgB;AAAA,GACjC;AAEA,EAAA,uBACEL,MAAAA,CAAA,aAAA;AAAA,IAAC,YAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,OAAA;AAAA,MACL,UAAA;AAAA,MACA,gBAAA;AAAA,MACA,YAAA,EAAc,qBAAA;AAAA,MACd,iBAAA;AAAA,MACC,GAAG,UAAA;AAAA,MACH,GAAG,MAAM,KAAA,EAAO,CAAC,aAAa,YAAA,EAAc,YAAA,EAAc,YAAA,EAAc,oBAAoB,CAAC,CAAA;AAAA,MAC7F,GAAGM,iBAAAA,CAAkB;AAAA,QACpB,WAAA,EAAa,MAAM,WAAA,IAAe,UAAA;AAAA,QAClC,SAAS,KAAA,CAAM,SAAA;AAAA,QACf,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM;AAAA,OACjB;AAAA,KAAA;AAAA,oBAEDN,OAAA,aAAA,CAAC,yBAAA,CAA0B,UAA1B,EAAmC,KAAA,EAAO,SAAQ,QAAS;AAAA,GAC9D;AAEJ,CAAC","file":"index.js","sourcesContent":["import React from 'react';\nimport { CheckboxGroupState } from 'react-stately';\n\nexport const CheckboxGroupStateContext = React.createContext<CheckboxGroupState | null>(null);\n","import React, { useContext, useRef, useMemo } from 'react';\nimport { Control, ControlProps } from '@bento/control';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { useFocusRing, useHover, type AriaCheckboxProps, useCheckboxGroupItem, useCheckbox } from 'react-aria';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useToggleState } from 'react-stately';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\n\nexport interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, keyof AriaCheckboxProps>> {\n /** The value of the checkbox, used when submitting an HTML form. */\n value?: string;\n\n /** The name of the checkbox. */\n name?: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the checkbox. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /** Whether the checkbox is required or not. */\n isRequired?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /**\n * Whether the checkbox is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n\n /** Whether the checkbox is in an indeterminate state. */\n isIndeterminate?: boolean;\n\n /** Whether the checkbox is in a selected state. */\n isSelected?: boolean;\n}\n\n/**\n * The `Checkbox` is a single checkbox option that can be selected by the user.\n *\n * @component\n * @param args - The props {@link CheckboxProps} passed to the Checkbox component.\n *\n * @public\n */\nexport const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: CheckboxProps) {\n const { props, apply } = useProps(args);\n const {\n isRequired = false,\n isIndeterminate = false,\n isDisabled: isDisabledProp = false,\n isSelected: isSelectedProp = false,\n isReadOnly: isReadOnlyProp = false\n } = props;\n\n const groupState = useContext(CheckboxGroupStateContext);\n\n const ref = useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n\n let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState\n ? useCheckboxGroupItem(\n {\n ...props,\n // Value is optional for standalone checkboxes, but required for CheckboxGroup items;\n // it's passed explicitly here to avoid typescript error (requires ignore)(recommendation from React Aria).\n value: (props as Required<Pick<typeof props, 'value'>>).value\n },\n groupState,\n inputRef\n )\n : useCheckbox(\n {\n ...props\n },\n useToggleState(props),\n inputRef\n );\n\n const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n\n return (\n <Control\n slot=\"control\"\n labelProps={mergeProps(labelProps, hoverProps)}\n inputProps={mergeProps(inputProps, focusProps)}\n label={props.children}\n inputRef={inputRef}\n aria-checked={isIndeterminate ? 'mixed' : undefined}\n {...apply(props, ['isReadOnly', 'isSelected', 'isIndeterminate', 'isDisabled', 'value', 'autoFocus'])}\n {...useDataAttributes({\n selected: isSelected || isSelectedProp,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: interactionDisabled,\n readOnly: isReadOnly || isReadOnlyProp,\n invalid: isInvalid,\n required: isRequired,\n indeterminate: isIndeterminate\n })}\n >\n {isIndeterminate ? (\n <Icon slot=\"icon-indeterminate\" icon=\"checkboxIndeterminate\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"6\" y=\"11\" width=\"12\" height=\"2\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"checkboxChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"checkboxUnchecked\">\n <svg width={24} height={24} aria-hidden=\"true\">\n <rect x={4} y={4} width={16} height={16} rx={3} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n </Control>\n );\n});\n","import React, { useMemo } from 'react';\nimport { useProps } from '@bento/use-props';\nimport { ControlGroup, ControlGroupProps } from '@bento/control';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { type ValidationResult } from '@react-types/shared';\nimport { AriaCheckboxGroupProps, useCheckboxGroup } from 'react-aria';\nimport { useCheckboxGroupState } from 'react-stately';\nimport { withSlots } from '@bento/slots';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\n\nexport interface CheckboxGroupProps\n extends AriaCheckboxGroupProps,\n Partial<Omit<ControlGroupProps, keyof AriaCheckboxGroupProps>> {\n /** The current value of the checkbox group (controlled). */\n value?: string[];\n\n /** The default value of the checkbox group (uncontrolled). */\n defaultValue?: string[];\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The <form> element to associate the input with.\n * The value of this attribute must be the id of a <form> in the same document.\n */\n form?: string;\n\n /** Description for the checkbox group. */\n description?: string;\n\n /** Checkbox children. */\n children?: React.ReactNode;\n\n /** Error message for the checkbox group. */\n errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);\n}\n\n/**\n * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.\n *\n * @component\n * @param {CheckboxGroupProps} args - The props passed to the CheckboxGroup component.\n *\n * @public\n */\nexport const CheckboxGroup = withSlots('BentoCheckboxGroup', function CheckboxGroup(args: CheckboxGroupProps) {\n const { errorMessage, ...restArgs } = args;\n const { props, apply } = useProps(restArgs);\n const state = useCheckboxGroupState(props);\n const { children } = props;\n const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(\n props,\n state\n );\n\n const displayedErrorMessage = useMemo(\n function getErrorMessage() {\n return typeof errorMessage === 'function'\n ? errorMessage(validationResult)\n : errorMessage || validationResult.validationErrors.join(', ');\n },\n [errorMessage, validationResult]\n );\n\n return (\n <ControlGroup\n slot=\"group\"\n labelProps={labelProps}\n descriptionProps={descriptionProps}\n errorMessage={displayedErrorMessage}\n errorMessageProps={errorMessageProps}\n {...groupProps}\n {...apply(props, ['isInvalid', 'isDisabled', 'isReadOnly', 'isRequired', 'validationBehavior'])}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n >\n <CheckboxGroupStateContext.Provider value={state}>{children}</CheckboxGroupStateContext.Provider>\n </ControlGroup>\n );\n});\n"]}
1
+ {"version":3,"sources":["../src/checkbox-group-state.tsx","../src/checkbox.tsx","../src/checkbox-group.tsx"],"names":["React","Checkbox","withSlots","CheckboxGroup","useProps","Container","useDataAttributes","mergeProps"],"mappings":";;;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4BA,MAAA,CAAM,aAAA,CAAyC,IAAI,CAAA;;;AC+CrF,IAAM,QAAA,GAAW,SAAA,CAAU,eAAA,EAAiB,SAASC,UAAS,IAAA,EAAqB;AACxF,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAI,SAAS,IAAI,CAAA;AACtC,EAAA,MAAM,UAAA,GAAa,WAAW,yBAAyB,CAAA;AACvD,EAAA,MAAM,GAAA,GAAM,OAAyB,IAAI,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,YAAA,CAAa,OAAA,CAAQ,MAAM,UAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAe,YAAA,EAAa;AAE/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAW,UAAA,EAAY,UAAA,EAAY,SAAA,EAAU,GAAI,UAAA,GACzF,oBAAA;AAAA,IACE;AAAA,MACE,GA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AK,CAAA;AACzC,EAAA,MAAM,EAAE,UAAA,EAAY,UAAA,EAAY,kBAAkB,iBAAA,EAAmB,GAAG,kBAAiB,GAAI,gBAAA;AAAA,IAC3F,EAAE,GAAG,KAAA,EAAO,KAAA,EAAO,KAAA,CAAM,SAAS,gBAAA,EAAkB,WAAA,EAAa,KAAA,CAAM,WAAA,IAAe,aAAA,EAAc;AAAA,IACpG;AAAA,GACF;AAEA,EAAA,uBACEJ,OAAA,aAAA,CAAC,yBAAA,CAA0B,UAA1B,EAAmC,KAAA,EAAO,KAAA,EAAA,kBACzCA,MAAAA,CAAA,aAAA;AAAA,IAACK,SAAAA;AAAA,IAAA;AAAA,MACE,GAAG,MAAM,UAAU,CAAA;AAAA,MACnB,GAAGC,iBAAAA,CAAkB;AAAA,QACpB,WAAA,EAAa,MAAM,WAAA,IAAe,UAAA;AAAA,QAClC,SAAS,KAAA,CAAM,SAAA;AAAA,QACf,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM;AAAA,OACjB,CAAA;AAAA,MACD,KAAA,EAAO;AAAA,QACL,KAAA,EAAO,UAAA;AAAA,QACP,WAAA,EAAa,gBAAA;AAAA,QACb,KAAA,EAAOC,YAAAA,CAAW,iBAAA,EAAmB,gBAAgB;AAAA;AACvD,KAAA;AAAA,IAEC,KAAA,CAAM;AAAA,GAEX,CAAA;AAEJ,CAAC","file":"index.js","sourcesContent":["import React from 'react';\nimport { CheckboxGroupState } from 'react-stately';\n\nexport const CheckboxGroupStateContext = React.createContext<CheckboxGroupState | null>(null);\n","import React, { useContext, useRef, useMemo } from 'react';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { VisuallyHidden } from '@bento/visually-hidden';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useFocusRing, useHover, useCheckbox, useCheckboxGroupItem, type AriaCheckboxProps } from 'react-aria';\nimport { useToggleState } from 'react-stately';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\n\nexport interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {\n /** The value of the checkbox, used when submitting an HTML form. */\n value?: string;\n\n /** The name of the checkbox. */\n name?: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the checkbox. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /** Whether the checkbox is required or not. */\n isRequired?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /**\n * Whether the checkbox is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n\n /** Whether the checkbox is in an indeterminate state. */\n isIndeterminate?: boolean;\n\n /** Whether the checkbox is in a selected state. */\n isSelected?: boolean;\n}\n\n/**\n * The `Checkbox` is a single checkbox option that can be selected by the user.\n */\nexport const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: CheckboxProps) {\n const { props, apply } = useProps(args);\n const groupState = useContext(CheckboxGroupStateContext);\n const ref = useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n\n const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState\n ? useCheckboxGroupItem(\n {\n ...props,\n // Value is optional for standalone checkboxes, but required for CheckboxGroup items;\n // it's passed explicitly here to avoid typescript error (requires ignore)(recommendation from React Aria).\n value: (props as Required<Pick<typeof props, 'value'>>).value\n },\n groupState,\n inputRef\n )\n : useCheckbox(props, useToggleState(props), inputRef);\n\n const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n\n return (\n <Container\n as=\"label\"\n aria-checked={props.isIndeterminate ? 'mixed' : undefined}\n {...apply(mergeProps(labelProps, hoverProps))}\n {...useDataAttributes({\n selected: isSelected,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: interactionDisabled,\n readonly: isReadOnly,\n invalid: isInvalid,\n required: props.isRequired,\n indeterminate: props.isIndeterminate\n })}\n >\n <VisuallyHidden>\n <input {...mergeProps(inputProps, focusProps)} ref={inputRef} />\n </VisuallyHidden>\n\n {props.isIndeterminate ? (\n <Icon slot=\"icon-indeterminate\" icon=\"checkboxIndeterminate\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect x=\"6\" y=\"11\" width=\"12\" height=\"2\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"checkboxChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z\" fill=\"currentColor\" />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"checkboxUnchecked\">\n <svg width={24} height={24}>\n <rect x={4} y={4} width={16} height={16} rx={3} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n {props.children}\n </Container>\n );\n});\n","import React from 'react';\nimport { withSlots } from '@bento/slots';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useProps } from '@bento/use-props';\nimport { useCheckboxGroup, mergeProps, type AriaCheckboxGroupProps } from 'react-aria';\nimport { useCheckboxGroupState } from 'react-stately';\nimport { CheckboxGroupStateContext } from './checkbox-group-state';\nimport { useDataAttributes } from '@bento/use-data-attributes';\n\nexport interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {\n /** The current value of the checkbox group (controlled). */\n value?: string[];\n\n /** The default value of the checkbox group (uncontrolled). */\n defaultValue?: string[];\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n */\n form?: string;\n\n /** Checkbox children. */\n children?: React.ReactNode;\n}\n\n/**\n * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.\n */\nexport const CheckboxGroup = withSlots('BentoCheckboxGroup', function CheckboxGroup(args: CheckboxGroupProps) {\n const { props, apply } = useProps(args);\n const state = useCheckboxGroupState(props);\n const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(\n { ...props, label: props.label ?? 'Checkbox Group', description: props.description ?? 'Description' },\n state\n );\n\n return (\n <CheckboxGroupStateContext.Provider value={state}>\n <Container\n {...apply(groupProps)}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n slots={{\n label: labelProps,\n description: descriptionProps,\n error: mergeProps(errorMessageProps, validationResult)\n }}\n >\n {props.children}\n </Container>\n </CheckboxGroupStateContext.Provider>\n );\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento/checkbox",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Checkbox component",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,11 +40,12 @@
40
40
  "package.json"
41
41
  ],
42
42
  "dependencies": {
43
- "@bento/control": "^0.1.2",
44
- "@bento/icon": "^0.1.2",
45
- "@bento/slots": "^0.1.3",
43
+ "@bento/container": "^0.2.0",
44
+ "@bento/icon": "^0.1.3",
45
+ "@bento/slots": "^0.2.0",
46
46
  "@bento/use-data-attributes": "^0.1.1",
47
- "@bento/use-props": "^0.1.1",
47
+ "@bento/use-props": "^0.2.0",
48
+ "@bento/visually-hidden": "^0.1.0",
48
49
  "@react-aria/utils": "^3.30.0",
49
50
  "react-aria": "^3.44.0",
50
51
  "react-stately": "^3.42.0"
@@ -1,16 +1,13 @@
1
- import React, { useMemo } from 'react';
1
+ import React from 'react';
2
+ import { withSlots } from '@bento/slots';
3
+ import { Container, type ContainerProps } from '@bento/container';
2
4
  import { useProps } from '@bento/use-props';
3
- import { ControlGroup, ControlGroupProps } from '@bento/control';
4
- import { useDataAttributes } from '@bento/use-data-attributes';
5
- import { type ValidationResult } from '@react-types/shared';
6
- import { AriaCheckboxGroupProps, useCheckboxGroup } from 'react-aria';
5
+ import { useCheckboxGroup, mergeProps, type AriaCheckboxGroupProps } from 'react-aria';
7
6
  import { useCheckboxGroupState } from 'react-stately';
8
- import { withSlots } from '@bento/slots';
9
7
  import { CheckboxGroupStateContext } from './checkbox-group-state';
8
+ import { useDataAttributes } from '@bento/use-data-attributes';
10
9
 
11
- export interface CheckboxGroupProps
12
- extends AriaCheckboxGroupProps,
13
- Partial<Omit<ControlGroupProps, keyof AriaCheckboxGroupProps>> {
10
+ export interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
14
11
  /** The current value of the checkbox group (controlled). */
15
12
  value?: string[];
16
13
 
@@ -33,66 +30,45 @@ export interface CheckboxGroupProps
33
30
  name?: string;
34
31
 
35
32
  /**
36
- * The <form> element to associate the input with.
37
- * The value of this attribute must be the id of a <form> in the same document.
33
+ * The `<form>` element to associate the input with.
34
+ * The value of this attribute must be the id of a `<form>` in the same document.
38
35
  */
39
36
  form?: string;
40
37
 
41
- /** Description for the checkbox group. */
42
- description?: string;
43
-
44
38
  /** Checkbox children. */
45
39
  children?: React.ReactNode;
46
-
47
- /** Error message for the checkbox group. */
48
- errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);
49
40
  }
50
41
 
51
42
  /**
52
43
  * The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
53
- *
54
- * @component
55
- * @param {CheckboxGroupProps} args - The props passed to the CheckboxGroup component.
56
- *
57
- * @public
58
44
  */
59
45
  export const CheckboxGroup = withSlots('BentoCheckboxGroup', function CheckboxGroup(args: CheckboxGroupProps) {
60
- const { errorMessage, ...restArgs } = args;
61
- const { props, apply } = useProps(restArgs);
46
+ const { props, apply } = useProps(args);
62
47
  const state = useCheckboxGroupState(props);
63
- const { children } = props;
64
48
  const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(
65
- props,
49
+ { ...props, label: props.label ?? 'Checkbox Group', description: props.description ?? 'Description' },
66
50
  state
67
51
  );
68
52
 
69
- const displayedErrorMessage = useMemo(
70
- function getErrorMessage() {
71
- return typeof errorMessage === 'function'
72
- ? errorMessage(validationResult)
73
- : errorMessage || validationResult.validationErrors.join(', ');
74
- },
75
- [errorMessage, validationResult]
76
- );
77
-
78
53
  return (
79
- <ControlGroup
80
- slot="group"
81
- labelProps={labelProps}
82
- descriptionProps={descriptionProps}
83
- errorMessage={displayedErrorMessage}
84
- errorMessageProps={errorMessageProps}
85
- {...groupProps}
86
- {...apply(props, ['isInvalid', 'isDisabled', 'isReadOnly', 'isRequired', 'validationBehavior'])}
87
- {...useDataAttributes({
88
- orientation: props.orientation || 'vertical',
89
- invalid: state.isInvalid,
90
- disabled: state.isDisabled,
91
- readonly: state.isReadOnly,
92
- required: state.isRequired
93
- })}
94
- >
95
- <CheckboxGroupStateContext.Provider value={state}>{children}</CheckboxGroupStateContext.Provider>
96
- </ControlGroup>
54
+ <CheckboxGroupStateContext.Provider value={state}>
55
+ <Container
56
+ {...apply(groupProps)}
57
+ {...useDataAttributes({
58
+ orientation: props.orientation || 'vertical',
59
+ invalid: state.isInvalid,
60
+ disabled: state.isDisabled,
61
+ readonly: state.isReadOnly,
62
+ required: state.isRequired
63
+ })}
64
+ slots={{
65
+ label: labelProps,
66
+ description: descriptionProps,
67
+ error: mergeProps(errorMessageProps, validationResult)
68
+ }}
69
+ >
70
+ {props.children}
71
+ </Container>
72
+ </CheckboxGroupStateContext.Provider>
97
73
  );
98
74
  });
package/src/checkbox.tsx CHANGED
@@ -1,15 +1,16 @@
1
1
  import React, { useContext, useRef, useMemo } from 'react';
2
- import { Control, ControlProps } from '@bento/control';
2
+ import { Container, type ContainerProps } from '@bento/container';
3
+ import { useDataAttributes } from '@bento/use-data-attributes';
3
4
  import { Icon } from '@bento/icon';
4
5
  import { withSlots } from '@bento/slots';
5
6
  import { useProps } from '@bento/use-props';
6
- import { useFocusRing, useHover, type AriaCheckboxProps, useCheckboxGroupItem, useCheckbox } from 'react-aria';
7
+ import { VisuallyHidden } from '@bento/visually-hidden';
7
8
  import { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';
9
+ import { useFocusRing, useHover, useCheckbox, useCheckboxGroupItem, type AriaCheckboxProps } from 'react-aria';
8
10
  import { useToggleState } from 'react-stately';
9
- import { useDataAttributes } from '@bento/use-data-attributes';
10
11
  import { CheckboxGroupStateContext } from './checkbox-group-state';
11
12
 
12
- export interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, keyof AriaCheckboxProps>> {
13
+ export interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
13
14
  /** The value of the checkbox, used when submitting an HTML form. */
14
15
  value?: string;
15
16
 
@@ -46,28 +47,15 @@ export interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlPr
46
47
 
47
48
  /**
48
49
  * The `Checkbox` is a single checkbox option that can be selected by the user.
49
- *
50
- * @component
51
- * @param args - The props {@link CheckboxProps} passed to the Checkbox component.
52
- *
53
- * @public
54
50
  */
55
51
  export const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: CheckboxProps) {
56
52
  const { props, apply } = useProps(args);
57
- const {
58
- isRequired = false,
59
- isIndeterminate = false,
60
- isDisabled: isDisabledProp = false,
61
- isSelected: isSelectedProp = false,
62
- isReadOnly: isReadOnlyProp = false
63
- } = props;
64
-
65
53
  const groupState = useContext(CheckboxGroupStateContext);
66
-
67
54
  const ref = useRef<HTMLInputElement>(null);
68
55
  const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
56
+ const { isFocused, isFocusVisible, focusProps } = useFocusRing();
69
57
 
70
- let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState
58
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState
71
59
  ? useCheckboxGroupItem(
72
60
  {
73
61
  ...props,
@@ -78,44 +66,37 @@ export const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: Check
78
66
  groupState,
79
67
  inputRef
80
68
  )
81
- : useCheckbox(
82
- {
83
- ...props
84
- },
85
- useToggleState(props),
86
- inputRef
87
- );
69
+ : useCheckbox(props, useToggleState(props), inputRef);
88
70
 
89
- const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;
71
+ const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
90
72
  const { hoverProps, isHovered } = useHover({
91
73
  ...props,
92
74
  isDisabled: interactionDisabled
93
75
  });
94
- const { isFocused, isFocusVisible, focusProps } = useFocusRing();
95
76
 
96
77
  return (
97
- <Control
98
- slot="control"
99
- labelProps={mergeProps(labelProps, hoverProps)}
100
- inputProps={mergeProps(inputProps, focusProps)}
101
- label={props.children}
102
- inputRef={inputRef}
103
- aria-checked={isIndeterminate ? 'mixed' : undefined}
104
- {...apply(props, ['isReadOnly', 'isSelected', 'isIndeterminate', 'isDisabled', 'value', 'autoFocus'])}
78
+ <Container
79
+ as="label"
80
+ aria-checked={props.isIndeterminate ? 'mixed' : undefined}
81
+ {...apply(mergeProps(labelProps, hoverProps))}
105
82
  {...useDataAttributes({
106
- selected: isSelected || isSelectedProp,
83
+ selected: isSelected,
107
84
  pressed: isPressed,
108
85
  hovered: isHovered,
109
86
  focused: isFocused,
110
87
  focusVisible: isFocusVisible,
111
88
  disabled: interactionDisabled,
112
- readOnly: isReadOnly || isReadOnlyProp,
89
+ readonly: isReadOnly,
113
90
  invalid: isInvalid,
114
- required: isRequired,
115
- indeterminate: isIndeterminate
91
+ required: props.isRequired,
92
+ indeterminate: props.isIndeterminate
116
93
  })}
117
94
  >
118
- {isIndeterminate ? (
95
+ <VisuallyHidden>
96
+ <input {...mergeProps(inputProps, focusProps)} ref={inputRef} />
97
+ </VisuallyHidden>
98
+
99
+ {props.isIndeterminate ? (
119
100
  <Icon slot="icon-indeterminate" icon="checkboxIndeterminate">
120
101
  <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
121
102
  <rect x="6" y="11" width="12" height="2" fill="currentColor" />
@@ -129,11 +110,12 @@ export const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: Check
129
110
  </Icon>
130
111
  ) : (
131
112
  <Icon slot="icon-unchecked" icon="checkboxUnchecked">
132
- <svg width={24} height={24} aria-hidden="true">
113
+ <svg width={24} height={24}>
133
114
  <rect x={4} y={4} width={16} height={16} rx={3} fill="none" stroke="gray" strokeWidth={2} />
134
115
  </svg>
135
116
  </Icon>
136
117
  )}
137
- </Control>
118
+ {props.children}
119
+ </Container>
138
120
  );
139
121
  });