@codefast/ui 0.3.9 → 0.3.10
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/CHANGELOG.md +11 -0
- package/dist/components/accordion.cjs +97 -1
- package/dist/components/accordion.d.ts +4 -4
- package/dist/components/accordion.js +51 -1
- package/dist/components/alert-dialog.cjs +155 -1
- package/dist/components/alert-dialog.d.ts +11 -11
- package/dist/components/alert-dialog.js +94 -1
- package/dist/components/alert.cjs +84 -1
- package/dist/components/alert.d.ts +5 -5
- package/dist/components/alert.js +41 -1
- package/dist/components/aspect-ratio.cjs +43 -1
- package/dist/components/aspect-ratio.d.ts +2 -2
- package/dist/components/aspect-ratio.js +9 -1
- package/dist/components/avatar.cjs +65 -1
- package/dist/components/avatar.d.ts +2 -2
- package/dist/components/avatar.js +25 -1
- package/dist/components/badge.cjs +66 -1
- package/dist/components/badge.d.ts +3 -3
- package/dist/components/badge.js +29 -1
- package/dist/components/breadcrumb.cjs +126 -1
- package/dist/components/breadcrumb.d.ts +8 -8
- package/dist/components/breadcrumb.js +74 -1
- package/dist/components/button-group.cjs +86 -1
- package/dist/components/button-group.d.ts +5 -5
- package/dist/components/button-group.js +43 -1
- package/dist/components/button.cjs +92 -1
- package/dist/components/button.d.ts +6 -6
- package/dist/components/button.js +55 -1
- package/dist/components/calendar.cjs +150 -1
- package/dist/components/calendar.d.ts +12 -19
- package/dist/components/calendar.js +113 -1
- package/dist/components/card.cjs +105 -1
- package/dist/components/card.d.ts +8 -8
- package/dist/components/card.js +53 -1
- package/dist/components/carousel.cjs +210 -1
- package/dist/components/carousel.d.ts +10 -10
- package/dist/components/carousel.js +151 -1
- package/dist/components/chart.cjs +250 -3
- package/dist/components/chart.d.ts +9 -9
- package/dist/components/chart.js +198 -3
- package/dist/components/checkbox-cards.cjs +69 -1
- package/dist/components/checkbox-cards.d.ts +2 -2
- package/dist/components/checkbox-cards.js +32 -1
- package/dist/components/checkbox-group.cjs +63 -1
- package/dist/components/checkbox-group.d.ts +2 -2
- package/dist/components/checkbox-group.js +26 -1
- package/dist/components/checkbox.cjs +53 -1
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/checkbox.js +19 -1
- package/dist/components/collapsible.cjs +61 -1
- package/dist/components/collapsible.d.ts +2 -2
- package/dist/components/collapsible.js +21 -1
- package/dist/components/command.cjs +167 -1
- package/dist/components/command.d.ts +4 -4
- package/dist/components/command.js +106 -1
- package/dist/components/context-menu.cjs +218 -1
- package/dist/components/context-menu.d.ts +4 -4
- package/dist/components/context-menu.js +142 -1
- package/dist/components/dialog.cjs +164 -1
- package/dist/components/dialog.d.ts +10 -10
- package/dist/components/dialog.js +106 -1
- package/dist/components/drawer.cjs +143 -1
- package/dist/components/drawer.d.ts +9 -9
- package/dist/components/drawer.js +85 -1
- package/dist/components/dropdown-menu.cjs +221 -1
- package/dist/components/dropdown-menu.d.ts +4 -4
- package/dist/components/dropdown-menu.js +145 -1
- package/dist/components/empty.cjs +113 -1
- package/dist/components/empty.d.ts +9 -9
- package/dist/components/empty.js +61 -1
- package/dist/components/field.cjs +193 -1
- package/dist/components/field.d.ts +14 -14
- package/dist/components/field.js +129 -1
- package/dist/components/form.cjs +151 -1
- package/dist/components/form.d.ts +10 -10
- package/dist/components/form.js +96 -1
- package/dist/components/hover-card.cjs +77 -1
- package/dist/components/hover-card.d.ts +2 -2
- package/dist/components/hover-card.js +34 -1
- package/dist/components/input-group.cjs +155 -1
- package/dist/components/input-group.d.ts +15 -15
- package/dist/components/input-group.js +97 -1
- package/dist/components/input-number.cjs +98 -1
- package/dist/components/input-number.d.ts +2 -2
- package/dist/components/input-number.js +64 -1
- package/dist/components/input-otp.cjs +101 -1
- package/dist/components/input-otp.d.ts +6 -6
- package/dist/components/input-otp.js +49 -1
- package/dist/components/input-password.cjs +71 -1
- package/dist/components/input-password.d.ts +3 -3
- package/dist/components/input-password.js +37 -1
- package/dist/components/input-search.cjs +80 -1
- package/dist/components/input-search.d.ts +3 -3
- package/dist/components/input-search.js +46 -1
- package/dist/components/input.cjs +45 -1
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +11 -1
- package/dist/components/item.cjs +186 -1
- package/dist/components/item.d.ts +12 -12
- package/dist/components/item.js +119 -1
- package/dist/components/kbd.cjs +54 -1
- package/dist/components/kbd.d.ts +3 -3
- package/dist/components/kbd.js +17 -1
- package/dist/components/label.cjs +45 -1
- package/dist/components/label.d.ts +2 -2
- package/dist/components/label.js +11 -1
- package/dist/components/menubar.cjs +232 -1
- package/dist/components/menubar.d.ts +4 -4
- package/dist/components/menubar.js +153 -1
- package/dist/components/native-select.cjs +75 -1
- package/dist/components/native-select.d.ts +4 -4
- package/dist/components/native-select.js +35 -1
- package/dist/components/navigation-menu.cjs +146 -2
- package/dist/components/navigation-menu.d.ts +2 -2
- package/dist/components/navigation-menu.js +94 -2
- package/dist/components/pagination.cjs +138 -1
- package/dist/components/pagination.d.ts +10 -10
- package/dist/components/pagination.js +86 -1
- package/dist/components/popover.cjs +86 -1
- package/dist/components/popover.d.ts +3 -3
- package/dist/components/popover.js +40 -1
- package/dist/components/progress-circle.cjs +184 -1
- package/dist/components/progress-circle.d.ts +5 -5
- package/dist/components/progress-circle.js +147 -1
- package/dist/components/progress.cjs +52 -1
- package/dist/components/progress.d.ts +2 -2
- package/dist/components/progress.js +18 -1
- package/dist/components/radio-cards.cjs +66 -1
- package/dist/components/radio-cards.d.ts +2 -2
- package/dist/components/radio-cards.js +29 -1
- package/dist/components/radio-group.cjs +59 -1
- package/dist/components/radio-group.d.ts +2 -2
- package/dist/components/radio-group.js +22 -1
- package/dist/components/radio.cjs +47 -1
- package/dist/components/radio.d.ts +2 -2
- package/dist/components/radio.js +13 -1
- package/dist/components/resizable.cjs +71 -1
- package/dist/components/resizable.d.ts +8 -8
- package/dist/components/resizable.js +31 -1
- package/dist/components/scroll-area.cjs +140 -1
- package/dist/components/scroll-area.d.ts +5 -5
- package/dist/components/scroll-area.js +100 -1
- package/dist/components/select.cjs +180 -1
- package/dist/components/select.d.ts +5 -5
- package/dist/components/select.js +119 -1
- package/dist/components/separator.cjs +82 -1
- package/dist/components/separator.d.ts +5 -5
- package/dist/components/separator.js +42 -1
- package/dist/components/sheet.cjs +184 -1
- package/dist/components/sheet.d.ts +9 -9
- package/dist/components/sheet.js +123 -1
- package/dist/components/sidebar.cjs +506 -1
- package/dist/components/sidebar.d.ts +31 -31
- package/dist/components/sidebar.js +400 -1
- package/dist/components/skeleton.cjs +44 -1
- package/dist/components/skeleton.d.ts +2 -2
- package/dist/components/skeleton.js +10 -1
- package/dist/components/slider.cjs +79 -1
- package/dist/components/slider.d.ts +2 -2
- package/dist/components/slider.js +45 -1
- package/dist/components/sonner.cjs +57 -1
- package/dist/components/sonner.d.ts +3 -3
- package/dist/components/sonner.js +17 -1
- package/dist/components/spinner.cjs +75 -1
- package/dist/components/spinner.d.ts +2 -2
- package/dist/components/spinner.js +41 -1
- package/dist/components/switch.cjs +49 -1
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +15 -1
- package/dist/components/table.cjs +118 -1
- package/dist/components/table.d.ts +9 -9
- package/dist/components/table.js +63 -1
- package/dist/components/tabs.cjs +75 -1
- package/dist/components/tabs.d.ts +3 -3
- package/dist/components/tabs.js +32 -1
- package/dist/components/textarea.cjs +44 -1
- package/dist/components/textarea.d.ts +2 -2
- package/dist/components/textarea.js +10 -1
- package/dist/components/toggle-group.cjs +90 -1
- package/dist/components/toggle-group.d.ts +10 -12
- package/dist/components/toggle-group.js +53 -1
- package/dist/components/toggle.cjs +71 -1
- package/dist/components/toggle.d.ts +10 -12
- package/dist/components/toggle.js +34 -1
- package/dist/components/tooltip.cjs +90 -1
- package/dist/components/tooltip.d.ts +3 -3
- package/dist/components/tooltip.js +44 -1
- package/dist/css/amber.css +95 -1
- package/dist/css/blue.css +95 -1
- package/dist/css/cyan.css +95 -1
- package/dist/css/emerald.css +95 -1
- package/dist/css/fuchsia.css +95 -1
- package/dist/css/gray.css +95 -1
- package/dist/css/green.css +95 -1
- package/dist/css/indigo.css +95 -1
- package/dist/css/lime.css +95 -1
- package/dist/css/neutral.css +95 -1
- package/dist/css/orange.css +95 -1
- package/dist/css/pink.css +95 -1
- package/dist/css/preset.css +118 -1
- package/dist/css/purple.css +95 -1
- package/dist/css/red.css +95 -1
- package/dist/css/rose.css +95 -1
- package/dist/css/sky.css +95 -1
- package/dist/css/slate.css +95 -1
- package/dist/css/stone.css +95 -1
- package/dist/css/style.css +3 -1
- package/dist/css/teal.css +95 -1
- package/dist/css/violet.css +95 -1
- package/dist/css/yellow.css +95 -1
- package/dist/css/zinc.css +95 -1
- package/dist/hooks/use-animated-value.cjs +74 -1
- package/dist/hooks/use-animated-value.d.ts +9 -10
- package/dist/hooks/use-animated-value.js +40 -1
- package/dist/hooks/use-copy-to-clipboard.cjs +57 -1
- package/dist/hooks/use-copy-to-clipboard.d.ts +18 -1
- package/dist/hooks/use-copy-to-clipboard.js +23 -1
- package/dist/hooks/use-is-mobile.cjs +39 -1
- package/dist/hooks/use-is-mobile.d.ts +15 -6
- package/dist/hooks/use-is-mobile.js +5 -1
- package/dist/hooks/use-media-query.cjs +56 -1
- package/dist/hooks/use-media-query.d.ts +11 -3
- package/dist/hooks/use-media-query.js +22 -1
- package/dist/hooks/use-mutation-observer.cjs +56 -1
- package/dist/hooks/use-mutation-observer.d.ts +8 -12
- package/dist/hooks/use-mutation-observer.js +22 -1
- package/dist/hooks/use-pagination.cjs +92 -1
- package/dist/hooks/use-pagination.d.ts +12 -10
- package/dist/hooks/use-pagination.js +55 -1
- package/dist/index.cjs +1081 -1
- package/dist/index.d.ts +130 -131
- package/dist/index.js +69 -1
- package/dist/primitives/checkbox-group.cjs +151 -1
- package/dist/primitives/checkbox-group.d.ts +11 -11
- package/dist/primitives/checkbox-group.js +99 -1
- package/dist/primitives/input-number.cjs +439 -1
- package/dist/primitives/input-number.d.ts +8 -8
- package/dist/primitives/input-number.js +381 -1
- package/dist/primitives/input.cjs +99 -1
- package/dist/primitives/input.d.ts +4 -4
- package/dist/primitives/input.js +53 -1
- package/dist/primitives/progress-circle.cjs +198 -1
- package/dist/primitives/progress-circle.d.ts +7 -7
- package/dist/primitives/progress-circle.js +128 -1
- package/package.json +385 -38
|
@@ -1 +1,151 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createCheckboxGroupScope: ()=>createCheckboxGroupScope,
|
|
28
|
+
CheckboxGroup: ()=>CheckboxGroup,
|
|
29
|
+
CheckboxGroupItem: ()=>CheckboxGroupItem,
|
|
30
|
+
CheckboxGroupIndicator: ()=>CheckboxGroupIndicator,
|
|
31
|
+
Indicator: ()=>CheckboxGroupIndicator,
|
|
32
|
+
Item: ()=>CheckboxGroupItem,
|
|
33
|
+
Root: ()=>CheckboxGroup
|
|
34
|
+
});
|
|
35
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
36
|
+
const react_checkbox_namespaceObject = require("@radix-ui/react-checkbox");
|
|
37
|
+
const react_context_namespaceObject = require("@radix-ui/react-context");
|
|
38
|
+
const react_direction_namespaceObject = require("@radix-ui/react-direction");
|
|
39
|
+
const react_roving_focus_namespaceObject = require("@radix-ui/react-roving-focus");
|
|
40
|
+
const react_use_controllable_state_namespaceObject = require("@radix-ui/react-use-controllable-state");
|
|
41
|
+
const external_react_namespaceObject = require("react");
|
|
42
|
+
const CHECKBOX_GROUP_NAME = 'CheckboxGroup';
|
|
43
|
+
const [createCheckboxGroupContext, createCheckboxGroupScope] = (0, react_context_namespaceObject.createContextScope)(CHECKBOX_GROUP_NAME, [
|
|
44
|
+
react_roving_focus_namespaceObject.createRovingFocusGroupScope,
|
|
45
|
+
react_checkbox_namespaceObject.createCheckboxScope
|
|
46
|
+
]);
|
|
47
|
+
const useRovingFocusGroupScope = (0, react_roving_focus_namespaceObject.createRovingFocusGroupScope)();
|
|
48
|
+
const useCheckboxScope = (0, react_checkbox_namespaceObject.createCheckboxScope)();
|
|
49
|
+
const [CheckboxGroupContextProvider, useCheckboxGroupContext] = createCheckboxGroupContext(CHECKBOX_GROUP_NAME);
|
|
50
|
+
function CheckboxGroup({ __scopeCheckboxGroup, defaultValue, dir, disabled = false, loop = true, name, onValueChange, orientation, required = false, value: valueProperty, ...props }) {
|
|
51
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
|
|
52
|
+
const direction = (0, react_direction_namespaceObject.useDirection)(dir);
|
|
53
|
+
const [value = [], setValue] = (0, react_use_controllable_state_namespaceObject.useControllableState)({
|
|
54
|
+
defaultProp: defaultValue,
|
|
55
|
+
onChange: onValueChange,
|
|
56
|
+
prop: valueProperty
|
|
57
|
+
});
|
|
58
|
+
const handleItemCheck = (0, external_react_namespaceObject.useCallback)((itemValue)=>{
|
|
59
|
+
setValue((previousValue)=>[
|
|
60
|
+
...previousValue ?? [],
|
|
61
|
+
itemValue
|
|
62
|
+
]);
|
|
63
|
+
}, [
|
|
64
|
+
setValue
|
|
65
|
+
]);
|
|
66
|
+
const handleItemUncheck = (0, external_react_namespaceObject.useCallback)((itemValue)=>{
|
|
67
|
+
setValue((previousValue)=>{
|
|
68
|
+
const currentValue = previousValue ?? [];
|
|
69
|
+
if (required && 1 === currentValue.length && currentValue[0] === itemValue) return currentValue;
|
|
70
|
+
return currentValue.filter((inputValue)=>inputValue !== itemValue);
|
|
71
|
+
});
|
|
72
|
+
}, [
|
|
73
|
+
setValue,
|
|
74
|
+
required
|
|
75
|
+
]);
|
|
76
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(CheckboxGroupContextProvider, {
|
|
77
|
+
disabled: disabled,
|
|
78
|
+
name: name,
|
|
79
|
+
required: required,
|
|
80
|
+
scope: __scopeCheckboxGroup,
|
|
81
|
+
value: value,
|
|
82
|
+
onItemCheck: handleItemCheck,
|
|
83
|
+
onItemUncheck: handleItemUncheck,
|
|
84
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_roving_focus_namespaceObject.Root, {
|
|
85
|
+
asChild: true,
|
|
86
|
+
...rovingFocusGroupScope,
|
|
87
|
+
dir: direction,
|
|
88
|
+
loop: loop,
|
|
89
|
+
orientation: orientation,
|
|
90
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
91
|
+
"data-disabled": disabled ? '' : void 0,
|
|
92
|
+
dir: direction,
|
|
93
|
+
role: "group",
|
|
94
|
+
...props
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const ITEM_NAME = 'CheckboxGroupItem';
|
|
100
|
+
function CheckboxGroupItem({ __scopeCheckboxGroup, disabled, ...props }) {
|
|
101
|
+
const context = useCheckboxGroupContext(ITEM_NAME, __scopeCheckboxGroup);
|
|
102
|
+
const isDisabled = context.disabled || disabled;
|
|
103
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
|
|
104
|
+
const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
|
|
105
|
+
const checked = context.value?.includes(props.value);
|
|
106
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_roving_focus_namespaceObject.Item, {
|
|
107
|
+
asChild: true,
|
|
108
|
+
...rovingFocusGroupScope,
|
|
109
|
+
active: checked,
|
|
110
|
+
focusable: !isDisabled,
|
|
111
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_checkbox_namespaceObject.Root, {
|
|
112
|
+
"aria-label": props.value,
|
|
113
|
+
checked: checked,
|
|
114
|
+
disabled: isDisabled,
|
|
115
|
+
name: context.name,
|
|
116
|
+
required: context.required,
|
|
117
|
+
...checkboxScope,
|
|
118
|
+
...props,
|
|
119
|
+
onCheckedChange: (checkedState)=>{
|
|
120
|
+
if (checkedState) context.onItemCheck(props.value);
|
|
121
|
+
else context.onItemUncheck(props.value);
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function CheckboxGroupIndicator({ __scopeCheckboxGroup, ...props }) {
|
|
127
|
+
const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
|
|
128
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_checkbox_namespaceObject.Indicator, {
|
|
129
|
+
...checkboxScope,
|
|
130
|
+
...props
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
exports.CheckboxGroup = __webpack_exports__.CheckboxGroup;
|
|
134
|
+
exports.CheckboxGroupIndicator = __webpack_exports__.CheckboxGroupIndicator;
|
|
135
|
+
exports.CheckboxGroupItem = __webpack_exports__.CheckboxGroupItem;
|
|
136
|
+
exports.Indicator = __webpack_exports__.Indicator;
|
|
137
|
+
exports.Item = __webpack_exports__.Item;
|
|
138
|
+
exports.Root = __webpack_exports__.Root;
|
|
139
|
+
exports.createCheckboxGroupScope = __webpack_exports__.createCheckboxGroupScope;
|
|
140
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
141
|
+
"CheckboxGroup",
|
|
142
|
+
"CheckboxGroupIndicator",
|
|
143
|
+
"CheckboxGroupItem",
|
|
144
|
+
"Indicator",
|
|
145
|
+
"Item",
|
|
146
|
+
"Root",
|
|
147
|
+
"createCheckboxGroupScope"
|
|
148
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
149
|
+
Object.defineProperty(exports, '__esModule', {
|
|
150
|
+
value: true
|
|
151
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import * as CheckboxPrimitive from
|
|
4
|
-
import * as RovingFocusGroup from
|
|
1
|
+
import type { Scope } from '@radix-ui/react-context';
|
|
2
|
+
import type { ComponentProps, JSX } from 'react';
|
|
3
|
+
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
4
|
+
import * as RovingFocusGroup from '@radix-ui/react-roving-focus';
|
|
5
5
|
/**
|
|
6
6
|
* Type for components that can be scoped within the CheckboxGroup context
|
|
7
7
|
*/
|
|
@@ -54,7 +54,7 @@ interface CheckboxGroupBaseProps {
|
|
|
54
54
|
/**
|
|
55
55
|
* Direction for roving focus navigation
|
|
56
56
|
*/
|
|
57
|
-
dir?: RovingFocusGroup.RovingFocusGroupProps[
|
|
57
|
+
dir?: RovingFocusGroup.RovingFocusGroupProps['dir'];
|
|
58
58
|
/**
|
|
59
59
|
* Whether the entire checkbox group is disabled
|
|
60
60
|
*/
|
|
@@ -62,11 +62,11 @@ interface CheckboxGroupBaseProps {
|
|
|
62
62
|
/**
|
|
63
63
|
* Whether focus should loop to the start/end when reaching the boundaries
|
|
64
64
|
*/
|
|
65
|
-
loop?: RovingFocusGroup.RovingFocusGroupProps[
|
|
65
|
+
loop?: RovingFocusGroup.RovingFocusGroupProps['loop'];
|
|
66
66
|
/**
|
|
67
67
|
* Name attribute for the checkbox group form field
|
|
68
68
|
*/
|
|
69
|
-
name?: CheckboxGroupContextValue[
|
|
69
|
+
name?: CheckboxGroupContextValue['name'];
|
|
70
70
|
/**
|
|
71
71
|
* Callback fired when the selected values change
|
|
72
72
|
* @param value - The new array of selected values
|
|
@@ -75,7 +75,7 @@ interface CheckboxGroupBaseProps {
|
|
|
75
75
|
/**
|
|
76
76
|
* Orientation of the checkbox group (horizontal or vertical)
|
|
77
77
|
*/
|
|
78
|
-
orientation?: RovingFocusGroup.RovingFocusGroupProps[
|
|
78
|
+
orientation?: RovingFocusGroup.RovingFocusGroupProps['orientation'];
|
|
79
79
|
/**
|
|
80
80
|
* Whether at least one checkbox must be selected
|
|
81
81
|
*/
|
|
@@ -83,12 +83,12 @@ interface CheckboxGroupBaseProps {
|
|
|
83
83
|
/**
|
|
84
84
|
* Controlled values for the checkbox group
|
|
85
85
|
*/
|
|
86
|
-
value?: CheckboxGroupContextValue[
|
|
86
|
+
value?: CheckboxGroupContextValue['value'];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Props for the CheckboxGroup component
|
|
90
90
|
*/
|
|
91
|
-
type CheckboxGroupProps = CheckboxGroupBaseProps & ComponentProps<
|
|
91
|
+
type CheckboxGroupProps = CheckboxGroupBaseProps & ComponentProps<'div'>;
|
|
92
92
|
/**
|
|
93
93
|
* CheckboxGroup component that manages a group of checkboxes with roving focus
|
|
94
94
|
*/
|
|
@@ -96,7 +96,7 @@ declare function CheckboxGroup({ __scopeCheckboxGroup, defaultValue, dir, disabl
|
|
|
96
96
|
/**
|
|
97
97
|
* Props for the CheckboxGroupItem component
|
|
98
98
|
*/
|
|
99
|
-
interface CheckboxGroupItemProps extends Omit<ComponentProps<typeof CheckboxPrimitive.Root>,
|
|
99
|
+
interface CheckboxGroupItemProps extends Omit<ComponentProps<typeof CheckboxPrimitive.Root>, 'checked' | 'defaultChecked' | 'name' | 'onCheckedChange'> {
|
|
100
100
|
/**
|
|
101
101
|
* Value of the checkbox item, used to identify the item within the group
|
|
102
102
|
*/
|
|
@@ -1 +1,99 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Indicator, Root, createCheckboxScope } from "@radix-ui/react-checkbox";
|
|
3
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
4
|
+
import { useDirection } from "@radix-ui/react-direction";
|
|
5
|
+
import { Item, Root as react_roving_focus_Root, createRovingFocusGroupScope } from "@radix-ui/react-roving-focus";
|
|
6
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
7
|
+
import { useCallback } from "react";
|
|
8
|
+
const CHECKBOX_GROUP_NAME = 'CheckboxGroup';
|
|
9
|
+
const [createCheckboxGroupContext, createCheckboxGroupScope] = createContextScope(CHECKBOX_GROUP_NAME, [
|
|
10
|
+
createRovingFocusGroupScope,
|
|
11
|
+
createCheckboxScope
|
|
12
|
+
]);
|
|
13
|
+
const useRovingFocusGroupScope = createRovingFocusGroupScope();
|
|
14
|
+
const useCheckboxScope = createCheckboxScope();
|
|
15
|
+
const [CheckboxGroupContextProvider, useCheckboxGroupContext] = createCheckboxGroupContext(CHECKBOX_GROUP_NAME);
|
|
16
|
+
function CheckboxGroup({ __scopeCheckboxGroup, defaultValue, dir, disabled = false, loop = true, name, onValueChange, orientation, required = false, value: valueProperty, ...props }) {
|
|
17
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
|
|
18
|
+
const direction = useDirection(dir);
|
|
19
|
+
const [value = [], setValue] = useControllableState({
|
|
20
|
+
defaultProp: defaultValue,
|
|
21
|
+
onChange: onValueChange,
|
|
22
|
+
prop: valueProperty
|
|
23
|
+
});
|
|
24
|
+
const handleItemCheck = useCallback((itemValue)=>{
|
|
25
|
+
setValue((previousValue)=>[
|
|
26
|
+
...previousValue ?? [],
|
|
27
|
+
itemValue
|
|
28
|
+
]);
|
|
29
|
+
}, [
|
|
30
|
+
setValue
|
|
31
|
+
]);
|
|
32
|
+
const handleItemUncheck = useCallback((itemValue)=>{
|
|
33
|
+
setValue((previousValue)=>{
|
|
34
|
+
const currentValue = previousValue ?? [];
|
|
35
|
+
if (required && 1 === currentValue.length && currentValue[0] === itemValue) return currentValue;
|
|
36
|
+
return currentValue.filter((inputValue)=>inputValue !== itemValue);
|
|
37
|
+
});
|
|
38
|
+
}, [
|
|
39
|
+
setValue,
|
|
40
|
+
required
|
|
41
|
+
]);
|
|
42
|
+
return /*#__PURE__*/ jsx(CheckboxGroupContextProvider, {
|
|
43
|
+
disabled: disabled,
|
|
44
|
+
name: name,
|
|
45
|
+
required: required,
|
|
46
|
+
scope: __scopeCheckboxGroup,
|
|
47
|
+
value: value,
|
|
48
|
+
onItemCheck: handleItemCheck,
|
|
49
|
+
onItemUncheck: handleItemUncheck,
|
|
50
|
+
children: /*#__PURE__*/ jsx(react_roving_focus_Root, {
|
|
51
|
+
asChild: true,
|
|
52
|
+
...rovingFocusGroupScope,
|
|
53
|
+
dir: direction,
|
|
54
|
+
loop: loop,
|
|
55
|
+
orientation: orientation,
|
|
56
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
57
|
+
"data-disabled": disabled ? '' : void 0,
|
|
58
|
+
dir: direction,
|
|
59
|
+
role: "group",
|
|
60
|
+
...props
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const ITEM_NAME = 'CheckboxGroupItem';
|
|
66
|
+
function CheckboxGroupItem({ __scopeCheckboxGroup, disabled, ...props }) {
|
|
67
|
+
const context = useCheckboxGroupContext(ITEM_NAME, __scopeCheckboxGroup);
|
|
68
|
+
const isDisabled = context.disabled || disabled;
|
|
69
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
|
|
70
|
+
const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
|
|
71
|
+
const checked = context.value?.includes(props.value);
|
|
72
|
+
return /*#__PURE__*/ jsx(Item, {
|
|
73
|
+
asChild: true,
|
|
74
|
+
...rovingFocusGroupScope,
|
|
75
|
+
active: checked,
|
|
76
|
+
focusable: !isDisabled,
|
|
77
|
+
children: /*#__PURE__*/ jsx(Root, {
|
|
78
|
+
"aria-label": props.value,
|
|
79
|
+
checked: checked,
|
|
80
|
+
disabled: isDisabled,
|
|
81
|
+
name: context.name,
|
|
82
|
+
required: context.required,
|
|
83
|
+
...checkboxScope,
|
|
84
|
+
...props,
|
|
85
|
+
onCheckedChange: (checkedState)=>{
|
|
86
|
+
if (checkedState) context.onItemCheck(props.value);
|
|
87
|
+
else context.onItemUncheck(props.value);
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function CheckboxGroupIndicator({ __scopeCheckboxGroup, ...props }) {
|
|
93
|
+
const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
|
|
94
|
+
return /*#__PURE__*/ jsx(Indicator, {
|
|
95
|
+
...checkboxScope,
|
|
96
|
+
...props
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export { CheckboxGroup, CheckboxGroupIndicator, CheckboxGroupItem, CheckboxGroupIndicator as Indicator, CheckboxGroupItem as Item, CheckboxGroup as Root, createCheckboxGroupScope };
|