@bento/checkbox 0.2.2 → 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 -49
- package/dist/index.cjs +159 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -50
- 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 +18 -17
- package/dist/index.d.ts +0 -63
- package/dist/index.js +0 -93
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -177,75 +177,69 @@ import React, { useState } from 'react';
|
|
|
177
177
|
import { Checkbox, CheckboxGroup } from '@bento/checkbox';
|
|
178
178
|
import { Text } from '@bento/text';
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
const [checkedItems, setCheckedItems] = useState<Set<string>>(new Set());
|
|
180
|
+
const SELECT_ALL = 'select-all';
|
|
182
181
|
|
|
182
|
+
export function CheckboxGroupIndeterminateExample() {
|
|
183
183
|
const items = [
|
|
184
184
|
{ id: 'option1', label: 'Option 1' },
|
|
185
185
|
{ id: 'option2', label: 'Option 2' },
|
|
186
186
|
{ id: 'option3', label: 'Option 3' }
|
|
187
187
|
];
|
|
188
|
-
|
|
189
188
|
const allItemIds = items.map(function getItemId(item) {
|
|
190
189
|
return item.id;
|
|
191
190
|
});
|
|
192
|
-
const isAllSelected = checkedItems.size === items.length;
|
|
193
|
-
const isIndeterminate = checkedItems.size > 0 && checkedItems.size < items.length;
|
|
194
191
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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;
|
|
200
213
|
}
|
|
201
|
-
}
|
|
202
214
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (checked) {
|
|
207
|
-
newSet.add(itemId);
|
|
208
|
-
if (
|
|
209
|
-
allItemIds.every(function checkItemInSet(id) {
|
|
210
|
-
return newSet.has(id);
|
|
211
|
-
})
|
|
212
|
-
) {
|
|
213
|
-
newSet.add('select-all');
|
|
214
|
-
}
|
|
215
|
-
} else {
|
|
216
|
-
newSet.delete(itemId);
|
|
217
|
-
newSet.delete('select-all');
|
|
218
|
-
}
|
|
219
|
-
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;
|
|
220
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
|
+
}
|
|
221
227
|
}
|
|
222
228
|
|
|
223
229
|
return (
|
|
224
|
-
<CheckboxGroup value={
|
|
230
|
+
<CheckboxGroup value={checkedItems} onChange={handleGroupChange} data-value={checkedItems}>
|
|
225
231
|
<Text slot="label">Select Items</Text>
|
|
226
|
-
<Checkbox
|
|
227
|
-
name="select-all"
|
|
228
|
-
value="select-all"
|
|
229
|
-
isSelected={isAllSelected}
|
|
230
|
-
isIndeterminate={isIndeterminate}
|
|
231
|
-
onChange={handleSelectAll}
|
|
232
|
-
>
|
|
232
|
+
<Checkbox name={SELECT_ALL} value={SELECT_ALL} isIndeterminate={isIndeterminate}>
|
|
233
233
|
Select All
|
|
234
234
|
</Checkbox>
|
|
235
235
|
|
|
236
|
-
{items.map((item)
|
|
237
|
-
|
|
238
|
-
key={item.id}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return handleItemChange(item.id, checked);
|
|
244
|
-
}}
|
|
245
|
-
>
|
|
246
|
-
{item.label}
|
|
247
|
-
</Checkbox>
|
|
248
|
-
))}
|
|
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
|
+
})}
|
|
249
243
|
</CheckboxGroup>
|
|
250
244
|
);
|
|
251
245
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,100 +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
|
-
|
|
67
|
-
|
|
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
|
+
});
|
|
68
126
|
});
|
|
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
|
-
|
|
94
|
-
|
|
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
|
+
});
|
|
95
159
|
});
|
|
96
|
-
|
|
160
|
+
//#endregion
|
|
97
161
|
exports.Checkbox = Checkbox;
|
|
98
162
|
exports.CheckboxGroup = CheckboxGroup;
|
|
99
|
-
|
|
163
|
+
|
|
100
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","jsxs","Container","mergeProps","useDataAttributes","jsx","VisuallyHidden","Input","Icon","CheckboxGroup","useCheckboxGroupState","useCheckboxGroup"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4BA,sBAAA,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,iBAAW,yBAAyB,CAAA;AACvD,EAAA,MAAM,GAAA,GAAMC,aAAyB,IAAI,CAAA;AACzC,EAAA,MAAM,QAAA,GAAWC,kBAAA,CAAaC,aAAA,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;AAA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QoB,mCAAsB,KAAK,CAAA;AACzC,EAAA,MAAM,EAAE,UAAA,EAAY,UAAA,EAAY,kBAAkB,iBAAA,EAAmB,GAAG,kBAAiB,GAAIC,0BAAA;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,uBACEN,cAAAA,CAAC,yBAAA,CAA0B,UAA1B,EAAmC,KAAA,EAAO,OACzC,QAAA,kBAAAA,cAAAA;AAAA,IAACH,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,OACvD;AAAA,MAEC,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,GACT,EACF,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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AkB,aAAa,MAAM,eAAe;CAAc,GACpG,KACF;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAC,0BAA0B,UAA3B;EAAoC,OAAO;YACzC,iBAAA,GAAA,kBAAA,KAACC,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,63 +1,66 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { ContainerProps } from
|
|
3
|
-
import {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ContainerProps } from "@bento/container";
|
|
3
|
+
import { AriaCheckboxGroupProps, AriaCheckboxProps } from "react-aria";
|
|
4
4
|
|
|
5
|
+
//#region src/checkbox.d.ts
|
|
5
6
|
interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
32
33
|
*/
|
|
33
34
|
declare const Checkbox: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
34
|
-
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/checkbox-group.d.ts
|
|
35
37
|
interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
60
62
|
*/
|
|
61
63
|
declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
62
|
-
|
|
63
|
-
export { Checkbox, CheckboxGroup,
|
|
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,gBAA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;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,16 +1,17 @@
|
|
|
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 &&
|
|
9
|
+
"build": "tsdown",
|
|
10
|
+
"lint": "biome lint && tsgo --noEmit",
|
|
11
11
|
"prepublishOnly": "node ../../../scripts/compile-readme.ts",
|
|
12
12
|
"test": "vitest --run",
|
|
13
|
-
"test:watch": "vitest"
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"typecheck": "tsgo --noEmit -p tsconfig.json"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -40,22 +41,22 @@
|
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@bento/container": "^0.2.1",
|
|
42
43
|
"@bento/icon": "^0.2.0",
|
|
43
|
-
"@bento/input": "^0.1.
|
|
44
|
+
"@bento/input": "^0.1.1",
|
|
44
45
|
"@bento/slots": "^0.3.0",
|
|
45
46
|
"@bento/use-data-attributes": "^0.1.1",
|
|
46
|
-
"@bento/use-props": "^0.2.
|
|
47
|
+
"@bento/use-props": "^0.2.3",
|
|
47
48
|
"@bento/visually-hidden": "^0.1.1",
|
|
48
|
-
"@react-aria/utils": "^3.
|
|
49
|
-
"react-aria": "^3.
|
|
50
|
-
"react-stately": "^3.
|
|
49
|
+
"@react-aria/utils": "^3.34.0",
|
|
50
|
+
"react-aria": "^3.48.0",
|
|
51
|
+
"react-stately": "^3.46.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@types/react": "^19.2.
|
|
54
|
+
"@types/react": "^19.2.15",
|
|
54
55
|
"@types/react-dom": "^19.2.3",
|
|
55
|
-
"
|
|
56
|
-
"typescript": "^
|
|
57
|
-
"vitest": "^4.
|
|
58
|
-
"vitest-browser-react": "^2.
|
|
56
|
+
"tsdown": "^0.22.1",
|
|
57
|
+
"typescript": "^6.0.3",
|
|
58
|
+
"vitest": "^4.1.7",
|
|
59
|
+
"vitest-browser-react": "^2.2.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
62
|
"react": "18.x || 19.x",
|
|
@@ -64,8 +65,8 @@
|
|
|
64
65
|
"exports": {
|
|
65
66
|
".": {
|
|
66
67
|
"import": {
|
|
67
|
-
"types": "./dist/index.d.
|
|
68
|
-
"default": "./dist/index.
|
|
68
|
+
"types": "./dist/index.d.mts",
|
|
69
|
+
"default": "./dist/index.mjs"
|
|
69
70
|
},
|
|
70
71
|
"require": {
|
|
71
72
|
"types": "./dist/index.d.cts",
|
package/dist/index.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ContainerProps } from '@bento/container';
|
|
3
|
-
import { AriaCheckboxProps, AriaCheckboxGroupProps } from 'react-aria';
|
|
4
|
-
|
|
5
|
-
interface CheckboxProps extends AriaCheckboxProps, Omit<ContainerProps, keyof AriaCheckboxProps> {
|
|
6
|
-
/** The value of the checkbox, used when submitting an HTML form. */
|
|
7
|
-
value?: string;
|
|
8
|
-
/** The name of the checkbox. */
|
|
9
|
-
name?: string;
|
|
10
|
-
/** A ref for the HTML input element. */
|
|
11
|
-
inputRef?: React.Ref<HTMLInputElement>;
|
|
12
|
-
/** The label for the checkbox. Accepts any renderable node. */
|
|
13
|
-
children?: React.ReactNode;
|
|
14
|
-
/** Whether the checkbox is required or not. */
|
|
15
|
-
isRequired?: boolean;
|
|
16
|
-
/** Whether the input can be selected but not changed by the user. */
|
|
17
|
-
isReadOnly?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Whether the checkbox is disabled or not. Shows that a selection exists,
|
|
20
|
-
* but is not available in that circumstance.
|
|
21
|
-
*/
|
|
22
|
-
isDisabled?: boolean;
|
|
23
|
-
/** Whether the element should receive focus on render. */
|
|
24
|
-
autoFocus?: boolean;
|
|
25
|
-
/** Whether the checkbox is in an indeterminate state. */
|
|
26
|
-
isIndeterminate?: boolean;
|
|
27
|
-
/** Whether the checkbox is in a selected state. */
|
|
28
|
-
isSelected?: boolean;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The `Checkbox` is a single checkbox option that can be selected by the user.
|
|
32
|
-
*/
|
|
33
|
-
declare const Checkbox: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
34
|
-
|
|
35
|
-
interface CheckboxGroupProps extends AriaCheckboxGroupProps, Omit<ContainerProps, keyof AriaCheckboxGroupProps> {
|
|
36
|
-
/** The current value of the checkbox group (controlled). */
|
|
37
|
-
value?: string[];
|
|
38
|
-
/** The default value of the checkbox group (uncontrolled). */
|
|
39
|
-
defaultValue?: string[];
|
|
40
|
-
/** Whether the input is disabled. */
|
|
41
|
-
isDisabled?: boolean;
|
|
42
|
-
/** Whether the input can be selected but not changed by the user. */
|
|
43
|
-
isReadOnly?: boolean;
|
|
44
|
-
/** Whether user input is required on the input before form submission. */
|
|
45
|
-
isRequired?: boolean;
|
|
46
|
-
/** Whether the input value is invalid. */
|
|
47
|
-
isInvalid?: boolean;
|
|
48
|
-
/** The name of the input element, used when submitting an HTML form. */
|
|
49
|
-
name?: string;
|
|
50
|
-
/**
|
|
51
|
-
* The `<form>` element to associate the input with.
|
|
52
|
-
* The value of this attribute must be the id of a `<form>` in the same document.
|
|
53
|
-
*/
|
|
54
|
-
form?: string;
|
|
55
|
-
/** Checkbox children. */
|
|
56
|
-
children?: React.ReactNode;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* The `CheckboxGroup` allows a user to select items from a list of `Checkbox` components.
|
|
60
|
-
*/
|
|
61
|
-
declare const CheckboxGroup: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
62
|
-
|
|
63
|
-
export { Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps };
|
package/dist/index.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import React, { 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
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
-
|
|
14
|
-
// src/checkbox.tsx
|
|
15
|
-
var CheckboxGroupStateContext = React.createContext(null);
|
|
16
|
-
var Checkbox = withSlots("BentoCheckbox", function Checkbox2(args) {
|
|
17
|
-
const { props, apply } = useProps(args);
|
|
18
|
-
const groupState = useContext(CheckboxGroupStateContext);
|
|
19
|
-
const ref = useRef(null);
|
|
20
|
-
const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));
|
|
21
|
-
const { isFocused, isFocusVisible, focusProps } = useFocusRing();
|
|
22
|
-
const { labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid } = groupState ? useCheckboxGroupItem(
|
|
23
|
-
{
|
|
24
|
-
...props,
|
|
25
|
-
// Value is optional for standalone checkboxes, but required for CheckboxGroup items;
|
|
26
|
-
// it's passed explicitly here to avoid typescript error (requires ignore)(recommendation from React Aria).
|
|
27
|
-
value: props.value
|
|
28
|
-
},
|
|
29
|
-
groupState,
|
|
30
|
-
inputRef
|
|
31
|
-
) : useCheckbox(props, useToggleState(props), inputRef);
|
|
32
|
-
const interactionDisabled = props.isDisabled || isDisabled || isReadOnly;
|
|
33
|
-
const { hoverProps, isHovered } = useHover({
|
|
34
|
-
...props,
|
|
35
|
-
isDisabled: interactionDisabled
|
|
36
|
-
});
|
|
37
|
-
return /* @__PURE__ */ jsxs(
|
|
38
|
-
Container,
|
|
39
|
-
{
|
|
40
|
-
as: "label",
|
|
41
|
-
"aria-checked": props.isIndeterminate ? "mixed" : void 0,
|
|
42
|
-
...apply(mergeProps(labelProps, hoverProps)),
|
|
43
|
-
...useDataAttributes({
|
|
44
|
-
selected: isSelected,
|
|
45
|
-
pressed: isPressed,
|
|
46
|
-
hovered: isHovered,
|
|
47
|
-
focused: isFocused,
|
|
48
|
-
focusVisible: isFocusVisible,
|
|
49
|
-
disabled: interactionDisabled,
|
|
50
|
-
readonly: isReadOnly,
|
|
51
|
-
invalid: isInvalid,
|
|
52
|
-
required: props.isRequired,
|
|
53
|
-
indeterminate: props.isIndeterminate
|
|
54
|
-
}),
|
|
55
|
-
children: [
|
|
56
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Input, { ...mergeProps(inputProps, focusProps), ref: inputRef }) }),
|
|
57
|
-
props.isIndeterminate ? /* @__PURE__ */ jsx(Icon, { slot: "icon-indeterminate", icon: "checkboxIndeterminate", children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("rect", { x: "6", y: "11", width: "12", height: "2", fill: "currentColor" }) }) }) : isSelected ? /* @__PURE__ */ jsx(Icon, { slot: "icon-checked", icon: "checkboxChecked", children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M9,16.2L4.8,12l-1.4,1.4L9,19L21,7l-1.4-1.4L9,16.2z", fill: "currentColor" }) }) }) : /* @__PURE__ */ jsx(Icon, { slot: "icon-unchecked", icon: "checkboxUnchecked", children: /* @__PURE__ */ jsx("svg", { width: 24, height: 24, children: /* @__PURE__ */ jsx("rect", { x: 4, y: 4, width: 16, height: 16, rx: 3, fill: "none", stroke: "gray", strokeWidth: 2 }) }) }),
|
|
58
|
-
props.children
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
var CheckboxGroup = withSlots("BentoCheckboxGroup", function CheckboxGroup2(args) {
|
|
64
|
-
const { props, apply } = useProps(args);
|
|
65
|
-
const state = useCheckboxGroupState(props);
|
|
66
|
-
const { groupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useCheckboxGroup(
|
|
67
|
-
{ ...props, label: props.label ?? "Checkbox Group", description: props.description ?? "Description" },
|
|
68
|
-
state
|
|
69
|
-
);
|
|
70
|
-
return /* @__PURE__ */ jsx(CheckboxGroupStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx(
|
|
71
|
-
Container,
|
|
72
|
-
{
|
|
73
|
-
...apply(groupProps),
|
|
74
|
-
...useDataAttributes({
|
|
75
|
-
orientation: props.orientation || "vertical",
|
|
76
|
-
invalid: state.isInvalid,
|
|
77
|
-
disabled: state.isDisabled,
|
|
78
|
-
readonly: state.isReadOnly,
|
|
79
|
-
required: state.isRequired
|
|
80
|
-
}),
|
|
81
|
-
slots: {
|
|
82
|
-
label: labelProps,
|
|
83
|
-
description: descriptionProps,
|
|
84
|
-
error: mergeProps$1(errorMessageProps, validationResult)
|
|
85
|
-
},
|
|
86
|
-
children: props.children
|
|
87
|
-
}
|
|
88
|
-
) });
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export { Checkbox, CheckboxGroup };
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
|
93
|
-
//# 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":["Checkbox","withSlots","CheckboxGroup","useProps","jsx","Container","useDataAttributes","mergeProps"],"mappings":";;;;;;;;;;;;;;AAGO,IAAM,yBAAA,GAA4B,KAAA,CAAM,aAAA,CAAyC,IAAI,CAAA;ACgDrF,IAAM,QAAA,GAAW,SAAA,CAAU,eAAA,EAAiB,SAASA,UAAS,IAAA,EAAqB;AACxF,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAI,SAAS,IAAI,CAAA;AACtC,EAAA,MAAM,UAAA,GAAa,WAAW,yBAAyB,CAAA;AACvD,EAAA,MAAM,GAAA,GAAM,OAAyB,IAAI,CAAA;AACzC,EAAA,MAAM,QAAA,GAAW,YAAA,CAAa,OAAA,CAAQ,MAAM,UAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAe,YAAA,EAAa;AAE/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAW,UAAA,EAAY,UAAA,EAAY,SAAA,EAAU,GAAI,UAAA,GACzF,oBAAA;AAAA,IACE;AAAA,MACE,GAAG,KAAA;AAAA;AAAA;AAAA,MAGH,OAAQ,KAAA,CAAgD;AAAA,KAC1D;AAAA,IACA,UAAA;AAAA,IACA;AAAA,MAEF,WAAA,CAAY,KAAA,EAAO,cAAA,CAAe,KAAK,GAAG,QAAQ,CAAA;AAEtD,EAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,IAAc,UAAA,IA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ACEC,GAAAA,CAAC,yBAAA,CAA0B,UAA1B,EAAmC,KAAA,EAAO,OACzC,QAAA,kBAAAA,GAAAA;AAAA,IAACC,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,OACvD;AAAA,MAEC,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,GACT,EACF,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"]}
|