@bento/checkbox 0.1.3 → 0.2.1

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,16 @@
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');
7
+ var input = require('@bento/input');
6
8
  var slots = require('@bento/slots');
7
9
  var useProps = require('@bento/use-props');
8
- var reactAria = require('react-aria');
10
+ var visuallyHidden = require('@bento/visually-hidden');
9
11
  var utils = require('@react-aria/utils');
12
+ var reactAria = require('react-aria');
10
13
  var reactStately = require('react-stately');
11
- var useDataAttributes = require('@bento/use-data-attributes');
12
14
 
13
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
16
 
@@ -20,17 +22,11 @@ var CheckboxGroupStateContext = React2__default.default.createContext(null);
20
22
  // src/checkbox.tsx
21
23
  var Checkbox = slots.withSlots("BentoCheckbox", function Checkbox2(args) {
22
24
  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
25
  const groupState = React2.useContext(CheckboxGroupStateContext);
31
26
  const ref = React2.useRef(null);
32
27
  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(
28
+ const { isFocused, isFocusVisible, focusProps } = reactAria.useFocusRing();
29
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? reactAria.useCheckboxGroupItem(
34
30
  {
35
31
  ...props,
36
32
  // Value is optional for standalone checkboxes, but required for CheckboxGroup items;
@@ -39,80 +35,62 @@ var Checkbox = slots.withSlots("BentoCheckbox", function Checkbox2(args) {
39
35
  },
40
36
  groupState,
41
37
  inputRef
42
- ) : reactAria.useCheckbox(
43
- {
44
- ...props
45
- },
46
- reactStately.useToggleState(props),
47
- inputRef
48
- );
49
- const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;
38
+ ) : reactAria.useCheckbox(props, reactStately.useToggleState(props), inputRef);
39
+ const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
50
40
  const { hoverProps, isHovered } = reactAria.useHover({
51
41
  ...props,
52
42
  isDisabled: interactionDisabled
53
43
  });
54
- const { isFocused, isFocusVisible, focusProps } = reactAria.useFocusRing();
55
44
  return /* @__PURE__ */ React2__default.default.createElement(
56
- control.Control,
45
+ container.Container,
57
46
  {
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"]),
47
+ as: "label",
48
+ "aria-checked": props.isIndeterminate ? "mixed" : void 0,
49
+ ...apply(utils.mergeProps(labelProps, hoverProps)),
65
50
  ...useDataAttributes.useDataAttributes({
66
- selected: isSelected || isSelectedProp,
51
+ selected: isSelected,
67
52
  pressed: isPressed,
68
53
  hovered: isHovered,
69
54
  focused: isFocused,
70
55
  focusVisible: isFocusVisible,
71
56
  disabled: interactionDisabled,
72
- readOnly: isReadOnly || isReadOnlyProp,
57
+ readonly: isReadOnly,
73
58
  invalid: isInvalid,
74
- required: isRequired,
75
- indeterminate: isIndeterminate
59
+ required: props.isRequired,
60
+ indeterminate: props.isIndeterminate
76
61
  })
77
62
  },
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 })))
63
+ /* @__PURE__ */ React2__default.default.createElement(visuallyHidden.VisuallyHidden, null, /* @__PURE__ */ React2__default.default.createElement(input.Input, { ...utils.mergeProps(inputProps, focusProps), ref: inputRef })),
64
+ 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 }))),
65
+ props.children
79
66
  );
80
67
  });
81
68
  var CheckboxGroup = slots.withSlots("BentoCheckboxGroup", function CheckboxGroup2(args) {
82
- const { errorMessage, ...restArgs } = args;
83
- const { props, apply } = useProps.useProps(restArgs);
69
+ const { props, apply } = useProps.useProps(args);
84
70
  const state = reactStately.useCheckboxGroupState(props);
85
- const { children } = props;
86
71
  const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = reactAria.useCheckboxGroup(
87
- props,
72
+ { ...props, label: props.label ?? "Checkbox Group", description: props.description ?? "Description" },
88
73
  state
89
74
  );
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,
75
+ return /* @__PURE__ */ React2__default.default.createElement(CheckboxGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2__default.default.createElement(
76
+ container.Container,
98
77
  {
99
- slot: "group",
100
- labelProps,
101
- descriptionProps,
102
- errorMessage: displayedErrorMessage,
103
- errorMessageProps,
104
- ...groupProps,
105
- ...apply(props, ["isInvalid", "isDisabled", "isReadOnly", "isRequired", "validationBehavior"]),
78
+ ...apply(groupProps),
106
79
  ...useDataAttributes.useDataAttributes({
107
80
  orientation: props.orientation || "vertical",
108
81
  invalid: state.isInvalid,
109
82
  disabled: state.isDisabled,
110
83
  readonly: state.isReadOnly,
111
84
  required: state.isRequired
112
- })
85
+ }),
86
+ slots: {
87
+ label: labelProps,
88
+ description: descriptionProps,
89
+ error: reactAria.mergeProps(errorMessageProps, validationResult)
90
+ }
113
91
  },
114
- /* @__PURE__ */ React2__default.default.createElement(CheckboxGroupStateContext.Provider, { value: state }, children)
115
- );
92
+ props.children
93
+ ));
116
94
  });
117
95
 
118
96
  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,G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mCAAsB,KAAK,CAAA;AACzC,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","Input","Icon","CheckboxGroup","useCheckboxGroupState","useCheckboxGroup"],"mappings":";;;;;;;;;;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4BA,uBAAA,CAAM,aAAA,CAAyC,IAAI,CAAA;;;ACgDrF,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,E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oBAAAA,CAAW,iBAAA,EAAmB,gBAAgB;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 { Input } from '@bento/input';\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,14 @@
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';
5
+ import { Input } from '@bento/input';
4
6
  import { withSlots } from '@bento/slots';
5
7
  import { useProps } from '@bento/use-props';
6
- import { useCheckboxGroupItem, useCheckbox, useHover, useFocusRing, useCheckboxGroup } from 'react-aria';
8
+ import { VisuallyHidden } from '@bento/visually-hidden';
7
9
  import { useObjectRef, mergeRefs, mergeProps } from '@react-aria/utils';
10
+ import { useFocusRing, useCheckboxGroupItem, useCheckbox, useHover, useCheckboxGroup, mergeProps as mergeProps$1 } from 'react-aria';
8
11
  import { useToggleState, useCheckboxGroupState } from 'react-stately';
9
- import { useDataAttributes } from '@bento/use-data-attributes';
10
12
 
11
13
  // src/checkbox.tsx
12
14
  var CheckboxGroupStateContext = React2.createContext(null);
@@ -14,17 +16,11 @@ var CheckboxGroupStateContext = React2.createContext(null);
14
16
  // src/checkbox.tsx
15
17
  var Checkbox = withSlots("BentoCheckbox", function Checkbox2(args) {
16
18
  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
19
  const groupState = useContext(CheckboxGroupStateContext);
25
20
  const ref = useRef(null);
26
21
  const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
27
- let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState ? useCheckboxGroupItem(
22
+ const { isFocused, isFocusVisible, focusProps } = useFocusRing();
23
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? useCheckboxGroupItem(
28
24
  {
29
25
  ...props,
30
26
  // Value is optional for standalone checkboxes, but required for CheckboxGroup items;
@@ -33,80 +29,62 @@ var Checkbox = withSlots("BentoCheckbox", function Checkbox2(args) {
33
29
  },
34
30
  groupState,
35
31
  inputRef
36
- ) : useCheckbox(
37
- {
38
- ...props
39
- },
40
- useToggleState(props),
41
- inputRef
42
- );
43
- const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;
32
+ ) : useCheckbox(props, useToggleState(props), inputRef);
33
+ const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
44
34
  const { hoverProps, isHovered } = useHover({
45
35
  ...props,
46
36
  isDisabled: interactionDisabled
47
37
  });
48
- const { isFocused, isFocusVisible, focusProps } = useFocusRing();
49
38
  return /* @__PURE__ */ React2.createElement(
50
- Control,
39
+ Container,
51
40
  {
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"]),
41
+ as: "label",
42
+ "aria-checked": props.isIndeterminate ? "mixed" : void 0,
43
+ ...apply(mergeProps(labelProps, hoverProps)),
59
44
  ...useDataAttributes({
60
- selected: isSelected || isSelectedProp,
45
+ selected: isSelected,
61
46
  pressed: isPressed,
62
47
  hovered: isHovered,
63
48
  focused: isFocused,
64
49
  focusVisible: isFocusVisible,
65
50
  disabled: interactionDisabled,
66
- readOnly: isReadOnly || isReadOnlyProp,
51
+ readonly: isReadOnly,
67
52
  invalid: isInvalid,
68
- required: isRequired,
69
- indeterminate: isIndeterminate
53
+ required: props.isRequired,
54
+ indeterminate: props.isIndeterminate
70
55
  })
71
56
  },
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 })))
57
+ /* @__PURE__ */ React2.createElement(VisuallyHidden, null, /* @__PURE__ */ React2.createElement(Input, { ...mergeProps(inputProps, focusProps), ref: inputRef })),
58
+ 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 }))),
59
+ props.children
73
60
  );
74
61
  });
75
62
  var CheckboxGroup = withSlots("BentoCheckboxGroup", function CheckboxGroup2(args) {
76
- const { errorMessage, ...restArgs } = args;
77
- const { props, apply } = useProps(restArgs);
63
+ const { props, apply } = useProps(args);
78
64
  const state = useCheckboxGroupState(props);
79
- const { children } = props;
80
65
  const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(
81
- props,
66
+ { ...props, label: props.label ?? "Checkbox Group", description: props.description ?? "Description" },
82
67
  state
83
68
  );
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,
69
+ return /* @__PURE__ */ React2.createElement(CheckboxGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2.createElement(
70
+ Container,
92
71
  {
93
- slot: "group",
94
- labelProps,
95
- descriptionProps,
96
- errorMessage: displayedErrorMessage,
97
- errorMessageProps,
98
- ...groupProps,
99
- ...apply(props, ["isInvalid", "isDisabled", "isReadOnly", "isRequired", "validationBehavior"]),
72
+ ...apply(groupProps),
100
73
  ...useDataAttributes({
101
74
  orientation: props.orientation || "vertical",
102
75
  invalid: state.isInvalid,
103
76
  disabled: state.isDisabled,
104
77
  readonly: state.isReadOnly,
105
78
  required: state.isRequired
106
- })
79
+ }),
80
+ slots: {
81
+ label: labelProps,
82
+ description: descriptionProps,
83
+ error: mergeProps$1(errorMessageProps, validationResult)
84
+ }
107
85
  },
108
- /* @__PURE__ */ React2.createElement(CheckboxGroupStateContext.Provider, { value: state }, children)
109
- );
86
+ props.children
87
+ ));
110
88
  });
111
89
 
112
90
  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","useMem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AA;AAAA,IAC3F,KAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,qBAAA,GAAwBC,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;;;ACgDrF,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,EAA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A,EAAM,GAAIC,SAAS,IAAI,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQ,sBAAsB,KAAK,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 { Input } from '@bento/input';\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.1",
4
4
  "description": "Checkbox component",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,11 +40,13 @@
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.1",
44
+ "@bento/icon": "^0.1.4",
45
+ "@bento/input": "^0.1.0",
46
+ "@bento/slots": "^0.3.0",
46
47
  "@bento/use-data-attributes": "^0.1.1",
47
- "@bento/use-props": "^0.1.1",
48
+ "@bento/use-props": "^0.2.1",
49
+ "@bento/visually-hidden": "^0.1.1",
48
50
  "@react-aria/utils": "^3.30.0",
49
51
  "react-aria": "^3.44.0",
50
52
  "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,17 @@
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';
5
+ import { Input } from '@bento/input';
4
6
  import { withSlots } from '@bento/slots';
5
7
  import { useProps } from '@bento/use-props';
6
- import { useFocusRing, useHover, type AriaCheckboxProps, useCheckboxGroupItem, useCheckbox } from 'react-aria';
8
+ import { VisuallyHidden } from '@bento/visually-hidden';
7
9
  import { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';
10
+ import { useFocusRing, useHover, useCheckbox, useCheckboxGroupItem, type AriaCheckboxProps } from 'react-aria';
8
11
  import { useToggleState } from 'react-stately';
9
- import { useDataAttributes } from '@bento/use-data-attributes';
10
12
  import { CheckboxGroupStateContext } from './checkbox-group-state';
11
13
 
12
- export interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlProps, keyof AriaCheckboxProps>> {
14
+ export interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
13
15
  /** The value of the checkbox, used when submitting an HTML form. */
14
16
  value?: string;
15
17
 
@@ -46,28 +48,15 @@ export interface CheckboxProps extends AriaCheckboxProps, Partial<Omit<ControlPr
46
48
 
47
49
  /**
48
50
  * 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
51
  */
55
52
  export const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: CheckboxProps) {
56
53
  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
54
  const groupState = useContext(CheckboxGroupStateContext);
66
-
67
55
  const ref = useRef<HTMLInputElement>(null);
68
56
  const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
57
+ const { isFocused, isFocusVisible, focusProps } = useFocusRing();
69
58
 
70
- let { labelProps, inputProps, isSelected, isReadOnly, isDisabled, isPressed, isInvalid } = groupState
59
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState
71
60
  ? useCheckboxGroupItem(
72
61
  {
73
62
  ...props,
@@ -78,44 +67,37 @@ export const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: Check
78
67
  groupState,
79
68
  inputRef
80
69
  )
81
- : useCheckbox(
82
- {
83
- ...props
84
- },
85
- useToggleState(props),
86
- inputRef
87
- );
70
+ : useCheckbox(props, useToggleState(props), inputRef);
88
71
 
89
- const interactionDisabled = isDisabledProp || isDisabled || isReadOnly || isReadOnlyProp;
72
+ const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
90
73
  const { hoverProps, isHovered } = useHover({
91
74
  ...props,
92
75
  isDisabled: interactionDisabled
93
76
  });
94
- const { isFocused, isFocusVisible, focusProps } = useFocusRing();
95
77
 
96
78
  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'])}
79
+ <Container
80
+ as="label"
81
+ aria-checked={props.isIndeterminate ? 'mixed' : undefined}
82
+ {...apply(mergeProps(labelProps, hoverProps))}
105
83
  {...useDataAttributes({
106
- selected: isSelected || isSelectedProp,
84
+ selected: isSelected,
107
85
  pressed: isPressed,
108
86
  hovered: isHovered,
109
87
  focused: isFocused,
110
88
  focusVisible: isFocusVisible,
111
89
  disabled: interactionDisabled,
112
- readOnly: isReadOnly || isReadOnlyProp,
90
+ readonly: isReadOnly,
113
91
  invalid: isInvalid,
114
- required: isRequired,
115
- indeterminate: isIndeterminate
92
+ required: props.isRequired,
93
+ indeterminate: props.isIndeterminate
116
94
  })}
117
95
  >
118
- {isIndeterminate ? (
96
+ <VisuallyHidden>
97
+ <Input {...mergeProps(inputProps, focusProps)} ref={inputRef} />
98
+ </VisuallyHidden>
99
+
100
+ {props.isIndeterminate ? (
119
101
  <Icon slot="icon-indeterminate" icon="checkboxIndeterminate">
120
102
  <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
121
103
  <rect x="6" y="11" width="12" height="2" fill="currentColor" />
@@ -129,11 +111,12 @@ export const Checkbox = withSlots('BentoCheckbox', function Checkbox(args: Check
129
111
  </Icon>
130
112
  ) : (
131
113
  <Icon slot="icon-unchecked" icon="checkboxUnchecked">
132
- <svg width={24} height={24} aria-hidden="true">
114
+ <svg width={24} height={24}>
133
115
  <rect x={4} y={4} width={16} height={16} rx={3} fill="none" stroke="gray" strokeWidth={2} />
134
116
  </svg>
135
117
  </Icon>
136
118
  )}
137
- </Control>
119
+ {props.children}
120
+ </Container>
138
121
  );
139
122
  });