@bento/checkbox 0.2.1 → 0.2.3
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 +43 -94
- package/dist/index.cjs +159 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -53
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +66 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +139 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -19
- package/dist/index.d.ts +0 -64
- package/dist/index.js +0 -92
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -26,53 +26,8 @@ The following properties are available to be used on the `CheckboxGroup` and `Ch
|
|
|
26
26
|
|
|
27
27
|
### Checkbox
|
|
28
28
|
|
|
29
|
-
| Prop | Type | Required | Description |
|
|
30
|
-
|------|------|----------|------------|
|
|
31
|
-
| `value` | `string` | No | The value of the checkbox, used when submitting an HTML form. |
|
|
32
|
-
| `name` | `string` | No | The name of the checkbox. |
|
|
33
|
-
| `inputRef` | `Ref<HTMLInputElement>` | No | A ref for the HTML input element. |
|
|
34
|
-
| `children` | `ReactNode` | No | The label for the checkbox. Accepts any renderable node. |
|
|
35
|
-
| `isRequired` | `boolean` | No | Whether the checkbox is required or not. |
|
|
36
|
-
| `isReadOnly` | `boolean` | No | Whether the input can be selected but not changed by the user. |
|
|
37
|
-
| `isDisabled` | `boolean` | No | Whether the checkbox is disabled or not. Shows that a selection exists,
|
|
38
|
-
but is not available in that circumstance. |
|
|
39
|
-
| `autoFocus` | `boolean` | No | Whether the element should receive focus on render. |
|
|
40
|
-
| `isIndeterminate` | `boolean` | No | Whether the checkbox is in an indeterminate state. |
|
|
41
|
-
| `isSelected` | `boolean` | No | Whether the checkbox is in a selected state. |
|
|
42
|
-
| `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
|
|
43
|
-
The exposed slot names of a component are available in the components documentation. |
|
|
44
|
-
| `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
|
|
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 | |
|
|
51
|
-
|
|
52
29
|
### CheckboxGroup
|
|
53
30
|
|
|
54
|
-
| Prop | Type | Required | Description |
|
|
55
|
-
|------|------|----------|------------|
|
|
56
|
-
| `value` | `string[]` | No | The current value of the checkbox group (controlled). |
|
|
57
|
-
| `defaultValue` | `string[]` | No | The default value of the checkbox group (uncontrolled). |
|
|
58
|
-
| `isDisabled` | `boolean` | No | Whether the input is disabled. |
|
|
59
|
-
| `isReadOnly` | `boolean` | No | Whether the input can be selected but not changed by the user. |
|
|
60
|
-
| `isRequired` | `boolean` | No | Whether user input is required on the input before form submission. |
|
|
61
|
-
| `isInvalid` | `boolean` | No | Whether the input value is invalid. |
|
|
62
|
-
| `name` | `string` | No | The name of the input element, used when submitting an HTML form. |
|
|
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. |
|
|
65
|
-
| `children` | `ReactNode` | No | Checkbox children. |
|
|
66
|
-
| `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
|
|
67
|
-
The exposed slot names of a component are available in the components documentation. |
|
|
68
|
-
| `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
|
|
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 | |
|
|
75
|
-
|
|
76
31
|
## Data Attributes, Slot Map and Props
|
|
77
32
|
|
|
78
33
|
### Data Attributes
|
|
@@ -222,75 +177,69 @@ import React, { useState } from 'react';
|
|
|
222
177
|
import { Checkbox, CheckboxGroup } from '@bento/checkbox';
|
|
223
178
|
import { Text } from '@bento/text';
|
|
224
179
|
|
|
225
|
-
|
|
226
|
-
const [checkedItems, setCheckedItems] = useState<Set<string>>(new Set());
|
|
180
|
+
const SELECT_ALL = 'select-all';
|
|
227
181
|
|
|
182
|
+
export function CheckboxGroupIndeterminateExample() {
|
|
228
183
|
const items = [
|
|
229
184
|
{ id: 'option1', label: 'Option 1' },
|
|
230
185
|
{ id: 'option2', label: 'Option 2' },
|
|
231
186
|
{ id: 'option3', label: 'Option 3' }
|
|
232
187
|
];
|
|
233
|
-
|
|
234
188
|
const allItemIds = items.map(function getItemId(item) {
|
|
235
189
|
return item.id;
|
|
236
190
|
});
|
|
237
|
-
const isAllSelected = checkedItems.size === items.length;
|
|
238
|
-
const isIndeterminate = checkedItems.size > 0 && checkedItems.size < items.length;
|
|
239
191
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
192
|
+
const [checkedItems, setCheckedItems] = useState<string[]>([]);
|
|
193
|
+
|
|
194
|
+
const itemsSelectedCount = checkedItems.filter(function isItem(value) {
|
|
195
|
+
return value !== SELECT_ALL;
|
|
196
|
+
}).length;
|
|
197
|
+
const isIndeterminate = itemsSelectedCount > 0 && itemsSelectedCount < allItemIds.length;
|
|
198
|
+
|
|
199
|
+
function handleGroupChange(nextValues: string[]) {
|
|
200
|
+
const prevHadSelectAll = checkedItems.includes(SELECT_ALL);
|
|
201
|
+
const nextHasSelectAll = nextValues.includes(SELECT_ALL);
|
|
202
|
+
|
|
203
|
+
// Select All was just toggled on → select every item, with select-all last.
|
|
204
|
+
if (!prevHadSelectAll && nextHasSelectAll) {
|
|
205
|
+
setCheckedItems([...allItemIds, SELECT_ALL]);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Select All was just toggled off → clear everything.
|
|
210
|
+
if (prevHadSelectAll && !nextHasSelectAll) {
|
|
211
|
+
setCheckedItems([]);
|
|
212
|
+
return;
|
|
245
213
|
}
|
|
246
|
-
}
|
|
247
214
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (checked) {
|
|
252
|
-
newSet.add(itemId);
|
|
253
|
-
if (
|
|
254
|
-
allItemIds.every(function checkItemInSet(id) {
|
|
255
|
-
return newSet.has(id);
|
|
256
|
-
})
|
|
257
|
-
) {
|
|
258
|
-
newSet.add('select-all');
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
newSet.delete(itemId);
|
|
262
|
-
newSet.delete('select-all');
|
|
263
|
-
}
|
|
264
|
-
return newSet;
|
|
215
|
+
// An individual item toggled. Strip select-all so its membership is purely derived.
|
|
216
|
+
const itemsOnly = nextValues.filter(function notSelectAll(value) {
|
|
217
|
+
return value !== SELECT_ALL;
|
|
265
218
|
});
|
|
219
|
+
const allItemsNowSelected = allItemIds.every(function isInItems(id) {
|
|
220
|
+
return itemsOnly.includes(id);
|
|
221
|
+
});
|
|
222
|
+
if (allItemsNowSelected) {
|
|
223
|
+
setCheckedItems([...itemsOnly, SELECT_ALL]);
|
|
224
|
+
} else {
|
|
225
|
+
setCheckedItems(itemsOnly);
|
|
226
|
+
}
|
|
266
227
|
}
|
|
267
228
|
|
|
268
229
|
return (
|
|
269
|
-
<CheckboxGroup value={
|
|
230
|
+
<CheckboxGroup value={checkedItems} onChange={handleGroupChange} data-value={checkedItems}>
|
|
270
231
|
<Text slot="label">Select Items</Text>
|
|
271
|
-
<Checkbox
|
|
272
|
-
name="select-all"
|
|
273
|
-
value="select-all"
|
|
274
|
-
isSelected={isAllSelected}
|
|
275
|
-
isIndeterminate={isIndeterminate}
|
|
276
|
-
onChange={handleSelectAll}
|
|
277
|
-
>
|
|
232
|
+
<Checkbox name={SELECT_ALL} value={SELECT_ALL} isIndeterminate={isIndeterminate}>
|
|
278
233
|
Select All
|
|
279
234
|
</Checkbox>
|
|
280
235
|
|
|
281
|
-
{items.map((item)
|
|
282
|
-
|
|
283
|
-
key={item.id}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return handleItemChange(item.id, checked);
|
|
289
|
-
}}
|
|
290
|
-
>
|
|
291
|
-
{item.label}
|
|
292
|
-
</Checkbox>
|
|
293
|
-
))}
|
|
236
|
+
{items.map(function renderItem(item) {
|
|
237
|
+
return (
|
|
238
|
+
<Checkbox key={item.id} name={item.id} value={item.id}>
|
|
239
|
+
{item.label}
|
|
240
|
+
</Checkbox>
|
|
241
|
+
);
|
|
242
|
+
})}
|
|
294
243
|
</CheckboxGroup>
|
|
295
244
|
);
|
|
296
245
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,99 +1,164 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let react = require("react");
|
|
25
|
+
react = __toESM(react);
|
|
26
|
+
let _bento_container = require("@bento/container");
|
|
27
|
+
let _bento_use_data_attributes = require("@bento/use-data-attributes");
|
|
28
|
+
let _bento_icon = require("@bento/icon");
|
|
29
|
+
let _bento_input = require("@bento/input");
|
|
30
|
+
let _bento_slots = require("@bento/slots");
|
|
31
|
+
let _bento_use_props = require("@bento/use-props");
|
|
32
|
+
let _bento_visually_hidden = require("@bento/visually-hidden");
|
|
33
|
+
let _react_aria_utils = require("@react-aria/utils");
|
|
34
|
+
let react_aria = require("react-aria");
|
|
35
|
+
let react_stately = require("react-stately");
|
|
36
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
//#region src/checkbox-group-state.tsx
|
|
38
|
+
const CheckboxGroupStateContext = react.default.createContext(null);
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/checkbox.tsx
|
|
41
|
+
/**
|
|
42
|
+
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
43
|
+
*/
|
|
44
|
+
const Checkbox = (0, _bento_slots.withSlots)("BentoCheckbox", function Checkbox(args) {
|
|
45
|
+
const { props, apply } = (0, _bento_use_props.useProps)(args);
|
|
46
|
+
const groupState = (0, react.useContext)(CheckboxGroupStateContext);
|
|
47
|
+
const ref = (0, react.useRef)(null);
|
|
48
|
+
const inputRef = (0, _react_aria_utils.useObjectRef)((0, react.useMemo)(() => (0, _react_aria_utils.mergeRefs)(ref, props.inputRef), [ref, props.inputRef]));
|
|
49
|
+
const { isFocused, isFocusVisible, focusProps } = (0, react_aria.useFocusRing)();
|
|
50
|
+
const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? (0, react_aria.useCheckboxGroupItem)({
|
|
51
|
+
...props,
|
|
52
|
+
value: props.value
|
|
53
|
+
}, groupState, inputRef) : (0, react_aria.useCheckbox)(props, (0, react_stately.useToggleState)(props), inputRef);
|
|
54
|
+
const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
|
|
55
|
+
const { hoverProps, isHovered } = (0, react_aria.useHover)({
|
|
56
|
+
...props,
|
|
57
|
+
isDisabled: interactionDisabled
|
|
58
|
+
});
|
|
59
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_bento_container.Container, {
|
|
60
|
+
as: "label",
|
|
61
|
+
"aria-checked": props.isIndeterminate ? "mixed" : void 0,
|
|
62
|
+
...apply((0, _react_aria_utils.mergeProps)(labelProps, hoverProps)),
|
|
63
|
+
...(0, _bento_use_data_attributes.useDataAttributes)({
|
|
64
|
+
selected: isSelected,
|
|
65
|
+
pressed: isPressed,
|
|
66
|
+
hovered: isHovered,
|
|
67
|
+
focused: isFocused,
|
|
68
|
+
focusVisible: isFocusVisible,
|
|
69
|
+
disabled: interactionDisabled,
|
|
70
|
+
readonly: isReadOnly,
|
|
71
|
+
invalid: isInvalid,
|
|
72
|
+
required: props.isRequired,
|
|
73
|
+
indeterminate: props.isIndeterminate
|
|
74
|
+
}),
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_bento_visually_hidden.VisuallyHidden, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_bento_input.Input, {
|
|
77
|
+
...(0, _react_aria_utils.mergeProps)(inputProps, focusProps),
|
|
78
|
+
ref: inputRef
|
|
79
|
+
}) }),
|
|
80
|
+
props.isIndeterminate ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_bento_icon.Icon, {
|
|
81
|
+
slot: "icon-indeterminate",
|
|
82
|
+
icon: "checkboxIndeterminate",
|
|
83
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
84
|
+
viewBox: "0 0 24 24",
|
|
85
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
86
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
87
|
+
x: "6",
|
|
88
|
+
y: "11",
|
|
89
|
+
width: "12",
|
|
90
|
+
height: "2",
|
|
91
|
+
fill: "currentColor"
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
}) : isSelected ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_bento_icon.Icon, {
|
|
95
|
+
slot: "icon-checked",
|
|
96
|
+
icon: "checkboxChecked",
|
|
97
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
98
|
+
viewBox: "0 0 24 24",
|
|
99
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
100
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
101
|
+
d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z",
|
|
102
|
+
fill: "currentColor"
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_bento_icon.Icon, {
|
|
106
|
+
slot: "icon-unchecked",
|
|
107
|
+
icon: "checkboxUnchecked",
|
|
108
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
109
|
+
width: 24,
|
|
110
|
+
height: 24,
|
|
111
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
112
|
+
x: 4,
|
|
113
|
+
y: 4,
|
|
114
|
+
width: 16,
|
|
115
|
+
height: 16,
|
|
116
|
+
rx: 3,
|
|
117
|
+
fill: "none",
|
|
118
|
+
stroke: "gray",
|
|
119
|
+
strokeWidth: 2
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
}),
|
|
123
|
+
props.children
|
|
124
|
+
]
|
|
125
|
+
});
|
|
67
126
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/checkbox-group.tsx
|
|
129
|
+
/**
|
|
130
|
+
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
131
|
+
*/
|
|
132
|
+
const CheckboxGroup = (0, _bento_slots.withSlots)("BentoCheckboxGroup", function CheckboxGroup(args) {
|
|
133
|
+
const { props, apply } = (0, _bento_use_props.useProps)(args);
|
|
134
|
+
const state = (0, react_stately.useCheckboxGroupState)(props);
|
|
135
|
+
const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = (0, react_aria.useCheckboxGroup)({
|
|
136
|
+
...props,
|
|
137
|
+
label: props.label ?? "Checkbox Group",
|
|
138
|
+
description: props.description ?? "Description"
|
|
139
|
+
}, state);
|
|
140
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckboxGroupStateContext.Provider, {
|
|
141
|
+
value: state,
|
|
142
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_bento_container.Container, {
|
|
143
|
+
...apply(groupProps),
|
|
144
|
+
...(0, _bento_use_data_attributes.useDataAttributes)({
|
|
145
|
+
orientation: props.orientation || "vertical",
|
|
146
|
+
invalid: state.isInvalid,
|
|
147
|
+
disabled: state.isDisabled,
|
|
148
|
+
readonly: state.isReadOnly,
|
|
149
|
+
required: state.isRequired
|
|
150
|
+
}),
|
|
151
|
+
slots: {
|
|
152
|
+
label: labelProps,
|
|
153
|
+
description: descriptionProps,
|
|
154
|
+
error: (0, react_aria.mergeProps)(errorMessageProps, validationResult)
|
|
155
|
+
},
|
|
156
|
+
children: props.children
|
|
157
|
+
})
|
|
158
|
+
});
|
|
94
159
|
});
|
|
95
|
-
|
|
160
|
+
//#endregion
|
|
96
161
|
exports.Checkbox = Checkbox;
|
|
97
162
|
exports.CheckboxGroup = CheckboxGroup;
|
|
98
|
-
|
|
163
|
+
|
|
99
164
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -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","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,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;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAeC,sBAAA,EAAa;AAE/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAW,UAAA,EAAY,UAAA,EAAY,SAAA,EAAU,GAAI,UAAA,GACzFC,8BAAA;AAAA,IACE;AAAA,MACE,GAAG,KAAA;AAAA;AAAA;AAAA,MAGH,OAAQ,KAAA,CAAgD;AAAA,KAC1D;AAAA,IACA,UAAA;AAAA,IACA;AAAA,MAEFC,qBAAA,CAAY,KAAA,EAAOC,2BAAA,CAAe,KAAK,GAAG,QAAQ,CAAA;A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E,GAAG,KAAA,EAAO,KAAA,EAAO,KAAA,CAAM,SAAS,gBAAA,EAAkB,WAAA,EAAa,KAAA,CAAM,WAAA,IAAe,aAAA,EAAc;AAAA,IACpG;AAAA,GACF;AAEA,EAAA,uBACEtB,wBAAA,aAAA,CAAC,yBAAA,CAA0B,UAA1B,EAAmC,KAAA,EAAO,KAAA,EAAA,kBACzCA,uBAAAA,CAAA,aAAA;AAAA,IAACc,mBAAAA;AAAA,IAAA;AAAA,MACE,GAAG,MAAM,UAAU,CAAA;AAAA,MACnB,GAAGE,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,CAAA;AAAA,MACD,KAAA,EAAO;AAAA,QACL,KAAA,EAAO,UAAA;AAAA,QACP,WAAA,EAAa,gBAAA;AAAA,QACb,KAAA,EAAOD,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"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["React","Container","VisuallyHidden","Input","Icon","Container"],"sources":["../src/checkbox-group-state.tsx","../src/checkbox.tsx","../src/checkbox-group.tsx"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAa,4BAA4BA,MAAAA,QAAM,cAAyC,IAAI;;;;;;ACgD5F,MAAa,YAAA,GAAA,aAAA,WAAqB,iBAAiB,SAAS,SAAS,MAAqB;CACxF,MAAM,EAAE,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,iBAAAA,WAAD;GACE,GAAI,MAAM,UAAU;GACpB,IAAA,GAAA,2BAAA,mBAAsB;IACpB,aAAa,MAAM,eAAe;IAClC,SAAS,MAAM;IACf,UAAU,MAAM;IAChB,UAAU,MAAM;IAChB,UAAU,MAAM;GAClB,CAAC;GACD,OAAO;IACL,OAAO;IACP,aAAa;IACb,QAAA,GAAA,WAAA,YAAkB,mBAAmB,gBAAgB;GACvD;aAEC,MAAM;EACE,CAAA;CACuB,CAAA;AAExC,CAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,64 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { AriaCheckboxProps, AriaCheckboxGroupProps } from 'react-aria';
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ContainerProps } from "@bento/container";
|
|
3
|
+
import { AriaCheckboxGroupProps, AriaCheckboxProps } from "react-aria";
|
|
5
4
|
|
|
5
|
+
//#region src/checkbox.d.ts
|
|
6
6
|
interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
7
|
+
/** The value of the checkbox, used when submitting an HTML form. */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** The name of the checkbox. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** A ref for the HTML input element. */
|
|
12
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
13
|
+
/** The label for the checkbox. Accepts any renderable node. */
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
/** Whether the checkbox is required or not. */
|
|
16
|
+
isRequired?: boolean;
|
|
17
|
+
/** Whether the input can be selected but not changed by the user. */
|
|
18
|
+
isReadOnly?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the checkbox is disabled or not. Shows that a selection exists,
|
|
21
|
+
* but is not available in that circumstance.
|
|
22
|
+
*/
|
|
23
|
+
isDisabled?: boolean;
|
|
24
|
+
/** Whether the element should receive focus on render. */
|
|
25
|
+
autoFocus?: boolean;
|
|
26
|
+
/** Whether the checkbox is in an indeterminate state. */
|
|
27
|
+
isIndeterminate?: boolean;
|
|
28
|
+
/** Whether the checkbox is in a selected state. */
|
|
29
|
+
isSelected?: boolean;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
33
33
|
*/
|
|
34
|
-
declare const Checkbox: React.MemoExoticComponent<React.ComponentType<
|
|
35
|
-
|
|
34
|
+
declare const Checkbox: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/checkbox-group.d.ts
|
|
36
37
|
interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
38
|
+
/** The current value of the checkbox group (controlled). */
|
|
39
|
+
value?: string[];
|
|
40
|
+
/** The default value of the checkbox group (uncontrolled). */
|
|
41
|
+
defaultValue?: string[];
|
|
42
|
+
/** Whether the input is disabled. */
|
|
43
|
+
isDisabled?: boolean;
|
|
44
|
+
/** Whether the input can be selected but not changed by the user. */
|
|
45
|
+
isReadOnly?: boolean;
|
|
46
|
+
/** Whether user input is required on the input before form submission. */
|
|
47
|
+
isRequired?: boolean;
|
|
48
|
+
/** Whether the input value is invalid. */
|
|
49
|
+
isInvalid?: boolean;
|
|
50
|
+
/** The name of the input element, used when submitting an HTML form. */
|
|
51
|
+
name?: string;
|
|
52
|
+
/**
|
|
53
|
+
* 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
|
+
*/
|
|
56
|
+
form?: string;
|
|
57
|
+
/** Checkbox children. */
|
|
58
|
+
children?: React.ReactNode;
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
61
62
|
*/
|
|
62
|
-
declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<
|
|
63
|
-
|
|
64
|
-
export { Checkbox, CheckboxGroup,
|
|
63
|
+
declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { Checkbox, CheckboxGroup, CheckboxGroupProps, CheckboxProps };
|
|
66
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/checkbox.tsx","../src/checkbox-group.tsx"],"mappings":";;;;;UAaiB,aAAA,SAAsB,iBAAA,EAAmB,IAAA,CAAK,cAAA,QAAsB,iBAAA;;EAEnF,KAAA;EAF6B;EAK7B,IAAA;EAL6D;EAQ7D,QAAA,GAAW,KAAA,CAAM,GAAA,CAAI,gBAAA;EAAA;EAGrB,QAAA,GAAW,KAAA,CAAM,SAAA;EAAN;EAGX,UAAA;EAdwD;EAiBxD,UAAA;EAjB4D;;;;EAuB5D,UAAA;EArBA;EAwBA,SAAA;EAlBA;EAqBA,eAAA;EArBiB;EAwBjB,UAAA;AAAA;;;;cAMW,QAAA,EAAQ,KAAA,CAAA,mBAAA,CAAA,KAAA,CAAA,aAAA;;;UC1CJ,kBAAA,SAA2B,sBAAA,EAAwB,IAAA,CAAK,cAAA,QAAsB,sBAAA;;EAE7F,KAAA;EDE6B;ECC7B,YAAA;EDD6D;ECI7D,UAAA;EDIqB;ECDrB,UAAA;EDIW;ECDX,UAAA;EDVwD;ECaxD,SAAA;EDb4D;ECgB5D,IAAA;EDhBwD;;;;ECsBxD,IAAA;EDdA;ECiBA,QAAA,GAAW,KAAA,CAAM,SAAA;AAAA;;;;cAMN,aAAA,EAAa,KAAA,CAAA,mBAAA,CAAA,KAAA,CAAA,aAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ContainerProps } from "@bento/container";
|
|
3
|
+
import { AriaCheckboxGroupProps, AriaCheckboxProps } from "react-aria";
|
|
4
|
+
|
|
5
|
+
//#region src/checkbox.d.ts
|
|
6
|
+
interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
|
|
7
|
+
/** The value of the checkbox, used when submitting an HTML form. */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** The name of the checkbox. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** A ref for the HTML input element. */
|
|
12
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
13
|
+
/** The label for the checkbox. Accepts any renderable node. */
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
/** Whether the checkbox is required or not. */
|
|
16
|
+
isRequired?: boolean;
|
|
17
|
+
/** Whether the input can be selected but not changed by the user. */
|
|
18
|
+
isReadOnly?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the checkbox is disabled or not. Shows that a selection exists,
|
|
21
|
+
* but is not available in that circumstance.
|
|
22
|
+
*/
|
|
23
|
+
isDisabled?: boolean;
|
|
24
|
+
/** Whether the element should receive focus on render. */
|
|
25
|
+
autoFocus?: boolean;
|
|
26
|
+
/** Whether the checkbox is in an indeterminate state. */
|
|
27
|
+
isIndeterminate?: boolean;
|
|
28
|
+
/** Whether the checkbox is in a selected state. */
|
|
29
|
+
isSelected?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
33
|
+
*/
|
|
34
|
+
declare const Checkbox: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/checkbox-group.d.ts
|
|
37
|
+
interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
|
|
38
|
+
/** The current value of the checkbox group (controlled). */
|
|
39
|
+
value?: string[];
|
|
40
|
+
/** The default value of the checkbox group (uncontrolled). */
|
|
41
|
+
defaultValue?: string[];
|
|
42
|
+
/** Whether the input is disabled. */
|
|
43
|
+
isDisabled?: boolean;
|
|
44
|
+
/** Whether the input can be selected but not changed by the user. */
|
|
45
|
+
isReadOnly?: boolean;
|
|
46
|
+
/** Whether user input is required on the input before form submission. */
|
|
47
|
+
isRequired?: boolean;
|
|
48
|
+
/** Whether the input value is invalid. */
|
|
49
|
+
isInvalid?: boolean;
|
|
50
|
+
/** The name of the input element, used when submitting an HTML form. */
|
|
51
|
+
name?: string;
|
|
52
|
+
/**
|
|
53
|
+
* 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
|
+
*/
|
|
56
|
+
form?: string;
|
|
57
|
+
/** Checkbox children. */
|
|
58
|
+
children?: React.ReactNode;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
62
|
+
*/
|
|
63
|
+
declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { Checkbox, CheckboxGroup, CheckboxGroupProps, CheckboxProps };
|
|
66
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/checkbox.tsx","../src/checkbox-group.tsx"],"mappings":";;;;;UAaiB,aAAA,SAAsB,iBAAA,EAAmB,IAAA,CAAK,cAAA,QAAsB,iBAAA;;EAEnF,KAAA;EAF6B;EAK7B,IAAA;EAL6D;EAQ7D,QAAA,GAAW,KAAA,CAAM,GAAA,CAAI,gBAAA;EAAA;EAGrB,QAAA,GAAW,KAAA,CAAM,SAAA;EAAN;EAGX,UAAA;EAdwD;EAiBxD,UAAA;EAjB4D;;;;EAuB5D,UAAA;EArBA;EAwBA,SAAA;EAlBA;EAqBA,eAAA;EArBiB;EAwBjB,UAAA;AAAA;;;;cAMW,QAAA,EAAQ,KAAA,CAAA,mBAAA,CAAA,KAAA,CAAA,aAAA;;;UC1CJ,kBAAA,SAA2B,sBAAA,EAAwB,IAAA,CAAK,cAAA,QAAsB,sBAAA;;EAE7F,KAAA;EDE6B;ECC7B,YAAA;EDD6D;ECI7D,UAAA;EDIqB;ECDrB,UAAA;EDIW;ECDX,UAAA;EDVwD;ECaxD,SAAA;EDb4D;ECgB5D,IAAA;EDhBwD;;;;ECsBxD,IAAA;EDdA;ECiBA,QAAA,GAAW,KAAA,CAAM,SAAA;AAAA;;;;cAMN,aAAA,EAAa,KAAA,CAAA,mBAAA,CAAA,KAAA,CAAA,aAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React, { useContext, useMemo, useRef } from "react";
|
|
2
|
+
import { Container } from "@bento/container";
|
|
3
|
+
import { useDataAttributes } from "@bento/use-data-attributes";
|
|
4
|
+
import { Icon } from "@bento/icon";
|
|
5
|
+
import { Input } from "@bento/input";
|
|
6
|
+
import { withSlots } from "@bento/slots";
|
|
7
|
+
import { useProps } from "@bento/use-props";
|
|
8
|
+
import { VisuallyHidden } from "@bento/visually-hidden";
|
|
9
|
+
import { mergeProps, mergeRefs, useObjectRef } from "@react-aria/utils";
|
|
10
|
+
import { mergeProps as mergeProps$1, useCheckbox, useCheckboxGroup, useCheckboxGroupItem, useFocusRing, useHover } from "react-aria";
|
|
11
|
+
import { useCheckboxGroupState, useToggleState } from "react-stately";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
//#region src/checkbox-group-state.tsx
|
|
14
|
+
const CheckboxGroupStateContext = React.createContext(null);
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/checkbox.tsx
|
|
17
|
+
/**
|
|
18
|
+
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
19
|
+
*/
|
|
20
|
+
const Checkbox = withSlots("BentoCheckbox", function Checkbox(args) {
|
|
21
|
+
const { props, apply } = useProps(args);
|
|
22
|
+
const groupState = useContext(CheckboxGroupStateContext);
|
|
23
|
+
const ref = useRef(null);
|
|
24
|
+
const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
|
|
25
|
+
const { isFocused, isFocusVisible, focusProps } = useFocusRing();
|
|
26
|
+
const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? useCheckboxGroupItem({
|
|
27
|
+
...props,
|
|
28
|
+
value: props.value
|
|
29
|
+
}, groupState, inputRef) : useCheckbox(props, useToggleState(props), inputRef);
|
|
30
|
+
const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
|
|
31
|
+
const { hoverProps, isHovered } = useHover({
|
|
32
|
+
...props,
|
|
33
|
+
isDisabled: interactionDisabled
|
|
34
|
+
});
|
|
35
|
+
return /* @__PURE__ */ jsxs(Container, {
|
|
36
|
+
as: "label",
|
|
37
|
+
"aria-checked": props.isIndeterminate ? "mixed" : void 0,
|
|
38
|
+
...apply(mergeProps(labelProps, hoverProps)),
|
|
39
|
+
...useDataAttributes({
|
|
40
|
+
selected: isSelected,
|
|
41
|
+
pressed: isPressed,
|
|
42
|
+
hovered: isHovered,
|
|
43
|
+
focused: isFocused,
|
|
44
|
+
focusVisible: isFocusVisible,
|
|
45
|
+
disabled: interactionDisabled,
|
|
46
|
+
readonly: isReadOnly,
|
|
47
|
+
invalid: isInvalid,
|
|
48
|
+
required: props.isRequired,
|
|
49
|
+
indeterminate: props.isIndeterminate
|
|
50
|
+
}),
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Input, {
|
|
53
|
+
...mergeProps(inputProps, focusProps),
|
|
54
|
+
ref: inputRef
|
|
55
|
+
}) }),
|
|
56
|
+
props.isIndeterminate ? /* @__PURE__ */ jsx(Icon, {
|
|
57
|
+
slot: "icon-indeterminate",
|
|
58
|
+
icon: "checkboxIndeterminate",
|
|
59
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
60
|
+
viewBox: "0 0 24 24",
|
|
61
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
62
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
63
|
+
x: "6",
|
|
64
|
+
y: "11",
|
|
65
|
+
width: "12",
|
|
66
|
+
height: "2",
|
|
67
|
+
fill: "currentColor"
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}) : isSelected ? /* @__PURE__ */ jsx(Icon, {
|
|
71
|
+
slot: "icon-checked",
|
|
72
|
+
icon: "checkboxChecked",
|
|
73
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
74
|
+
viewBox: "0 0 24 24",
|
|
75
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
76
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
77
|
+
d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z",
|
|
78
|
+
fill: "currentColor"
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
}) : /* @__PURE__ */ jsx(Icon, {
|
|
82
|
+
slot: "icon-unchecked",
|
|
83
|
+
icon: "checkboxUnchecked",
|
|
84
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
85
|
+
width: 24,
|
|
86
|
+
height: 24,
|
|
87
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
88
|
+
x: 4,
|
|
89
|
+
y: 4,
|
|
90
|
+
width: 16,
|
|
91
|
+
height: 16,
|
|
92
|
+
rx: 3,
|
|
93
|
+
fill: "none",
|
|
94
|
+
stroke: "gray",
|
|
95
|
+
strokeWidth: 2
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
}),
|
|
99
|
+
props.children
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/checkbox-group.tsx
|
|
105
|
+
/**
|
|
106
|
+
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
107
|
+
*/
|
|
108
|
+
const CheckboxGroup = withSlots("BentoCheckboxGroup", function CheckboxGroup(args) {
|
|
109
|
+
const { props, apply } = useProps(args);
|
|
110
|
+
const state = useCheckboxGroupState(props);
|
|
111
|
+
const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup({
|
|
112
|
+
...props,
|
|
113
|
+
label: props.label ?? "Checkbox Group",
|
|
114
|
+
description: props.description ?? "Description"
|
|
115
|
+
}, state);
|
|
116
|
+
return /* @__PURE__ */ jsx(CheckboxGroupStateContext.Provider, {
|
|
117
|
+
value: state,
|
|
118
|
+
children: /* @__PURE__ */ jsx(Container, {
|
|
119
|
+
...apply(groupProps),
|
|
120
|
+
...useDataAttributes({
|
|
121
|
+
orientation: props.orientation || "vertical",
|
|
122
|
+
invalid: state.isInvalid,
|
|
123
|
+
disabled: state.isDisabled,
|
|
124
|
+
readonly: state.isReadOnly,
|
|
125
|
+
required: state.isRequired
|
|
126
|
+
}),
|
|
127
|
+
slots: {
|
|
128
|
+
label: labelProps,
|
|
129
|
+
description: descriptionProps,
|
|
130
|
+
error: mergeProps$1(errorMessageProps, validationResult)
|
|
131
|
+
},
|
|
132
|
+
children: props.children
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
//#endregion
|
|
137
|
+
export { Checkbox, CheckboxGroup };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["mergeProps"],"sources":["../src/checkbox-group-state.tsx","../src/checkbox.tsx","../src/checkbox-group.tsx"],"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"],"mappings":";;;;;;;;;;;;;AAGA,MAAa,4BAA4B,MAAM,cAAyC,IAAI;;;;;;ACgD5F,MAAa,WAAW,UAAU,iBAAiB,SAAS,SAAS,MAAqB;CACxF,MAAM,EAAE,OAAO,UAAU,SAAS,IAAI;CACtC,MAAM,aAAa,WAAW,yBAAyB;CACvD,MAAM,MAAM,OAAyB,IAAI;CACzC,MAAM,WAAW,aAAa,cAAc,UAAU,KAAK,MAAM,QAAQ,GAAG,CAAC,KAAK,MAAM,QAAQ,CAAC,CAAC;CAClG,MAAM,EAAE,WAAW,gBAAgB,eAAe,aAAa;CAE/D,MAAM,EAAE,YAAY,YAAY,YAAY,WAAW,YAAY,YAAY,cAAc,aACzF,qBACE;EACE,GAAG;EAGH,OAAQ,MAAgD;CAC1D,GACA,YACA,QACF,IACA,YAAY,OAAO,eAAe,KAAK,GAAG,QAAQ;CAEtD,MAAM,sBAAsB,MAAM,cAAc,cAAc;CAC9D,MAAM,EAAE,YAAY,cAAc,SAAS;EACzC,GAAG;EACH,YAAY;CACd,CAAC;CAED,OACE,qBAAC,WAAD;EACE,IAAG;EACH,gBAAc,MAAM,kBAAkB,UAAU,KAAA;EAChD,GAAI,MAAM,WAAW,YAAY,UAAU,CAAC;EAC5C,GAAI,kBAAkB;GACpB,UAAU;GACV,SAAS;GACT,SAAS;GACT,SAAS;GACT,cAAc;GACd,UAAU;GACV,UAAU;GACV,SAAS;GACT,UAAU,MAAM;GAChB,eAAe,MAAM;EACvB,CAAC;YAfH;GAiBE,oBAAC,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MAAM;IAChB,UAAU,MAAM;GAClB,CAAC;GACD,OAAO;IACL,OAAO;IACP,aAAa;IACb,OAAOA,aAAW,mBAAmB,gBAAgB;GACvD;aAEC,MAAM;EACE,CAAA;CACuB,CAAA;AAExC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento/checkbox",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Checkbox component",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"lint": "biome lint &&
|
|
11
|
-
"
|
|
12
|
-
"prepublishOnly": "node ../../scripts/compile-readme.ts",
|
|
13
|
-
"pretest": "npm run build",
|
|
9
|
+
"build": "tsdown",
|
|
10
|
+
"lint": "biome lint && tsgo --noEmit",
|
|
11
|
+
"prepublishOnly": "node ../../../scripts/compile-readme.ts",
|
|
14
12
|
"test": "vitest --run",
|
|
15
|
-
"test:watch": "vitest"
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"typecheck": "tsgo --noEmit -p tsconfig.json"
|
|
16
15
|
},
|
|
17
16
|
"repository": {
|
|
18
17
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/godaddy/
|
|
18
|
+
"url": "git+https://github.com/godaddy/antares.git"
|
|
20
19
|
},
|
|
21
20
|
"keywords": [
|
|
22
21
|
"accessibility",
|
|
@@ -31,9 +30,9 @@
|
|
|
31
30
|
"author": "GoDaddy Operating Company, LLC",
|
|
32
31
|
"license": "MIT",
|
|
33
32
|
"bugs": {
|
|
34
|
-
"url": "https://github.com/godaddy/
|
|
33
|
+
"url": "https://github.com/godaddy/antares/issues"
|
|
35
34
|
},
|
|
36
|
-
"homepage": "https://github.com/godaddy/
|
|
35
|
+
"homepage": "https://github.com/godaddy/antares#readme",
|
|
37
36
|
"files": [
|
|
38
37
|
"dist",
|
|
39
38
|
"src",
|
|
@@ -41,15 +40,23 @@
|
|
|
41
40
|
],
|
|
42
41
|
"dependencies": {
|
|
43
42
|
"@bento/container": "^0.2.1",
|
|
44
|
-
"@bento/icon": "^0.
|
|
45
|
-
"@bento/input": "^0.1.
|
|
43
|
+
"@bento/icon": "^0.2.0",
|
|
44
|
+
"@bento/input": "^0.1.1",
|
|
46
45
|
"@bento/slots": "^0.3.0",
|
|
47
46
|
"@bento/use-data-attributes": "^0.1.1",
|
|
48
|
-
"@bento/use-props": "^0.2.
|
|
47
|
+
"@bento/use-props": "^0.2.3",
|
|
49
48
|
"@bento/visually-hidden": "^0.1.1",
|
|
50
|
-
"@react-aria/utils": "^3.
|
|
51
|
-
"react-aria": "^3.
|
|
52
|
-
"react-stately": "^3.
|
|
49
|
+
"@react-aria/utils": "^3.34.0",
|
|
50
|
+
"react-aria": "^3.48.0",
|
|
51
|
+
"react-stately": "^3.46.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/react": "^19.2.15",
|
|
55
|
+
"@types/react-dom": "^19.2.3",
|
|
56
|
+
"tsdown": "^0.22.1",
|
|
57
|
+
"typescript": "^6.0.3",
|
|
58
|
+
"vitest": "^4.1.7",
|
|
59
|
+
"vitest-browser-react": "^2.2.0"
|
|
53
60
|
},
|
|
54
61
|
"peerDependencies": {
|
|
55
62
|
"react": "18.x || 19.x",
|
|
@@ -58,8 +65,8 @@
|
|
|
58
65
|
"exports": {
|
|
59
66
|
".": {
|
|
60
67
|
"import": {
|
|
61
|
-
"types": "./dist/index.d.
|
|
62
|
-
"default": "./dist/index.
|
|
68
|
+
"types": "./dist/index.d.mts",
|
|
69
|
+
"default": "./dist/index.mjs"
|
|
63
70
|
},
|
|
64
71
|
"require": {
|
|
65
72
|
"types": "./dist/index.d.cts",
|
package/dist/index.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as _bento_slots from '@bento/slots';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { ContainerProps } from '@bento/container';
|
|
4
|
-
import { AriaCheckboxProps, AriaCheckboxGroupProps } from 'react-aria';
|
|
5
|
-
|
|
6
|
-
interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
|
|
7
|
-
/** The value of the checkbox, used when submitting an HTML form. */
|
|
8
|
-
value?: string;
|
|
9
|
-
/** The name of the checkbox. */
|
|
10
|
-
name?: string;
|
|
11
|
-
/** A ref for the HTML input element. */
|
|
12
|
-
inputRef?: React.Ref<HTMLInputElement>;
|
|
13
|
-
/** The label for the checkbox. Accepts any renderable node. */
|
|
14
|
-
children?: React.ReactNode;
|
|
15
|
-
/** Whether the checkbox is required or not. */
|
|
16
|
-
isRequired?: boolean;
|
|
17
|
-
/** Whether the input can be selected but not changed by the user. */
|
|
18
|
-
isReadOnly?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Whether the checkbox is disabled or not. Shows that a selection exists,
|
|
21
|
-
* but is not available in that circumstance.
|
|
22
|
-
*/
|
|
23
|
-
isDisabled?: boolean;
|
|
24
|
-
/** Whether the element should receive focus on render. */
|
|
25
|
-
autoFocus?: boolean;
|
|
26
|
-
/** Whether the checkbox is in an indeterminate state. */
|
|
27
|
-
isIndeterminate?: boolean;
|
|
28
|
-
/** Whether the checkbox is in a selected state. */
|
|
29
|
-
isSelected?: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
33
|
-
*/
|
|
34
|
-
declare const Checkbox: React.MemoExoticComponent<React.ComponentType<CheckboxProps & _bento_slots.Slots>>;
|
|
35
|
-
|
|
36
|
-
interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
|
|
37
|
-
/** The current value of the checkbox group (controlled). */
|
|
38
|
-
value?: string[];
|
|
39
|
-
/** The default value of the checkbox group (uncontrolled). */
|
|
40
|
-
defaultValue?: string[];
|
|
41
|
-
/** Whether the input is disabled. */
|
|
42
|
-
isDisabled?: boolean;
|
|
43
|
-
/** Whether the input can be selected but not changed by the user. */
|
|
44
|
-
isReadOnly?: boolean;
|
|
45
|
-
/** Whether user input is required on the input before form submission. */
|
|
46
|
-
isRequired?: boolean;
|
|
47
|
-
/** Whether the input value is invalid. */
|
|
48
|
-
isInvalid?: boolean;
|
|
49
|
-
/** The name of the input element, used when submitting an HTML form. */
|
|
50
|
-
name?: string;
|
|
51
|
-
/**
|
|
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.
|
|
54
|
-
*/
|
|
55
|
-
form?: string;
|
|
56
|
-
/** Checkbox children. */
|
|
57
|
-
children?: React.ReactNode;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
61
|
-
*/
|
|
62
|
-
declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<CheckboxGroupProps & _bento_slots.Slots>>;
|
|
63
|
-
|
|
64
|
-
export { Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps };
|
package/dist/index.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React2, { useContext, useRef, useMemo } from 'react';
|
|
2
|
-
import { Container } from '@bento/container';
|
|
3
|
-
import { useDataAttributes } from '@bento/use-data-attributes';
|
|
4
|
-
import { Icon } from '@bento/icon';
|
|
5
|
-
import { Input } from '@bento/input';
|
|
6
|
-
import { withSlots } from '@bento/slots';
|
|
7
|
-
import { useProps } from '@bento/use-props';
|
|
8
|
-
import { VisuallyHidden } from '@bento/visually-hidden';
|
|
9
|
-
import { useObjectRef, mergeRefs, mergeProps } from '@react-aria/utils';
|
|
10
|
-
import { useFocusRing, useCheckboxGroupItem, useCheckbox, useHover, useCheckboxGroup, mergeProps as mergeProps$1 } from 'react-aria';
|
|
11
|
-
import { useToggleState, useCheckboxGroupState } from 'react-stately';
|
|
12
|
-
|
|
13
|
-
// src/checkbox.tsx
|
|
14
|
-
var CheckboxGroupStateContext = React2.createContext(null);
|
|
15
|
-
|
|
16
|
-
// src/checkbox.tsx
|
|
17
|
-
var Checkbox = withSlots("BentoCheckbox", function Checkbox2(args) {
|
|
18
|
-
const { props, apply } = useProps(args);
|
|
19
|
-
const groupState = useContext(CheckboxGroupStateContext);
|
|
20
|
-
const ref = useRef(null);
|
|
21
|
-
const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
|
|
22
|
-
const { isFocused, isFocusVisible, focusProps } = useFocusRing();
|
|
23
|
-
const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? useCheckboxGroupItem(
|
|
24
|
-
{
|
|
25
|
-
...props,
|
|
26
|
-
// Value is optional for standalone checkboxes, but required for CheckboxGroup items;
|
|
27
|
-
// it's passed explicitly here to avoid typescript error (requires ignore)(recommendation from React Aria).
|
|
28
|
-
value: props.value
|
|
29
|
-
},
|
|
30
|
-
groupState,
|
|
31
|
-
inputRef
|
|
32
|
-
) : useCheckbox(props, useToggleState(props), inputRef);
|
|
33
|
-
const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
|
|
34
|
-
const { hoverProps, isHovered } = useHover({
|
|
35
|
-
...props,
|
|
36
|
-
isDisabled: interactionDisabled
|
|
37
|
-
});
|
|
38
|
-
return /* @__PURE__ */ React2.createElement(
|
|
39
|
-
Container,
|
|
40
|
-
{
|
|
41
|
-
as: "label",
|
|
42
|
-
"aria-checked": props.isIndeterminate ? "mixed" : void 0,
|
|
43
|
-
...apply(mergeProps(labelProps, hoverProps)),
|
|
44
|
-
...useDataAttributes({
|
|
45
|
-
selected: isSelected,
|
|
46
|
-
pressed: isPressed,
|
|
47
|
-
hovered: isHovered,
|
|
48
|
-
focused: isFocused,
|
|
49
|
-
focusVisible: isFocusVisible,
|
|
50
|
-
disabled: interactionDisabled,
|
|
51
|
-
readonly: isReadOnly,
|
|
52
|
-
invalid: isInvalid,
|
|
53
|
-
required: props.isRequired,
|
|
54
|
-
indeterminate: props.isIndeterminate
|
|
55
|
-
})
|
|
56
|
-
},
|
|
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
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
var CheckboxGroup = withSlots("BentoCheckboxGroup", function CheckboxGroup2(args) {
|
|
63
|
-
const { props, apply } = useProps(args);
|
|
64
|
-
const state = useCheckboxGroupState(props);
|
|
65
|
-
const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(
|
|
66
|
-
{ ...props, label: props.label ?? "Checkbox Group", description: props.description ?? "Description" },
|
|
67
|
-
state
|
|
68
|
-
);
|
|
69
|
-
return /* @__PURE__ */ React2.createElement(CheckboxGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2.createElement(
|
|
70
|
-
Container,
|
|
71
|
-
{
|
|
72
|
-
...apply(groupProps),
|
|
73
|
-
...useDataAttributes({
|
|
74
|
-
orientation: props.orientation || "vertical",
|
|
75
|
-
invalid: state.isInvalid,
|
|
76
|
-
disabled: state.isDisabled,
|
|
77
|
-
readonly: state.isReadOnly,
|
|
78
|
-
required: state.isRequired
|
|
79
|
-
}),
|
|
80
|
-
slots: {
|
|
81
|
-
label: labelProps,
|
|
82
|
-
description: descriptionProps,
|
|
83
|
-
error: mergeProps$1(errorMessageProps, validationResult)
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
props.children
|
|
87
|
-
));
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
export { Checkbox, CheckboxGroup };
|
|
91
|
-
//# sourceMappingURL=index.js.map
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,KA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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"]}
|