@proyecto-viviana/solidaria-components 0.3.2 → 0.4.0
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/dist/ActionBar.js +184 -0
- package/dist/ActionBar.js.map +1 -0
- package/dist/ActionBar.jsx +128 -0
- package/dist/ActionBar.jsx.map +1 -0
- package/dist/ActionGroup.js +179 -0
- package/dist/ActionGroup.js.map +1 -0
- package/dist/ActionGroup.jsx +129 -0
- package/dist/ActionGroup.jsx.map +1 -0
- package/dist/Alert.js +111 -0
- package/dist/Alert.js.map +1 -0
- package/dist/Alert.jsx +82 -0
- package/dist/Alert.jsx.map +1 -0
- package/dist/Autocomplete.js +130 -0
- package/dist/Autocomplete.js.map +1 -0
- package/dist/Autocomplete.jsx +116 -0
- package/dist/Autocomplete.jsx.map +1 -0
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Breadcrumbs.js +334 -0
- package/dist/Breadcrumbs.js.map +1 -0
- package/dist/Breadcrumbs.jsx +266 -0
- package/dist/Breadcrumbs.jsx.map +1 -0
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +348 -0
- package/dist/Button.js.map +1 -0
- package/dist/Button.jsx +314 -0
- package/dist/Button.jsx.map +1 -0
- package/dist/Calendar.d.ts +4 -4
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Calendar.js +538 -0
- package/dist/Calendar.js.map +1 -0
- package/dist/Calendar.jsx +333 -0
- package/dist/Calendar.jsx.map +1 -0
- package/dist/CalendarPicker.d.ts +33 -0
- package/dist/CalendarPicker.d.ts.map +1 -0
- package/dist/CalendarPicker.js +44 -0
- package/dist/CalendarPicker.js.map +1 -0
- package/dist/CalendarPicker.jsx +44 -0
- package/dist/CalendarPicker.jsx.map +1 -0
- package/dist/Checkbox.d.ts +83 -4
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Checkbox.js +923 -0
- package/dist/Checkbox.js.map +1 -0
- package/dist/Checkbox.jsx +707 -0
- package/dist/Checkbox.jsx.map +1 -0
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +202 -0
- package/dist/Collection.js.map +1 -0
- package/dist/Collection.jsx +152 -0
- package/dist/Collection.jsx.map +1 -0
- package/dist/Color.d.ts.map +1 -1
- package/dist/Color.js +1720 -0
- package/dist/Color.js.map +1 -0
- package/dist/Color.jsx +1344 -0
- package/dist/Color.jsx.map +1 -0
- package/dist/ColorEditor.js +208 -0
- package/dist/ColorEditor.js.map +1 -0
- package/dist/ColorEditor.jsx +120 -0
- package/dist/ColorEditor.jsx.map +1 -0
- package/dist/ComboBox.d.ts +4 -4
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ComboBox.js +992 -0
- package/dist/ComboBox.js.map +1 -0
- package/dist/ComboBox.jsx +714 -0
- package/dist/ComboBox.jsx.map +1 -0
- package/dist/ContextualHelpTrigger.js +146 -0
- package/dist/ContextualHelpTrigger.js.map +1 -0
- package/dist/ContextualHelpTrigger.jsx +109 -0
- package/dist/ContextualHelpTrigger.jsx.map +1 -0
- package/dist/DateField.d.ts +3 -3
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DateField.js +4 -0
- package/dist/DateField.jsx +4 -0
- package/dist/DateField2.js +499 -0
- package/dist/DateField2.js.map +1 -0
- package/dist/DateField2.jsx +317 -0
- package/dist/DateField2.jsx.map +1 -0
- package/dist/DatePicker.d.ts +4 -4
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DatePicker.js +991 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/DatePicker.jsx +682 -0
- package/dist/DatePicker.jsx.map +1 -0
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Dialog.js +337 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Dialog.jsx +192 -0
- package/dist/Dialog.jsx.map +1 -0
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/Disclosure.js +328 -0
- package/dist/Disclosure.js.map +1 -0
- package/dist/Disclosure.jsx +230 -0
- package/dist/Disclosure.jsx.map +1 -0
- package/dist/DragAndDrop.d.ts.map +1 -1
- package/dist/DragAndDrop.js +176 -0
- package/dist/DragAndDrop.js.map +1 -0
- package/dist/DragAndDrop.jsx +160 -0
- package/dist/DragAndDrop.jsx.map +1 -0
- package/dist/DropZone.d.ts.map +1 -1
- package/dist/DropZone.js +189 -0
- package/dist/DropZone.js.map +1 -0
- package/dist/DropZone.jsx +144 -0
- package/dist/DropZone.jsx.map +1 -0
- package/dist/FieldError.js +66 -0
- package/dist/FieldError.js.map +1 -0
- package/dist/FieldError.jsx +47 -0
- package/dist/FieldError.jsx.map +1 -0
- package/dist/FileTrigger.js +79 -0
- package/dist/FileTrigger.js.map +1 -0
- package/dist/FileTrigger.jsx +49 -0
- package/dist/FileTrigger.jsx.map +1 -0
- package/dist/Focusable.js +70 -0
- package/dist/Focusable.js.map +1 -0
- package/dist/Focusable.jsx +69 -0
- package/dist/Focusable.jsx.map +1 -0
- package/dist/Form.js +99 -0
- package/dist/Form.js.map +1 -0
- package/dist/Form.jsx +73 -0
- package/dist/Form.jsx.map +1 -0
- package/dist/GridList.d.ts +34 -2
- package/dist/GridList.d.ts.map +1 -1
- package/dist/GridList.js +723 -0
- package/dist/GridList.js.map +1 -0
- package/dist/GridList.jsx +552 -0
- package/dist/GridList.jsx.map +1 -0
- package/dist/HiddenTimeInput.js +104 -0
- package/dist/HiddenTimeInput.js.map +1 -0
- package/dist/HiddenTimeInput.jsx +69 -0
- package/dist/HiddenTimeInput.jsx.map +1 -0
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Icon.js +127 -0
- package/dist/Icon.js.map +1 -0
- package/dist/Icon.jsx +72 -0
- package/dist/Icon.jsx.map +1 -0
- package/dist/Keyboard.js +30 -0
- package/dist/Keyboard.js.map +1 -0
- package/dist/Keyboard.jsx +24 -0
- package/dist/Keyboard.jsx.map +1 -0
- package/dist/Landmark.js +134 -0
- package/dist/Landmark.js.map +1 -0
- package/dist/Landmark.jsx +118 -0
- package/dist/Landmark.jsx.map +1 -0
- package/dist/Link.d.ts.map +1 -1
- package/dist/Link.js +219 -0
- package/dist/Link.js.map +1 -0
- package/dist/Link.jsx +189 -0
- package/dist/Link.jsx.map +1 -0
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListBox.js +670 -0
- package/dist/ListBox.js.map +1 -0
- package/dist/ListBox.jsx +508 -0
- package/dist/ListBox.jsx.map +1 -0
- package/dist/Menu.d.ts +27 -9
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Menu.js +1254 -0
- package/dist/Menu.js.map +1 -0
- package/dist/Menu.jsx +1042 -0
- package/dist/Menu.jsx.map +1 -0
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Meter.js +123 -0
- package/dist/Meter.js.map +1 -0
- package/dist/Meter.jsx +107 -0
- package/dist/Meter.jsx.map +1 -0
- package/dist/Modal.d.ts.map +1 -1
- package/dist/Modal.js +380 -0
- package/dist/Modal.js.map +1 -0
- package/dist/Modal.jsx +314 -0
- package/dist/Modal.jsx.map +1 -0
- package/dist/NumberField.d.ts +3 -3
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/NumberField.js +573 -0
- package/dist/NumberField.js.map +1 -0
- package/dist/NumberField.jsx +443 -0
- package/dist/NumberField.jsx.map +1 -0
- package/dist/Popover.d.ts +10 -2
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Popover.js +464 -0
- package/dist/Popover.js.map +1 -0
- package/dist/Popover.jsx +333 -0
- package/dist/Popover.jsx.map +1 -0
- package/dist/Pressable.js +69 -0
- package/dist/Pressable.js.map +1 -0
- package/dist/Pressable.jsx +68 -0
- package/dist/Pressable.jsx.map +1 -0
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/ProgressBar.js +130 -0
- package/dist/ProgressBar.js.map +1 -0
- package/dist/ProgressBar.jsx +114 -0
- package/dist/ProgressBar.jsx.map +1 -0
- package/dist/RadioGroup.d.ts +82 -4
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RadioGroup.js +931 -0
- package/dist/RadioGroup.js.map +1 -0
- package/dist/RadioGroup.jsx +681 -0
- package/dist/RadioGroup.jsx.map +1 -0
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RangeCalendar.js +410 -0
- package/dist/RangeCalendar.js.map +1 -0
- package/dist/RangeCalendar.jsx +253 -0
- package/dist/RangeCalendar.jsx.map +1 -0
- package/dist/RouterProvider.js +118 -0
- package/dist/RouterProvider.js.map +1 -0
- package/dist/RouterProvider.jsx +112 -0
- package/dist/RouterProvider.jsx.map +1 -0
- package/dist/SearchField.d.ts +2 -2
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/SearchField.js +643 -0
- package/dist/SearchField.js.map +1 -0
- package/dist/SearchField.jsx +526 -0
- package/dist/SearchField.jsx.map +1 -0
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +1031 -0
- package/dist/Select.js.map +1 -0
- package/dist/Select.jsx +744 -0
- package/dist/Select.jsx.map +1 -0
- package/dist/SelectionIndicator.d.ts.map +1 -1
- package/dist/SelectionIndicator.js +86 -0
- package/dist/SelectionIndicator.js.map +1 -0
- package/dist/SelectionIndicator.jsx +50 -0
- package/dist/SelectionIndicator.jsx.map +1 -0
- package/dist/Separator.js +97 -0
- package/dist/Separator.js.map +1 -0
- package/dist/Separator.jsx +85 -0
- package/dist/Separator.jsx.map +1 -0
- package/dist/SharedElementTransition.d.ts.map +1 -1
- package/dist/SharedElementTransition.js +165 -0
- package/dist/SharedElementTransition.js.map +1 -0
- package/dist/SharedElementTransition.jsx +138 -0
- package/dist/SharedElementTransition.jsx.map +1 -0
- package/dist/Slider.d.ts +33 -1
- package/dist/Slider.d.ts.map +1 -1
- package/dist/Slider.js +515 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Slider.jsx +403 -0
- package/dist/Slider.jsx.map +1 -0
- package/dist/StepList.js +198 -0
- package/dist/StepList.js.map +1 -0
- package/dist/StepList.jsx +141 -0
- package/dist/StepList.jsx.map +1 -0
- package/dist/Switch.d.ts +65 -2
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Switch.js +534 -0
- package/dist/Switch.js.map +1 -0
- package/dist/Switch.jsx +393 -0
- package/dist/Switch.jsx.map +1 -0
- package/dist/Table.d.ts +48 -0
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +1759 -0
- package/dist/Table.js.map +1 -0
- package/dist/Table.jsx +1348 -0
- package/dist/Table.jsx.map +1 -0
- package/dist/Tabs.d.ts +0 -4
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/Tabs.js +595 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Tabs.jsx +367 -0
- package/dist/Tabs.jsx.map +1 -0
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/TagGroup.js +378 -0
- package/dist/TagGroup.js.map +1 -0
- package/dist/TagGroup.jsx +270 -0
- package/dist/TagGroup.jsx.map +1 -0
- package/dist/Text.d.ts +18 -6
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +42 -0
- package/dist/Text.js.map +1 -0
- package/dist/Text.jsx +35 -0
- package/dist/Text.jsx.map +1 -0
- package/dist/TextField.d.ts +6 -6
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +436 -0
- package/dist/TextField.js.map +1 -0
- package/dist/TextField.jsx +403 -0
- package/dist/TextField.jsx.map +1 -0
- package/dist/TimeField.d.ts +3 -3
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/TimeField.js +372 -0
- package/dist/TimeField.js.map +1 -0
- package/dist/TimeField.jsx +224 -0
- package/dist/TimeField.jsx.map +1 -0
- package/dist/Toast.d.ts +14 -0
- package/dist/Toast.d.ts.map +1 -1
- package/dist/Toast.js +551 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Toast.jsx +361 -0
- package/dist/Toast.jsx.map +1 -0
- package/dist/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButton.js +123 -0
- package/dist/ToggleButton.js.map +1 -0
- package/dist/ToggleButton.jsx +88 -0
- package/dist/ToggleButton.jsx.map +1 -0
- package/dist/ToggleButtonGroup.d.ts.map +1 -1
- package/dist/ToggleButtonGroup.js +114 -0
- package/dist/ToggleButtonGroup.js.map +1 -0
- package/dist/ToggleButtonGroup.jsx +85 -0
- package/dist/ToggleButtonGroup.jsx.map +1 -0
- package/dist/Toolbar.js +112 -0
- package/dist/Toolbar.js.map +1 -0
- package/dist/Toolbar.jsx +92 -0
- package/dist/Toolbar.jsx.map +1 -0
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip.js +539 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/Tooltip.jsx +465 -0
- package/dist/Tooltip.jsx.map +1 -0
- package/dist/Tree.d.ts +14 -2
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Tree.js +1424 -0
- package/dist/Tree.js.map +1 -0
- package/dist/Tree.jsx +1172 -0
- package/dist/Tree.jsx.map +1 -0
- package/dist/Virtualizer.d.ts +16 -2
- package/dist/Virtualizer.d.ts.map +1 -1
- package/dist/Virtualizer.js +2 -0
- package/dist/Virtualizer.jsx +2 -0
- package/dist/Virtualizer2.js +751 -0
- package/dist/Virtualizer2.js.map +1 -0
- package/dist/Virtualizer2.jsx +730 -0
- package/dist/Virtualizer2.jsx.map +1 -0
- package/dist/VirtualizerLayouts.d.ts +18 -0
- package/dist/VirtualizerLayouts.d.ts.map +1 -1
- package/dist/VisuallyHidden.js +42 -0
- package/dist/VisuallyHidden.js.map +1 -0
- package/dist/VisuallyHidden.jsx +35 -0
- package/dist/VisuallyHidden.jsx.map +1 -0
- package/dist/contexts.js +33 -0
- package/dist/contexts.js.map +1 -0
- package/dist/contexts.jsx +33 -0
- package/dist/contexts.jsx.map +1 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -23932
- package/dist/index.jsx +70 -18337
- package/dist/useDragAndDrop.js +2 -0
- package/dist/useDragAndDrop.jsx +2 -0
- package/dist/useDragAndDrop2.js +395 -0
- package/dist/useDragAndDrop2.js.map +1 -0
- package/dist/useDragAndDrop2.jsx +395 -0
- package/dist/useDragAndDrop2.jsx.map +1 -0
- package/dist/utils.d.ts +83 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +285 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.jsx +277 -0
- package/dist/utils.jsx.map +1 -0
- package/dist/virtualizer/Layout.js +144 -0
- package/dist/virtualizer/Layout.js.map +1 -0
- package/dist/virtualizer/Layout.jsx +144 -0
- package/dist/virtualizer/Layout.jsx.map +1 -0
- package/package.json +401 -4
- package/src/Breadcrumbs.tsx +3 -1
- package/src/Button.tsx +22 -2
- package/src/Calendar.tsx +27 -10
- package/src/CalendarPicker.tsx +73 -0
- package/src/Checkbox.tsx +539 -3
- package/src/Collection.tsx +9 -3
- package/src/Color.tsx +42 -14
- package/src/ComboBox.tsx +50 -6
- package/src/DateField.tsx +20 -2
- package/src/DatePicker.tsx +57 -5
- package/src/Dialog.tsx +13 -5
- package/src/Disclosure.tsx +3 -1
- package/src/DragAndDrop.tsx +3 -1
- package/src/DropZone.tsx +3 -1
- package/src/GridList.tsx +125 -24
- package/src/Icon.tsx +3 -1
- package/src/Link.tsx +3 -1
- package/src/ListBox.tsx +31 -4
- package/src/Menu.tsx +252 -128
- package/src/Meter.tsx +3 -1
- package/src/Modal.tsx +100 -52
- package/src/NumberField.tsx +51 -8
- package/src/Popover.tsx +40 -10
- package/src/ProgressBar.tsx +3 -1
- package/src/RadioGroup.tsx +468 -4
- package/src/RangeCalendar.tsx +3 -1
- package/src/SearchField.tsx +27 -3
- package/src/Select.tsx +22 -7
- package/src/SelectionIndicator.tsx +3 -1
- package/src/SharedElementTransition.tsx +3 -1
- package/src/Slider.tsx +159 -13
- package/src/Switch.tsx +395 -2
- package/src/Table.tsx +409 -95
- package/src/Tabs.tsx +16 -45
- package/src/TagGroup.tsx +3 -1
- package/src/Text.tsx +31 -10
- package/src/TextField.tsx +43 -5
- package/src/TimeField.tsx +20 -2
- package/src/Toast.tsx +79 -14
- package/src/ToggleButton.tsx +3 -1
- package/src/ToggleButtonGroup.tsx +3 -1
- package/src/Tooltip.tsx +3 -1
- package/src/Tree.tsx +77 -9
- package/src/Virtualizer.tsx +180 -31
- package/src/VirtualizerLayouts.ts +45 -10
- package/src/index.ts +50 -0
- package/src/utils.tsx +243 -27
- package/dist/index.js.map +0 -1
- package/dist/index.jsx.map +0 -1
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { Provider, filterDOMProps, useRenderProps } from "./utils.jsx";
|
|
2
|
+
import { VisuallyHidden } from "./VisuallyHidden.jsx";
|
|
3
|
+
import { FieldErrorContext } from "./FieldError.jsx";
|
|
4
|
+
import { TextContext } from "./Text.jsx";
|
|
5
|
+
import { FormContext } from "./Form.jsx";
|
|
6
|
+
import { Show, createContext, createMemo, createSignal, createUniqueId, splitProps, useContext } from "solid-js";
|
|
7
|
+
import { createCheckbox, createCheckboxGroup, createCheckboxGroupItem, createFocusRing, createHover, mergeProps as mergeProps$1 } from "@proyecto-viviana/solidaria";
|
|
8
|
+
import { VALID_VALIDITY_STATE, createCheckboxGroupState, createToggleState } from "@proyecto-viviana/solid-stately";
|
|
9
|
+
//#region src/Checkbox.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Checkbox and CheckboxGroup components for solidaria-components
|
|
12
|
+
*
|
|
13
|
+
* Pre-wired headless checkbox components that combine state + aria hooks.
|
|
14
|
+
* Port of react-aria-components/src/Checkbox.tsx
|
|
15
|
+
*/
|
|
16
|
+
function assignRef(ref, el) {
|
|
17
|
+
if (!ref) return;
|
|
18
|
+
if (typeof ref === "function") ref(el);
|
|
19
|
+
else ref.current = el;
|
|
20
|
+
}
|
|
21
|
+
const CheckboxGroupContext = createContext(null);
|
|
22
|
+
const CheckboxGroupStateContext = createContext(null);
|
|
23
|
+
const CheckboxContext = createContext(null);
|
|
24
|
+
function withFormValidationBehavior(props, formContext) {
|
|
25
|
+
if (!formContext?.validationBehavior) return props;
|
|
26
|
+
return new Proxy(props, {
|
|
27
|
+
get(target, property, receiver) {
|
|
28
|
+
const localValue = Reflect.get(target, property, receiver);
|
|
29
|
+
if (property === "validationBehavior" && localValue === void 0) return formContext.validationBehavior;
|
|
30
|
+
return localValue;
|
|
31
|
+
},
|
|
32
|
+
has(target, property) {
|
|
33
|
+
return Reflect.has(target, property) || property === "validationBehavior" && formContext.validationBehavior !== void 0;
|
|
34
|
+
},
|
|
35
|
+
ownKeys(target) {
|
|
36
|
+
const keys = new Set(Reflect.ownKeys(target));
|
|
37
|
+
if (formContext.validationBehavior !== void 0) keys.add("validationBehavior");
|
|
38
|
+
return Array.from(keys);
|
|
39
|
+
},
|
|
40
|
+
getOwnPropertyDescriptor(target, property) {
|
|
41
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
42
|
+
if (descriptor) return descriptor;
|
|
43
|
+
if (property === "validationBehavior" && formContext.validationBehavior !== void 0) return {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
get: () => formContext.validationBehavior
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A checkbox group allows a user to select multiple items from a list of options.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* <CheckboxGroup>
|
|
57
|
+
* <Checkbox value="one">Option 1</Checkbox>
|
|
58
|
+
* <Checkbox value="two">Option 2</Checkbox>
|
|
59
|
+
* </CheckboxGroup>
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function CheckboxGroup(props) {
|
|
63
|
+
const [local, ariaProps] = splitProps(withFormValidationBehavior(props, useContext(FormContext)), [
|
|
64
|
+
"class",
|
|
65
|
+
"style",
|
|
66
|
+
"slot",
|
|
67
|
+
"ref",
|
|
68
|
+
"description",
|
|
69
|
+
"errorMessage",
|
|
70
|
+
"renderHelpText",
|
|
71
|
+
"children"
|
|
72
|
+
]);
|
|
73
|
+
const state = createCheckboxGroupState(() => ({
|
|
74
|
+
value: ariaProps.value,
|
|
75
|
+
defaultValue: ariaProps.defaultValue,
|
|
76
|
+
onChange: ariaProps.onChange,
|
|
77
|
+
isDisabled: ariaProps.isDisabled,
|
|
78
|
+
isReadOnly: ariaProps.isReadOnly,
|
|
79
|
+
isRequired: ariaProps.isRequired,
|
|
80
|
+
isInvalid: ariaProps.isInvalid,
|
|
81
|
+
validationState: ariaProps.validationState,
|
|
82
|
+
validate: ariaProps.validate,
|
|
83
|
+
validationBehavior: ariaProps.validationBehavior,
|
|
84
|
+
name: ariaProps.name
|
|
85
|
+
}));
|
|
86
|
+
const groupAria = createCheckboxGroup(() => ({
|
|
87
|
+
...ariaProps,
|
|
88
|
+
description: local.description,
|
|
89
|
+
errorMessage: local.errorMessage
|
|
90
|
+
}), state);
|
|
91
|
+
const renderValues = createMemo(() => ({
|
|
92
|
+
isDisabled: state.isDisabled,
|
|
93
|
+
isReadOnly: state.isReadOnly,
|
|
94
|
+
isRequired: ariaProps.isRequired ?? false,
|
|
95
|
+
isInvalid: groupAria.isInvalid,
|
|
96
|
+
state
|
|
97
|
+
}));
|
|
98
|
+
const renderProps = useRenderProps({
|
|
99
|
+
get children() {
|
|
100
|
+
return local.children;
|
|
101
|
+
},
|
|
102
|
+
class: local.class,
|
|
103
|
+
style: local.style,
|
|
104
|
+
defaultClassName: "solidaria-CheckboxGroup"
|
|
105
|
+
}, renderValues);
|
|
106
|
+
const domProps = createMemo(() => filterDOMProps(ariaProps, { global: true }));
|
|
107
|
+
const cleanGroupProps = () => {
|
|
108
|
+
const { ref: _ref, ...rest } = groupAria.groupProps;
|
|
109
|
+
return rest;
|
|
110
|
+
};
|
|
111
|
+
const setGroupRef = (el) => {
|
|
112
|
+
assignRef(local.ref, el);
|
|
113
|
+
};
|
|
114
|
+
const groupDescribedBy = () => {
|
|
115
|
+
const ids = [
|
|
116
|
+
cleanGroupProps()["aria-describedby"],
|
|
117
|
+
local.description ? groupAria.descriptionProps.id : void 0,
|
|
118
|
+
groupAria.isInvalid && local.errorMessage ? groupAria.errorMessageProps.id : void 0
|
|
119
|
+
].filter(Boolean).join(" ").split(" ").filter(Boolean);
|
|
120
|
+
return ids.length ? Array.from(new Set(ids)).join(" ") : void 0;
|
|
121
|
+
};
|
|
122
|
+
const GroupChildren = () => {
|
|
123
|
+
const childRenderValues = {
|
|
124
|
+
get isDisabled() {
|
|
125
|
+
return state.isDisabled;
|
|
126
|
+
},
|
|
127
|
+
get isReadOnly() {
|
|
128
|
+
return state.isReadOnly;
|
|
129
|
+
},
|
|
130
|
+
get isRequired() {
|
|
131
|
+
return state.isRequired();
|
|
132
|
+
},
|
|
133
|
+
get isInvalid() {
|
|
134
|
+
return groupAria.isInvalid;
|
|
135
|
+
},
|
|
136
|
+
get state() {
|
|
137
|
+
return state;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const renderedChildren = createMemo(() => {
|
|
141
|
+
const children = local.children;
|
|
142
|
+
if (typeof children === "function") return children.length > 0 ? children(childRenderValues) : children();
|
|
143
|
+
return children;
|
|
144
|
+
});
|
|
145
|
+
return <>{renderedChildren()}</>;
|
|
146
|
+
};
|
|
147
|
+
return <CheckboxGroupStateContext.Provider value={state}>
|
|
148
|
+
<div {...domProps()} {...cleanGroupProps()} ref={setGroupRef} aria-describedby={groupDescribedBy()} class={renderProps.class()} style={renderProps.style()} data-disabled={state.isDisabled || void 0} data-readonly={state.isReadOnly || void 0} data-required={ariaProps.isRequired || void 0} data-invalid={groupAria.isInvalid || void 0}>
|
|
149
|
+
<GroupChildren />
|
|
150
|
+
{}
|
|
151
|
+
<Show when={(local.renderHelpText ?? true) && local.description}>
|
|
152
|
+
<div {...groupAria.descriptionProps}>
|
|
153
|
+
{local.description}
|
|
154
|
+
</div>
|
|
155
|
+
</Show>
|
|
156
|
+
<Show when={(local.renderHelpText ?? true) && groupAria.isInvalid && local.errorMessage}>
|
|
157
|
+
<div {...groupAria.errorMessageProps}>
|
|
158
|
+
{local.errorMessage}
|
|
159
|
+
</div>
|
|
160
|
+
</Show>
|
|
161
|
+
</div>
|
|
162
|
+
</CheckboxGroupStateContext.Provider>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A checkbox allows a user to select multiple items from a list of individual items,
|
|
166
|
+
* or to mark one individual item as selected.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```tsx
|
|
170
|
+
* <Checkbox>
|
|
171
|
+
* {({ isSelected }) => (
|
|
172
|
+
* <>
|
|
173
|
+
* <span class={`checkbox ${isSelected ? 'checked' : ''}`}>
|
|
174
|
+
* {isSelected && '✓'}
|
|
175
|
+
* </span>
|
|
176
|
+
* <span>Accept terms</span>
|
|
177
|
+
* </>
|
|
178
|
+
* )}
|
|
179
|
+
* </Checkbox>
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function Checkbox(props) {
|
|
183
|
+
const [inputElement, setInputElement] = createSignal(null);
|
|
184
|
+
const formContext = useContext(FormContext);
|
|
185
|
+
const contextProps = useContext(CheckboxContext);
|
|
186
|
+
const contextSlotProps = contextProps?.slots?.[props.slot ?? "default"];
|
|
187
|
+
const contextBaseProps = createMemo(() => {
|
|
188
|
+
if (!contextProps) return {};
|
|
189
|
+
const { slots: _slots, ...rest } = contextProps;
|
|
190
|
+
return rest;
|
|
191
|
+
});
|
|
192
|
+
const mergedProps = contextProps ? mergeProps$1(contextBaseProps(), contextSlotProps ?? {}, props) : props;
|
|
193
|
+
const propsWithFormBehavior = withFormValidationBehavior(mergedProps, formContext);
|
|
194
|
+
const inputRefs = createMemo(() => [
|
|
195
|
+
contextBaseProps().inputRef,
|
|
196
|
+
contextSlotProps?.inputRef,
|
|
197
|
+
props.inputRef
|
|
198
|
+
].filter(Boolean));
|
|
199
|
+
const [local, ariaProps] = splitProps(propsWithFormBehavior, [
|
|
200
|
+
"class",
|
|
201
|
+
"style",
|
|
202
|
+
"render",
|
|
203
|
+
"ref",
|
|
204
|
+
"inputRef",
|
|
205
|
+
"slot",
|
|
206
|
+
"isIndeterminate",
|
|
207
|
+
"description",
|
|
208
|
+
"errorMessage",
|
|
209
|
+
"onHoverStart",
|
|
210
|
+
"onHoverEnd",
|
|
211
|
+
"onHoverChange"
|
|
212
|
+
]);
|
|
213
|
+
const descriptionId = createUniqueId();
|
|
214
|
+
const errorMessageId = createUniqueId();
|
|
215
|
+
const inputAriaProps = createMemo(() => {
|
|
216
|
+
const clean = {};
|
|
217
|
+
for (const key in ariaProps) if (!key.startsWith("data-")) clean[key] = ariaProps[key];
|
|
218
|
+
return clean;
|
|
219
|
+
});
|
|
220
|
+
const groupState = useContext(CheckboxGroupStateContext);
|
|
221
|
+
let isSelected;
|
|
222
|
+
let isPressed;
|
|
223
|
+
let isDisabled;
|
|
224
|
+
let isReadOnly;
|
|
225
|
+
let isInvalid;
|
|
226
|
+
let labelProps;
|
|
227
|
+
let inputProps;
|
|
228
|
+
if (groupState) {
|
|
229
|
+
const itemAria = createCheckboxGroupItem(() => ({
|
|
230
|
+
...inputAriaProps(),
|
|
231
|
+
value: inputAriaProps().value ?? "",
|
|
232
|
+
children: typeof mergedProps.children === "function" ? true : mergedProps.children
|
|
233
|
+
}), groupState, inputElement);
|
|
234
|
+
isSelected = itemAria.isSelected;
|
|
235
|
+
isPressed = itemAria.isPressed;
|
|
236
|
+
labelProps = itemAria.labelProps;
|
|
237
|
+
inputProps = () => itemAria.inputProps;
|
|
238
|
+
} else {
|
|
239
|
+
const checkboxAria = createCheckbox(() => ({
|
|
240
|
+
...inputAriaProps(),
|
|
241
|
+
isIndeterminate: local.isIndeterminate,
|
|
242
|
+
children: typeof mergedProps.children === "function" ? true : mergedProps.children
|
|
243
|
+
}), createToggleState(() => ({
|
|
244
|
+
isSelected: ariaProps.isSelected,
|
|
245
|
+
defaultSelected: ariaProps.defaultSelected,
|
|
246
|
+
onChange: ariaProps.onChange,
|
|
247
|
+
isReadOnly: ariaProps.isReadOnly
|
|
248
|
+
})), inputElement);
|
|
249
|
+
isSelected = checkboxAria.isSelected;
|
|
250
|
+
isPressed = checkboxAria.isPressed;
|
|
251
|
+
labelProps = checkboxAria.labelProps;
|
|
252
|
+
inputProps = () => checkboxAria.inputProps;
|
|
253
|
+
}
|
|
254
|
+
isDisabled = () => inputProps().disabled === true;
|
|
255
|
+
isReadOnly = () => inputProps()["aria-readonly"] === true;
|
|
256
|
+
isInvalid = () => inputProps()["aria-invalid"] === true;
|
|
257
|
+
const describedBy = () => {
|
|
258
|
+
const ids = [
|
|
259
|
+
ariaProps["aria-describedby"],
|
|
260
|
+
local.description ? descriptionId : void 0,
|
|
261
|
+
isInvalid() && local.errorMessage ? errorMessageId : void 0
|
|
262
|
+
].filter(Boolean);
|
|
263
|
+
return ids.length ? ids.join(" ") : void 0;
|
|
264
|
+
};
|
|
265
|
+
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
266
|
+
const { isHovered, hoverProps } = createHover({
|
|
267
|
+
get isDisabled() {
|
|
268
|
+
return isDisabled() || isReadOnly();
|
|
269
|
+
},
|
|
270
|
+
onHoverStart: local.onHoverStart,
|
|
271
|
+
onHoverEnd: local.onHoverEnd,
|
|
272
|
+
onHoverChange: local.onHoverChange
|
|
273
|
+
});
|
|
274
|
+
const renderValues = createMemo(() => ({
|
|
275
|
+
isSelected: isSelected(),
|
|
276
|
+
isIndeterminate: local.isIndeterminate ?? false,
|
|
277
|
+
isHovered: isHovered(),
|
|
278
|
+
isPressed: isPressed(),
|
|
279
|
+
isFocused: isFocused(),
|
|
280
|
+
isFocusVisible: isFocusVisible(),
|
|
281
|
+
isDisabled: isDisabled(),
|
|
282
|
+
isReadOnly: isReadOnly(),
|
|
283
|
+
isInvalid: isInvalid(),
|
|
284
|
+
isRequired: ariaProps.isRequired ?? false
|
|
285
|
+
}));
|
|
286
|
+
const renderProps = useRenderProps({
|
|
287
|
+
children: mergedProps.children,
|
|
288
|
+
class: local.class,
|
|
289
|
+
style: local.style,
|
|
290
|
+
defaultClassName: "solidaria-Checkbox"
|
|
291
|
+
}, renderValues);
|
|
292
|
+
const childRenderValues = {
|
|
293
|
+
get isSelected() {
|
|
294
|
+
return isSelected();
|
|
295
|
+
},
|
|
296
|
+
get isIndeterminate() {
|
|
297
|
+
return local.isIndeterminate ?? false;
|
|
298
|
+
},
|
|
299
|
+
get isHovered() {
|
|
300
|
+
return isHovered();
|
|
301
|
+
},
|
|
302
|
+
get isPressed() {
|
|
303
|
+
return isPressed();
|
|
304
|
+
},
|
|
305
|
+
get isFocused() {
|
|
306
|
+
return isFocused();
|
|
307
|
+
},
|
|
308
|
+
get isFocusVisible() {
|
|
309
|
+
return isFocusVisible();
|
|
310
|
+
},
|
|
311
|
+
get isDisabled() {
|
|
312
|
+
return isDisabled();
|
|
313
|
+
},
|
|
314
|
+
get isReadOnly() {
|
|
315
|
+
return isReadOnly();
|
|
316
|
+
},
|
|
317
|
+
get isInvalid() {
|
|
318
|
+
return isInvalid();
|
|
319
|
+
},
|
|
320
|
+
get isRequired() {
|
|
321
|
+
return ariaProps.isRequired ?? false;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const checkboxChildren = () => {
|
|
325
|
+
const children = mergedProps.children;
|
|
326
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
327
|
+
};
|
|
328
|
+
const domProps = createMemo(() => {
|
|
329
|
+
const filtered = filterDOMProps(ariaProps, { global: true });
|
|
330
|
+
delete filtered.id;
|
|
331
|
+
delete filtered.onClick;
|
|
332
|
+
return filtered;
|
|
333
|
+
});
|
|
334
|
+
const cleanLabelProps = () => {
|
|
335
|
+
const { ref: _ref1, ...rest } = labelProps;
|
|
336
|
+
return rest;
|
|
337
|
+
};
|
|
338
|
+
const cleanHoverProps = () => {
|
|
339
|
+
const { ref: _ref2, ...rest } = hoverProps;
|
|
340
|
+
return rest;
|
|
341
|
+
};
|
|
342
|
+
const cleanInputProps = () => {
|
|
343
|
+
const { ref: _ref3, onFocus: _onFocus, onBlur: _onBlur, ...rest } = inputProps();
|
|
344
|
+
return rest;
|
|
345
|
+
};
|
|
346
|
+
const cleanFocusProps = () => {
|
|
347
|
+
const { ref: _ref4, onFocus: _onFocus, onBlur: _onBlur, ...rest } = focusProps;
|
|
348
|
+
return rest;
|
|
349
|
+
};
|
|
350
|
+
const handleInputFocus = (event) => {
|
|
351
|
+
inputProps().onFocus?.(event);
|
|
352
|
+
focusProps.onFocus?.(event);
|
|
353
|
+
};
|
|
354
|
+
const handleInputBlur = (event) => {
|
|
355
|
+
inputProps().onBlur?.(event);
|
|
356
|
+
focusProps.onBlur?.(event);
|
|
357
|
+
};
|
|
358
|
+
const setLabelRef = (el) => {
|
|
359
|
+
assignRef(local.ref, el);
|
|
360
|
+
};
|
|
361
|
+
const setInputRef = (el) => {
|
|
362
|
+
setInputElement(el);
|
|
363
|
+
for (const ref of inputRefs()) assignRef(ref, el);
|
|
364
|
+
};
|
|
365
|
+
const hiddenInput = <VisuallyHidden>
|
|
366
|
+
<input ref={setInputRef} {...cleanInputProps()} {...cleanFocusProps()} onFocus={handleInputFocus} onBlur={handleInputBlur} aria-describedby={describedBy()} />
|
|
367
|
+
</VisuallyHidden>;
|
|
368
|
+
const labelChildren = () => <>
|
|
369
|
+
{hiddenInput}
|
|
370
|
+
{checkboxChildren()}
|
|
371
|
+
<Show when={local.description}>
|
|
372
|
+
<span id={descriptionId} slot="description">
|
|
373
|
+
{local.description}
|
|
374
|
+
</span>
|
|
375
|
+
</Show>
|
|
376
|
+
<Show when={isInvalid() && local.errorMessage}>
|
|
377
|
+
<span id={errorMessageId} slot="errorMessage">
|
|
378
|
+
{local.errorMessage}
|
|
379
|
+
</span>
|
|
380
|
+
</Show>
|
|
381
|
+
</>;
|
|
382
|
+
const rootProps = createMemo(() => ({
|
|
383
|
+
...domProps(),
|
|
384
|
+
...cleanLabelProps(),
|
|
385
|
+
...cleanHoverProps(),
|
|
386
|
+
class: renderProps.class(),
|
|
387
|
+
style: renderProps.style(),
|
|
388
|
+
slot: local.slot,
|
|
389
|
+
"data-selected": isSelected() || void 0,
|
|
390
|
+
"data-indeterminate": local.isIndeterminate || void 0,
|
|
391
|
+
"data-pressed": isPressed() || void 0,
|
|
392
|
+
"data-hovered": isHovered() || void 0,
|
|
393
|
+
"data-focused": isFocused() || void 0,
|
|
394
|
+
"data-focus-visible": isFocusVisible() || void 0,
|
|
395
|
+
"data-disabled": isDisabled() || void 0,
|
|
396
|
+
"data-readonly": isReadOnly() || void 0,
|
|
397
|
+
"data-invalid": isInvalid() || void 0,
|
|
398
|
+
"data-required": ariaProps.isRequired || void 0
|
|
399
|
+
}));
|
|
400
|
+
const customRootProps = () => ({
|
|
401
|
+
...rootProps(),
|
|
402
|
+
ref: setLabelRef,
|
|
403
|
+
children: labelChildren()
|
|
404
|
+
});
|
|
405
|
+
return local.render ? local.render(customRootProps(), renderValues()) : <label {...domProps()} {...cleanLabelProps()} {...cleanHoverProps()} ref={setLabelRef} class={renderProps.class()} style={renderProps.style()} slot={local.slot} data-selected={isSelected() || void 0} data-indeterminate={local.isIndeterminate || void 0} data-pressed={isPressed() || void 0} data-hovered={isHovered() || void 0} data-focused={isFocused() || void 0} data-focus-visible={isFocusVisible() || void 0} data-disabled={isDisabled() || void 0} data-readonly={isReadOnly() || void 0} data-invalid={isInvalid() || void 0} data-required={ariaProps.isRequired || void 0}>
|
|
406
|
+
{labelChildren()}
|
|
407
|
+
</label>;
|
|
408
|
+
}
|
|
409
|
+
const CheckboxFieldContext = createContext(null);
|
|
410
|
+
const InternalCheckboxContext = createContext(null);
|
|
411
|
+
/**
|
|
412
|
+
* A checkbox allows a user to select an item, with support for validation and help text.
|
|
413
|
+
* Wraps a `CheckboxButton` and provides description/error wiring.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```tsx
|
|
417
|
+
* <CheckboxField>
|
|
418
|
+
* <CheckboxButton>Accept terms</CheckboxButton>
|
|
419
|
+
* <Text slot="description">Required to continue</Text>
|
|
420
|
+
* </CheckboxField>
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
function CheckboxField(props) {
|
|
424
|
+
const [inputElement, setInputElement] = createSignal(null);
|
|
425
|
+
const formContext = useContext(FormContext);
|
|
426
|
+
const contextProps = useContext(CheckboxFieldContext);
|
|
427
|
+
const contextSlotProps = contextProps?.slots?.[props.slot ?? "default"];
|
|
428
|
+
const contextBaseProps = createMemo(() => {
|
|
429
|
+
if (!contextProps) return {};
|
|
430
|
+
const { slots: _slots, ...rest } = contextProps;
|
|
431
|
+
return rest;
|
|
432
|
+
});
|
|
433
|
+
const mergedProps = contextProps ? mergeProps$1(contextBaseProps(), contextSlotProps ?? {}, props) : props;
|
|
434
|
+
const propsWithFormBehavior = withFormValidationBehavior(mergedProps, formContext);
|
|
435
|
+
const inputRefs = createMemo(() => [
|
|
436
|
+
contextBaseProps().inputRef,
|
|
437
|
+
contextSlotProps?.inputRef,
|
|
438
|
+
props.inputRef
|
|
439
|
+
].filter(Boolean));
|
|
440
|
+
const [local, ariaProps] = splitProps(propsWithFormBehavior, [
|
|
441
|
+
"class",
|
|
442
|
+
"style",
|
|
443
|
+
"ref",
|
|
444
|
+
"inputRef",
|
|
445
|
+
"slot",
|
|
446
|
+
"isIndeterminate",
|
|
447
|
+
"children"
|
|
448
|
+
]);
|
|
449
|
+
const inputAriaProps = createMemo(() => {
|
|
450
|
+
const clean = {};
|
|
451
|
+
for (const key in ariaProps) if (!key.startsWith("data-")) clean[key] = ariaProps[key];
|
|
452
|
+
return clean;
|
|
453
|
+
});
|
|
454
|
+
const groupState = useContext(CheckboxGroupStateContext);
|
|
455
|
+
let isSelected;
|
|
456
|
+
let isPressed;
|
|
457
|
+
let labelProps;
|
|
458
|
+
let inputProps;
|
|
459
|
+
let getDescriptionProps;
|
|
460
|
+
let getErrorMessageProps;
|
|
461
|
+
if (groupState) {
|
|
462
|
+
const itemAria = createCheckboxGroupItem(() => ({
|
|
463
|
+
...inputAriaProps(),
|
|
464
|
+
value: inputAriaProps().value ?? "",
|
|
465
|
+
children: true
|
|
466
|
+
}), groupState, inputElement);
|
|
467
|
+
isSelected = itemAria.isSelected;
|
|
468
|
+
isPressed = itemAria.isPressed;
|
|
469
|
+
labelProps = itemAria.labelProps;
|
|
470
|
+
inputProps = () => itemAria.inputProps;
|
|
471
|
+
getDescriptionProps = () => itemAria.descriptionProps;
|
|
472
|
+
getErrorMessageProps = () => itemAria.errorMessageProps;
|
|
473
|
+
} else {
|
|
474
|
+
const checkboxAria = createCheckbox(() => ({
|
|
475
|
+
...inputAriaProps(),
|
|
476
|
+
isIndeterminate: local.isIndeterminate,
|
|
477
|
+
children: true
|
|
478
|
+
}), createToggleState(() => ({
|
|
479
|
+
isSelected: ariaProps.isSelected,
|
|
480
|
+
defaultSelected: ariaProps.defaultSelected,
|
|
481
|
+
onChange: ariaProps.onChange,
|
|
482
|
+
isReadOnly: ariaProps.isReadOnly
|
|
483
|
+
})), inputElement);
|
|
484
|
+
isSelected = checkboxAria.isSelected;
|
|
485
|
+
isPressed = checkboxAria.isPressed;
|
|
486
|
+
labelProps = checkboxAria.labelProps;
|
|
487
|
+
inputProps = () => checkboxAria.inputProps;
|
|
488
|
+
getDescriptionProps = () => checkboxAria.descriptionProps;
|
|
489
|
+
getErrorMessageProps = () => checkboxAria.errorMessageProps;
|
|
490
|
+
}
|
|
491
|
+
const isDisabled = () => inputProps().disabled === true;
|
|
492
|
+
const isReadOnly = () => inputProps()["aria-readonly"] === true;
|
|
493
|
+
const isInvalid = () => inputProps()["aria-invalid"] === true;
|
|
494
|
+
const isIndeterminate = () => local.isIndeterminate ?? false;
|
|
495
|
+
const isRequired = () => ariaProps.isRequired ?? false;
|
|
496
|
+
const setInputRef = (el) => {
|
|
497
|
+
setInputElement(el);
|
|
498
|
+
for (const ref of inputRefs()) assignRef(ref, el);
|
|
499
|
+
};
|
|
500
|
+
const setFieldRef = (el) => {
|
|
501
|
+
assignRef(local.ref, el);
|
|
502
|
+
};
|
|
503
|
+
const internalContext = {
|
|
504
|
+
isSelected,
|
|
505
|
+
isPressed,
|
|
506
|
+
isDisabled,
|
|
507
|
+
isReadOnly,
|
|
508
|
+
isInvalid,
|
|
509
|
+
isIndeterminate,
|
|
510
|
+
isRequired,
|
|
511
|
+
labelProps: () => labelProps,
|
|
512
|
+
inputProps,
|
|
513
|
+
setInputRef,
|
|
514
|
+
defaultClassName: "solidaria-CheckboxButton"
|
|
515
|
+
};
|
|
516
|
+
const textSlots = { slots: {
|
|
517
|
+
get description() {
|
|
518
|
+
return getDescriptionProps();
|
|
519
|
+
},
|
|
520
|
+
get errorMessage() {
|
|
521
|
+
return getErrorMessageProps();
|
|
522
|
+
}
|
|
523
|
+
} };
|
|
524
|
+
const renderValues = createMemo(() => ({
|
|
525
|
+
isSelected: isSelected(),
|
|
526
|
+
isIndeterminate: isIndeterminate(),
|
|
527
|
+
isDisabled: isDisabled(),
|
|
528
|
+
isReadOnly: isReadOnly(),
|
|
529
|
+
isInvalid: isInvalid(),
|
|
530
|
+
isRequired: isRequired()
|
|
531
|
+
}));
|
|
532
|
+
const renderProps = useRenderProps({
|
|
533
|
+
children: mergedProps.children,
|
|
534
|
+
class: local.class,
|
|
535
|
+
style: local.style,
|
|
536
|
+
defaultClassName: "solidaria-CheckboxField"
|
|
537
|
+
}, renderValues);
|
|
538
|
+
const fieldErrorContext = groupState ? null : {
|
|
539
|
+
get validation() {
|
|
540
|
+
return {
|
|
541
|
+
isInvalid: isInvalid(),
|
|
542
|
+
validationDetails: VALID_VALIDITY_STATE,
|
|
543
|
+
validationErrors: []
|
|
544
|
+
};
|
|
545
|
+
},
|
|
546
|
+
get errorMessageProps() {
|
|
547
|
+
return getErrorMessageProps();
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
const domProps = createMemo(() => {
|
|
551
|
+
const filtered = filterDOMProps(ariaProps, { global: true });
|
|
552
|
+
delete filtered.id;
|
|
553
|
+
delete filtered.onClick;
|
|
554
|
+
return filtered;
|
|
555
|
+
});
|
|
556
|
+
const FieldChildren = () => {
|
|
557
|
+
const childRenderValues = {
|
|
558
|
+
get isSelected() {
|
|
559
|
+
return isSelected();
|
|
560
|
+
},
|
|
561
|
+
get isIndeterminate() {
|
|
562
|
+
return isIndeterminate();
|
|
563
|
+
},
|
|
564
|
+
get isDisabled() {
|
|
565
|
+
return isDisabled();
|
|
566
|
+
},
|
|
567
|
+
get isReadOnly() {
|
|
568
|
+
return isReadOnly();
|
|
569
|
+
},
|
|
570
|
+
get isInvalid() {
|
|
571
|
+
return isInvalid();
|
|
572
|
+
},
|
|
573
|
+
get isRequired() {
|
|
574
|
+
return isRequired();
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
const renderedChildren = createMemo(() => {
|
|
578
|
+
const children = mergedProps.children;
|
|
579
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
580
|
+
});
|
|
581
|
+
return <>{renderedChildren()}</>;
|
|
582
|
+
};
|
|
583
|
+
return <div {...domProps()} ref={setFieldRef} class={renderProps.class()} style={renderProps.style()} slot={local.slot} data-selected={isSelected() || void 0} data-indeterminate={isIndeterminate() || void 0} data-disabled={isDisabled() || void 0} data-readonly={isReadOnly() || void 0} data-invalid={isInvalid() || void 0} data-required={isRequired() || void 0}>
|
|
584
|
+
<InternalCheckboxContext.Provider value={internalContext}>
|
|
585
|
+
<Provider values={[[TextContext, textSlots]]}>
|
|
586
|
+
<Show when={fieldErrorContext} fallback={<FieldChildren />} keyed>
|
|
587
|
+
{(ctx) => <FieldErrorContext.Provider value={ctx}>
|
|
588
|
+
<FieldChildren />
|
|
589
|
+
</FieldErrorContext.Provider>}
|
|
590
|
+
</Show>
|
|
591
|
+
</Provider>
|
|
592
|
+
</InternalCheckboxContext.Provider>
|
|
593
|
+
</div>;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* A checkbox button is the clickable area of a checkbox, including the indicator and label.
|
|
597
|
+
* Must be rendered inside a `CheckboxField` (or the legacy `Checkbox`).
|
|
598
|
+
*/
|
|
599
|
+
function CheckboxButton(props) {
|
|
600
|
+
const getCtx = createMemo(() => useContext(InternalCheckboxContext));
|
|
601
|
+
return <Show when={getCtx()} fallback={null} keyed>
|
|
602
|
+
{(ctx) => <CheckboxButtonImpl buttonProps={props} ctx={ctx} />}
|
|
603
|
+
</Show>;
|
|
604
|
+
}
|
|
605
|
+
function CheckboxButtonImpl(props) {
|
|
606
|
+
const { ctx } = props;
|
|
607
|
+
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
608
|
+
const { isHovered, hoverProps } = createHover({
|
|
609
|
+
get isDisabled() {
|
|
610
|
+
return ctx.isDisabled() || ctx.isReadOnly();
|
|
611
|
+
},
|
|
612
|
+
onHoverStart: props.buttonProps.onHoverStart,
|
|
613
|
+
onHoverEnd: props.buttonProps.onHoverEnd,
|
|
614
|
+
onHoverChange: props.buttonProps.onHoverChange
|
|
615
|
+
});
|
|
616
|
+
const renderValues = createMemo(() => ({
|
|
617
|
+
isSelected: ctx.isSelected(),
|
|
618
|
+
isIndeterminate: ctx.isIndeterminate(),
|
|
619
|
+
isHovered: isHovered(),
|
|
620
|
+
isPressed: ctx.isPressed(),
|
|
621
|
+
isFocused: isFocused(),
|
|
622
|
+
isFocusVisible: isFocusVisible(),
|
|
623
|
+
isDisabled: ctx.isDisabled(),
|
|
624
|
+
isReadOnly: ctx.isReadOnly(),
|
|
625
|
+
isInvalid: ctx.isInvalid(),
|
|
626
|
+
isRequired: ctx.isRequired()
|
|
627
|
+
}));
|
|
628
|
+
const renderProps = useRenderProps({
|
|
629
|
+
children: props.buttonProps.children,
|
|
630
|
+
class: props.buttonProps.class,
|
|
631
|
+
style: props.buttonProps.style,
|
|
632
|
+
defaultClassName: ctx.defaultClassName
|
|
633
|
+
}, renderValues);
|
|
634
|
+
const childRenderValues = {
|
|
635
|
+
get isSelected() {
|
|
636
|
+
return ctx.isSelected();
|
|
637
|
+
},
|
|
638
|
+
get isIndeterminate() {
|
|
639
|
+
return ctx.isIndeterminate();
|
|
640
|
+
},
|
|
641
|
+
get isHovered() {
|
|
642
|
+
return isHovered();
|
|
643
|
+
},
|
|
644
|
+
get isPressed() {
|
|
645
|
+
return ctx.isPressed();
|
|
646
|
+
},
|
|
647
|
+
get isFocused() {
|
|
648
|
+
return isFocused();
|
|
649
|
+
},
|
|
650
|
+
get isFocusVisible() {
|
|
651
|
+
return isFocusVisible();
|
|
652
|
+
},
|
|
653
|
+
get isDisabled() {
|
|
654
|
+
return ctx.isDisabled();
|
|
655
|
+
},
|
|
656
|
+
get isReadOnly() {
|
|
657
|
+
return ctx.isReadOnly();
|
|
658
|
+
},
|
|
659
|
+
get isInvalid() {
|
|
660
|
+
return ctx.isInvalid();
|
|
661
|
+
},
|
|
662
|
+
get isRequired() {
|
|
663
|
+
return ctx.isRequired();
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
const cleanLabelProps = () => {
|
|
667
|
+
const { ref: _ref1, ...rest } = ctx.labelProps();
|
|
668
|
+
return rest;
|
|
669
|
+
};
|
|
670
|
+
const cleanHoverProps = () => {
|
|
671
|
+
const { ref: _ref2, ...rest } = hoverProps;
|
|
672
|
+
return rest;
|
|
673
|
+
};
|
|
674
|
+
const cleanInputProps = () => {
|
|
675
|
+
const { ref: _ref3, onFocus: _onFocus, onBlur: _onBlur, ...rest } = ctx.inputProps();
|
|
676
|
+
return rest;
|
|
677
|
+
};
|
|
678
|
+
const cleanFocusProps = () => {
|
|
679
|
+
const { ref: _ref4, onFocus: _onFocus, onBlur: _onBlur, ...rest } = focusProps;
|
|
680
|
+
return rest;
|
|
681
|
+
};
|
|
682
|
+
const handleInputFocus = (event) => {
|
|
683
|
+
ctx.inputProps().onFocus?.(event);
|
|
684
|
+
focusProps.onFocus?.(event);
|
|
685
|
+
};
|
|
686
|
+
const handleInputBlur = (event) => {
|
|
687
|
+
ctx.inputProps().onBlur?.(event);
|
|
688
|
+
focusProps.onBlur?.(event);
|
|
689
|
+
};
|
|
690
|
+
const setButtonRef = (el) => {
|
|
691
|
+
assignRef(props.buttonProps.ref, el);
|
|
692
|
+
};
|
|
693
|
+
const buttonChildren = () => {
|
|
694
|
+
const children = props.buttonProps.children;
|
|
695
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
696
|
+
};
|
|
697
|
+
return <label {...cleanLabelProps()} {...cleanHoverProps()} ref={setButtonRef} class={renderProps.class()} style={renderProps.style()} slot={props.buttonProps.slot} data-selected={ctx.isSelected() || void 0} data-indeterminate={ctx.isIndeterminate() || void 0} data-pressed={ctx.isPressed() || void 0} data-hovered={isHovered() || void 0} data-focused={isFocused() || void 0} data-focus-visible={isFocusVisible() || void 0} data-disabled={ctx.isDisabled() || void 0} data-readonly={ctx.isReadOnly() || void 0} data-invalid={ctx.isInvalid() || void 0} data-required={ctx.isRequired() || void 0}>
|
|
698
|
+
<VisuallyHidden>
|
|
699
|
+
<input ref={ctx.setInputRef} {...cleanInputProps()} {...cleanFocusProps()} onFocus={handleInputFocus} onBlur={handleInputBlur} />
|
|
700
|
+
</VisuallyHidden>
|
|
701
|
+
{buttonChildren()}
|
|
702
|
+
</label>;
|
|
703
|
+
}
|
|
704
|
+
//#endregion
|
|
705
|
+
export { Checkbox, CheckboxButton, CheckboxContext, CheckboxField, CheckboxFieldContext, CheckboxGroup, CheckboxGroupContext, CheckboxGroupStateContext };
|
|
706
|
+
|
|
707
|
+
//# sourceMappingURL=Checkbox.jsx.map
|