@codefast/ui 0.3.16-canary.1 → 0.3.16-canary.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/CHANGELOG.md +30 -0
- package/README.md +1 -1
- package/dist/components/accordion.mjs +2 -2
- package/dist/components/alert-dialog.d.mts +1 -1
- package/dist/components/alert-dialog.mjs +4 -4
- package/dist/components/alert.d.mts +3 -13
- package/dist/components/alert.mjs +3 -23
- package/dist/components/badge.d.mts +3 -15
- package/dist/components/badge.mjs +2 -44
- package/dist/components/breadcrumb.mjs +1 -1
- package/dist/components/button-group.d.mts +3 -13
- package/dist/components/button-group.mjs +3 -24
- package/dist/components/button.d.mts +3 -25
- package/dist/components/button.mjs +2 -72
- package/dist/components/calendar.mjs +2 -1
- package/dist/components/carousel.d.mts +1 -2
- package/dist/components/chart.d.mts +2 -4
- package/dist/components/checkbox.mjs +2 -2
- package/dist/components/context-menu.mjs +2 -2
- package/dist/components/dialog.d.mts +1 -1
- package/dist/components/dialog.mjs +4 -4
- package/dist/components/drawer.d.mts +1 -1
- package/dist/components/drawer.mjs +2 -2
- package/dist/components/dropdown-menu.mjs +2 -2
- package/dist/components/empty.d.mts +3 -13
- package/dist/components/empty.mjs +3 -18
- package/dist/components/field.d.mts +3 -14
- package/dist/components/field.mjs +3 -32
- package/dist/components/form.d.mts +2 -4
- package/dist/components/hover-card.mjs +1 -1
- package/dist/components/input-group.d.mts +4 -31
- package/dist/components/input-group.mjs +3 -90
- package/dist/components/input-number.mjs +4 -4
- package/dist/components/input-otp.mjs +2 -2
- package/dist/components/input.mjs +1 -1
- package/dist/components/item.d.mts +4 -29
- package/dist/components/item.mjs +3 -56
- package/dist/components/menubar.mjs +2 -2
- package/dist/components/native-select.mjs +1 -1
- package/dist/components/navigation-menu.d.mts +1 -6
- package/dist/components/navigation-menu.mjs +8 -15
- package/dist/components/pagination.d.mts +1 -1
- package/dist/components/pagination.mjs +1 -1
- package/dist/components/popover.mjs +1 -1
- package/dist/components/progress-circle.d.mts +3 -47
- package/dist/components/progress-circle.mjs +2 -47
- package/dist/components/progress.mjs +1 -1
- package/dist/components/radio-group.mjs +1 -1
- package/dist/components/radio.mjs +1 -1
- package/dist/components/scroll-area.d.mts +3 -19
- package/dist/components/scroll-area.mjs +4 -61
- package/dist/components/select.d.mts +1 -1
- package/dist/components/select.mjs +3 -3
- package/dist/components/separator.d.mts +3 -18
- package/dist/components/separator.mjs +3 -23
- package/dist/components/sheet.d.mts +6 -18
- package/dist/components/sheet.mjs +6 -49
- package/dist/components/sidebar.d.mts +4 -19
- package/dist/components/sidebar.mjs +10 -46
- package/dist/components/skeleton.mjs +1 -1
- package/dist/components/slider.mjs +1 -1
- package/dist/components/spinner.mjs +1 -1
- package/dist/components/switch.mjs +2 -2
- package/dist/components/table.mjs +1 -1
- package/dist/components/tabs.mjs +1 -1
- package/dist/components/textarea.mjs +1 -1
- package/dist/components/toggle-group.d.mts +3 -2
- package/dist/components/toggle-group.mjs +1 -1
- package/dist/components/toggle.d.mts +2 -21
- package/dist/components/toggle.mjs +2 -39
- package/dist/components/tooltip.mjs +1 -1
- package/dist/index.d.mts +31 -16
- package/dist/index.mjs +30 -15
- package/dist/lib/utils.d.mts +1 -12
- package/dist/lib/utils.mjs +1 -9
- package/dist/primitives/checkbox-group.d.mts +1 -2
- package/dist/primitives/input-number.d.mts +1 -2
- package/dist/primitives/input.d.mts +1 -2
- package/dist/primitives/progress-circle.d.mts +1 -2
- package/dist/variants/alert.d.mts +18 -0
- package/dist/variants/alert.mjs +25 -0
- package/dist/variants/badge.d.mts +20 -0
- package/dist/variants/badge.mjs +46 -0
- package/dist/variants/button-group.d.mts +18 -0
- package/dist/variants/button-group.mjs +26 -0
- package/dist/variants/button.d.mts +30 -0
- package/dist/variants/button.mjs +76 -0
- package/dist/variants/empty.d.mts +18 -0
- package/dist/variants/empty.mjs +20 -0
- package/dist/variants/field.d.mts +19 -0
- package/dist/variants/field.mjs +34 -0
- package/dist/variants/input-group.d.mts +43 -0
- package/dist/variants/input-group.mjs +93 -0
- package/dist/variants/item.d.mts +37 -0
- package/dist/variants/item.mjs +60 -0
- package/dist/variants/navigation-menu.d.mts +13 -0
- package/dist/variants/navigation-menu.mjs +12 -0
- package/dist/variants/progress-circle.d.mts +52 -0
- package/dist/variants/progress-circle.mjs +49 -0
- package/dist/variants/scroll-area.d.mts +24 -0
- package/dist/variants/scroll-area.mjs +63 -0
- package/dist/variants/separator.d.mts +23 -0
- package/dist/variants/separator.mjs +25 -0
- package/dist/variants/sheet.d.mts +20 -0
- package/dist/variants/sheet.mjs +50 -0
- package/dist/variants/sidebar.d.mts +23 -0
- package/dist/variants/sidebar.mjs +42 -0
- package/dist/variants/toggle.d.mts +23 -0
- package/dist/variants/toggle.mjs +43 -0
- package/package.json +169 -21
- package/src/components/accordion.tsx +156 -0
- package/src/components/alert-dialog.tsx +314 -0
- package/src/components/alert.tsx +86 -0
- package/src/components/aspect-ratio.tsx +28 -0
- package/src/components/avatar.tsx +84 -0
- package/src/components/badge.tsx +38 -0
- package/src/components/breadcrumb.tsx +197 -0
- package/src/components/button-group.tsx +107 -0
- package/src/components/button.tsx +66 -0
- package/src/components/calendar.tsx +277 -0
- package/src/components/card.tsx +175 -0
- package/src/components/carousel.tsx +367 -0
- package/src/components/chart.tsx +587 -0
- package/src/components/checkbox-cards.tsx +92 -0
- package/src/components/checkbox-group.tsx +83 -0
- package/src/components/checkbox.tsx +65 -0
- package/src/components/collapsible.tsx +60 -0
- package/src/components/command.tsx +311 -0
- package/src/components/context-menu.tsx +489 -0
- package/src/components/dialog.tsx +295 -0
- package/src/components/drawer.tsx +271 -0
- package/src/components/dropdown-menu.tsx +498 -0
- package/src/components/empty.tsx +169 -0
- package/src/components/field.tsx +362 -0
- package/src/components/form.tsx +300 -0
- package/src/components/hover-card.tsx +116 -0
- package/src/components/input-group.tsx +224 -0
- package/src/components/input-number.tsx +161 -0
- package/src/components/input-otp.tsx +151 -0
- package/src/components/input-password.tsx +74 -0
- package/src/components/input-search.tsx +98 -0
- package/src/components/input.tsx +52 -0
- package/src/components/item.tsx +280 -0
- package/src/components/kbd.tsx +59 -0
- package/src/components/label.tsx +44 -0
- package/src/components/menubar.tsx +531 -0
- package/src/components/native-select.tsx +96 -0
- package/src/components/navigation-menu.tsx +295 -0
- package/src/components/pagination.tsx +204 -0
- package/src/components/popover.tsx +139 -0
- package/src/components/progress-circle.tsx +203 -0
- package/src/components/progress.tsx +54 -0
- package/src/components/radio-cards.tsx +85 -0
- package/src/components/radio-group.tsx +79 -0
- package/src/components/radio.tsx +61 -0
- package/src/components/resizable.tsx +99 -0
- package/src/components/scroll-area.tsx +115 -0
- package/src/components/select.tsx +319 -0
- package/src/components/separator.tsx +74 -0
- package/src/components/sheet.tsx +278 -0
- package/src/components/sidebar.tsx +1056 -0
- package/src/components/skeleton.tsx +37 -0
- package/src/components/slider.tsx +95 -0
- package/src/components/sonner.tsx +47 -0
- package/src/components/spinner.tsx +75 -0
- package/src/components/switch.tsx +66 -0
- package/src/components/table.tsx +200 -0
- package/src/components/tabs.tsx +128 -0
- package/src/components/textarea.tsx +49 -0
- package/src/components/toggle-group.tsx +141 -0
- package/src/components/toggle.tsx +39 -0
- package/src/components/tooltip.tsx +141 -0
- package/src/css/amber.css +59 -22
- package/src/css/blue.css +59 -22
- package/src/css/cyan.css +59 -22
- package/src/css/emerald.css +59 -22
- package/src/css/fuchsia.css +59 -22
- package/src/css/gray.css +59 -22
- package/src/css/green.css +59 -22
- package/src/css/indigo.css +59 -22
- package/src/css/lime.css +59 -22
- package/src/css/neutral.css +59 -22
- package/src/css/orange.css +59 -22
- package/src/css/pink.css +59 -22
- package/src/css/preset.css +32 -13
- package/src/css/purple.css +59 -22
- package/src/css/red.css +59 -22
- package/src/css/rose.css +59 -22
- package/src/css/sky.css +59 -22
- package/src/css/slate.css +59 -22
- package/src/css/stone.css +59 -22
- package/src/css/teal.css +59 -22
- package/src/css/violet.css +59 -22
- package/src/css/yellow.css +59 -22
- package/src/css/zinc.css +59 -22
- package/src/hooks/use-animated-value.ts +97 -0
- package/src/hooks/use-copy-to-clipboard.ts +63 -0
- package/src/hooks/use-is-mobile.ts +27 -0
- package/src/hooks/use-media-query.ts +71 -0
- package/src/hooks/use-mutation-observer.ts +54 -0
- package/src/hooks/use-pagination.ts +166 -0
- package/src/index.ts +720 -0
- package/src/lib/utils.ts +5 -0
- package/src/primitives/checkbox-group.tsx +360 -0
- package/src/primitives/input-number.tsx +1013 -0
- package/src/primitives/input.tsx +243 -0
- package/src/primitives/progress-circle.tsx +537 -0
- package/src/variants/alert.ts +45 -0
- package/src/variants/badge.ts +66 -0
- package/src/variants/button-group.ts +49 -0
- package/src/variants/button.ts +93 -0
- package/src/variants/empty.ts +43 -0
- package/src/variants/field.ts +50 -0
- package/src/variants/input-group.ts +132 -0
- package/src/variants/item.ts +90 -0
- package/src/variants/navigation-menu.ts +32 -0
- package/src/variants/progress-circle.ts +47 -0
- package/src/variants/scroll-area.ts +79 -0
- package/src/variants/separator.ts +41 -0
- package/src/variants/sheet.ts +70 -0
- package/src/variants/sidebar.ts +61 -0
- package/src/variants/toggle.ts +59 -0
- package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/clsx.d.mts +0 -6
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import type { Scope } from "@radix-ui/react-context";
|
|
2
|
+
import type { ComponentProps, JSX } from "react";
|
|
3
|
+
|
|
4
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
5
|
+
import { createCheckboxScope } from "@radix-ui/react-checkbox";
|
|
6
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
7
|
+
import { useDirection } from "@radix-ui/react-direction";
|
|
8
|
+
import * as RovingFocusGroup from "@radix-ui/react-roving-focus";
|
|
9
|
+
import { createRovingFocusGroupScope } from "@radix-ui/react-roving-focus";
|
|
10
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
11
|
+
import { useCallback } from "react";
|
|
12
|
+
|
|
13
|
+
/* -----------------------------------------------------------------------------
|
|
14
|
+
* Context: CheckboxGroup
|
|
15
|
+
* --------------------------------------------------------------------------- */
|
|
16
|
+
|
|
17
|
+
const CHECKBOX_GROUP_NAME = "CheckboxGroup";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Type for components that can be scoped within the CheckboxGroup context
|
|
21
|
+
*/
|
|
22
|
+
type ScopedProps<P> = P & {
|
|
23
|
+
/**
|
|
24
|
+
* Optional scope for the CheckboxGroup component
|
|
25
|
+
*/
|
|
26
|
+
__scopeCheckboxGroup?: Scope;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const [createCheckboxGroupContext, createCheckboxGroupScope] = createContextScope(
|
|
30
|
+
CHECKBOX_GROUP_NAME,
|
|
31
|
+
[createRovingFocusGroupScope, createCheckboxScope],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const useRovingFocusGroupScope = createRovingFocusGroupScope();
|
|
35
|
+
const useCheckboxScope = createCheckboxScope();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Context values shared between CheckboxGroup components
|
|
39
|
+
*/
|
|
40
|
+
interface CheckboxGroupContextValue {
|
|
41
|
+
/**
|
|
42
|
+
* Whether all checkbox items are disabled
|
|
43
|
+
*/
|
|
44
|
+
disabled: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Function called when a checkbox item is checked
|
|
48
|
+
* @param value - The value of the checked item
|
|
49
|
+
*/
|
|
50
|
+
onItemCheck: (value: string) => void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Function called when a checkbox item is unchecked
|
|
54
|
+
* @param value - The value of the unchecked item
|
|
55
|
+
*/
|
|
56
|
+
onItemUncheck: (value: string) => void;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether checkbox selection is required
|
|
60
|
+
*/
|
|
61
|
+
required: boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Optional name attribute for the checkbox group form field
|
|
65
|
+
*/
|
|
66
|
+
name?: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Array of currently selected checkbox values
|
|
70
|
+
*/
|
|
71
|
+
value?: Array<string>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const [CheckboxGroupContextProvider, useCheckboxGroupContext] =
|
|
75
|
+
createCheckboxGroupContext<CheckboxGroupContextValue>(CHECKBOX_GROUP_NAME);
|
|
76
|
+
|
|
77
|
+
/* -----------------------------------------------------------------------------
|
|
78
|
+
* Component: CheckboxGroup
|
|
79
|
+
* --------------------------------------------------------------------------- */
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Base props for the CheckboxGroup component
|
|
83
|
+
*/
|
|
84
|
+
interface CheckboxGroupBaseProps {
|
|
85
|
+
/**
|
|
86
|
+
* Default values for the checkbox group when uncontrolled
|
|
87
|
+
*/
|
|
88
|
+
defaultValue?: Array<string>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Direction for roving focus navigation
|
|
92
|
+
*/
|
|
93
|
+
dir?: RovingFocusGroup.RovingFocusGroupProps["dir"];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether the entire checkbox group is disabled
|
|
97
|
+
*/
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether focus should loop to the start/end when reaching the boundaries
|
|
102
|
+
*/
|
|
103
|
+
loop?: RovingFocusGroup.RovingFocusGroupProps["loop"];
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Name attribute for the checkbox group form field
|
|
107
|
+
*/
|
|
108
|
+
name?: CheckboxGroupContextValue["name"];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Callback fired when the selected values change
|
|
112
|
+
* @param value - The new array of selected values
|
|
113
|
+
*/
|
|
114
|
+
onValueChange?: (value?: Array<string>) => void;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Orientation of the checkbox group (horizontal or vertical)
|
|
118
|
+
*/
|
|
119
|
+
orientation?: RovingFocusGroup.RovingFocusGroupProps["orientation"];
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Whether at least one checkbox must be selected
|
|
123
|
+
*/
|
|
124
|
+
required?: boolean;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Controlled values for the checkbox group
|
|
128
|
+
*/
|
|
129
|
+
value?: CheckboxGroupContextValue["value"];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Props for the CheckboxGroup component
|
|
134
|
+
*
|
|
135
|
+
* @since 0.3.16-canary.0
|
|
136
|
+
*/
|
|
137
|
+
type CheckboxGroupProps = CheckboxGroupBaseProps & ComponentProps<"div">;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* CheckboxGroup component that manages a group of checkboxes with roving focus
|
|
141
|
+
*
|
|
142
|
+
* @since 0.3.16-canary.0
|
|
143
|
+
*/
|
|
144
|
+
function CheckboxGroup({
|
|
145
|
+
__scopeCheckboxGroup,
|
|
146
|
+
defaultValue,
|
|
147
|
+
dir,
|
|
148
|
+
disabled = false,
|
|
149
|
+
loop = true,
|
|
150
|
+
name,
|
|
151
|
+
onValueChange,
|
|
152
|
+
orientation,
|
|
153
|
+
required = false,
|
|
154
|
+
value: valueProperty,
|
|
155
|
+
...props
|
|
156
|
+
}: ScopedProps<CheckboxGroupProps>): JSX.Element {
|
|
157
|
+
/**
|
|
158
|
+
* Scope for the RovingFocusGroup component
|
|
159
|
+
*/
|
|
160
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Direction for layout and navigation
|
|
164
|
+
*/
|
|
165
|
+
const direction = useDirection(dir);
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* State for managing selected checkbox values
|
|
169
|
+
*/
|
|
170
|
+
const [value = [], setValue] = useControllableState<Array<string> | undefined>({
|
|
171
|
+
defaultProp: defaultValue,
|
|
172
|
+
onChange: onValueChange,
|
|
173
|
+
prop: valueProperty,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Handles checking a checkbox item
|
|
178
|
+
* @param itemValue - Value of the checkbox being checked
|
|
179
|
+
*/
|
|
180
|
+
const handleItemCheck = useCallback(
|
|
181
|
+
(itemValue: string) => {
|
|
182
|
+
setValue((previousValue) => [...(previousValue ?? []), itemValue]);
|
|
183
|
+
},
|
|
184
|
+
[setValue],
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Handles unchecking a checkbox item
|
|
189
|
+
* @param itemValue - Value of the checkbox being unchecked
|
|
190
|
+
*/
|
|
191
|
+
const handleItemUncheck = useCallback(
|
|
192
|
+
(itemValue: string) => {
|
|
193
|
+
setValue((previousValue) => {
|
|
194
|
+
const currentValue = previousValue ?? [];
|
|
195
|
+
|
|
196
|
+
// If this is the last selected item and required=true, prevent unchecking
|
|
197
|
+
if (required && currentValue.length === 1 && currentValue[0] === itemValue) {
|
|
198
|
+
return currentValue; // Keep the current state
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Otherwise, proceed with unchecking
|
|
202
|
+
return currentValue.filter((inputValue) => inputValue !== itemValue);
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
[setValue, required],
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<CheckboxGroupContextProvider
|
|
210
|
+
disabled={disabled}
|
|
211
|
+
name={name}
|
|
212
|
+
required={required}
|
|
213
|
+
scope={__scopeCheckboxGroup}
|
|
214
|
+
value={value}
|
|
215
|
+
onItemCheck={handleItemCheck}
|
|
216
|
+
onItemUncheck={handleItemUncheck}
|
|
217
|
+
>
|
|
218
|
+
<RovingFocusGroup.Root
|
|
219
|
+
asChild
|
|
220
|
+
{...rovingFocusGroupScope}
|
|
221
|
+
dir={direction}
|
|
222
|
+
loop={loop}
|
|
223
|
+
orientation={orientation}
|
|
224
|
+
>
|
|
225
|
+
<div data-disabled={disabled ? "" : undefined} dir={direction} role="group" {...props} />
|
|
226
|
+
</RovingFocusGroup.Root>
|
|
227
|
+
</CheckboxGroupContextProvider>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* -----------------------------------------------------------------------------
|
|
232
|
+
* Component: CheckboxGroupItem
|
|
233
|
+
* --------------------------------------------------------------------------- */
|
|
234
|
+
const ITEM_NAME = "CheckboxGroupItem";
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Props for the CheckboxGroupItem component
|
|
238
|
+
*
|
|
239
|
+
* @since 0.3.16-canary.0
|
|
240
|
+
*/
|
|
241
|
+
interface CheckboxGroupItemProps extends Omit<
|
|
242
|
+
ComponentProps<typeof CheckboxPrimitive.Root>,
|
|
243
|
+
"checked" | "defaultChecked" | "name" | "onCheckedChange"
|
|
244
|
+
> {
|
|
245
|
+
/**
|
|
246
|
+
* Value of the checkbox item, used to identify the item within the group
|
|
247
|
+
*/
|
|
248
|
+
value: string;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Whether this specific checkbox item is disabled
|
|
252
|
+
*/
|
|
253
|
+
disabled?: boolean;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Individual checkbox item within a CheckboxGroup
|
|
258
|
+
*
|
|
259
|
+
* @since 0.3.16-canary.0
|
|
260
|
+
*/
|
|
261
|
+
function CheckboxGroupItem({
|
|
262
|
+
__scopeCheckboxGroup,
|
|
263
|
+
disabled,
|
|
264
|
+
...props
|
|
265
|
+
}: ScopedProps<CheckboxGroupItemProps>): JSX.Element {
|
|
266
|
+
/**
|
|
267
|
+
* Context values from the parent CheckboxGroup
|
|
268
|
+
*/
|
|
269
|
+
const context = useCheckboxGroupContext(ITEM_NAME, __scopeCheckboxGroup);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Combined disabled state from both context and props
|
|
273
|
+
*/
|
|
274
|
+
const isDisabled = context.disabled || disabled;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Scope for the RovingFocusGroup component
|
|
278
|
+
*/
|
|
279
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeCheckboxGroup);
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Scope for the Checkbox component
|
|
283
|
+
*/
|
|
284
|
+
const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Whether this checkbox is currently checked
|
|
288
|
+
*/
|
|
289
|
+
const checked = context.value?.includes(props.value);
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<RovingFocusGroup.Item
|
|
293
|
+
asChild
|
|
294
|
+
{...rovingFocusGroupScope}
|
|
295
|
+
active={checked}
|
|
296
|
+
focusable={!isDisabled}
|
|
297
|
+
>
|
|
298
|
+
<CheckboxPrimitive.Root
|
|
299
|
+
aria-label={props.value}
|
|
300
|
+
checked={checked}
|
|
301
|
+
disabled={isDisabled}
|
|
302
|
+
name={context.name}
|
|
303
|
+
required={context.required}
|
|
304
|
+
{...checkboxScope}
|
|
305
|
+
{...props}
|
|
306
|
+
onCheckedChange={(checkedState) => {
|
|
307
|
+
if (checkedState) {
|
|
308
|
+
context.onItemCheck(props.value);
|
|
309
|
+
} else {
|
|
310
|
+
context.onItemUncheck(props.value);
|
|
311
|
+
}
|
|
312
|
+
}}
|
|
313
|
+
/>
|
|
314
|
+
</RovingFocusGroup.Item>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/* -----------------------------------------------------------------------------
|
|
319
|
+
* Component: CheckboxGroupIndicator
|
|
320
|
+
* --------------------------------------------------------------------------- */
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Props for the CheckboxGroupIndicator component
|
|
324
|
+
*
|
|
325
|
+
* @since 0.3.16-canary.0
|
|
326
|
+
*/
|
|
327
|
+
type CheckboxGroupIndicatorProps = ComponentProps<typeof CheckboxPrimitive.Indicator>;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Visual indicator component for a CheckboxGroupItem
|
|
331
|
+
*
|
|
332
|
+
* @since 0.3.16-canary.0
|
|
333
|
+
*/
|
|
334
|
+
function CheckboxGroupIndicator({
|
|
335
|
+
__scopeCheckboxGroup,
|
|
336
|
+
...props
|
|
337
|
+
}: ScopedProps<CheckboxGroupIndicatorProps>): JSX.Element {
|
|
338
|
+
/**
|
|
339
|
+
* Scope for the Checkbox component
|
|
340
|
+
*/
|
|
341
|
+
const checkboxScope = useCheckboxScope(__scopeCheckboxGroup);
|
|
342
|
+
|
|
343
|
+
return <CheckboxPrimitive.Indicator {...checkboxScope} {...props} />;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/* -----------------------------------------------------------------------------
|
|
347
|
+
* Exports
|
|
348
|
+
* -------------------------------------------------------------------------- */
|
|
349
|
+
|
|
350
|
+
export {
|
|
351
|
+
CheckboxGroup,
|
|
352
|
+
CheckboxGroupIndicator,
|
|
353
|
+
CheckboxGroupItem,
|
|
354
|
+
createCheckboxGroupScope,
|
|
355
|
+
CheckboxGroupIndicator as Indicator,
|
|
356
|
+
CheckboxGroupItem as Item,
|
|
357
|
+
CheckboxGroup as Root,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export type { CheckboxGroupIndicatorProps, CheckboxGroupItemProps, CheckboxGroupProps };
|