@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
package/dist/Checkbox.js
ADDED
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
import { Provider, filterDOMProps, useRenderProps } from "./utils.js";
|
|
2
|
+
import { VisuallyHidden } from "./VisuallyHidden.js";
|
|
3
|
+
import { FieldErrorContext } from "./FieldError.js";
|
|
4
|
+
import { TextContext } from "./Text.js";
|
|
5
|
+
import { FormContext } from "./Form.js";
|
|
6
|
+
import { createComponent, getNextElement, getNextMarker, insert, memo, mergeProps, runHydrationEvents, setAttribute, spread, template, use } from "solid-js/web";
|
|
7
|
+
import { Show, createContext, createMemo, createSignal, createUniqueId, splitProps, useContext } from "solid-js";
|
|
8
|
+
import { createCheckbox, createCheckboxGroup, createCheckboxGroupItem, createFocusRing, createHover, mergeProps as mergeProps$2 } from "@proyecto-viviana/solidaria";
|
|
9
|
+
import { VALID_VALIDITY_STATE, createCheckboxGroupState, createToggleState } from "@proyecto-viviana/solid-stately";
|
|
10
|
+
//#region src/Checkbox.tsx
|
|
11
|
+
/**
|
|
12
|
+
* Checkbox and CheckboxGroup components for solidaria-components
|
|
13
|
+
*
|
|
14
|
+
* Pre-wired headless checkbox components that combine state + aria hooks.
|
|
15
|
+
* Port of react-aria-components/src/Checkbox.tsx
|
|
16
|
+
*/
|
|
17
|
+
var _tmpl$ = /*#__PURE__*/ template(`<div>`), _tmpl$2 = /*#__PURE__*/ template(`<div><!$><!/><!$><!/><!$><!/>`), _tmpl$3 = /*#__PURE__*/ template(`<input>`), _tmpl$4 = /*#__PURE__*/ template(`<span slot=description>`), _tmpl$5 = /*#__PURE__*/ template(`<span slot=errorMessage>`), _tmpl$6 = /*#__PURE__*/ template(`<label>`), _tmpl$7 = /*#__PURE__*/ template(`<label><!$><!/><!$><!/>`);
|
|
18
|
+
function assignRef(ref, el) {
|
|
19
|
+
if (!ref) return;
|
|
20
|
+
if (typeof ref === "function") ref(el);
|
|
21
|
+
else ref.current = el;
|
|
22
|
+
}
|
|
23
|
+
const CheckboxGroupContext = createContext(null);
|
|
24
|
+
const CheckboxGroupStateContext = createContext(null);
|
|
25
|
+
const CheckboxContext = createContext(null);
|
|
26
|
+
function withFormValidationBehavior(props, formContext) {
|
|
27
|
+
if (!formContext?.validationBehavior) return props;
|
|
28
|
+
return new Proxy(props, {
|
|
29
|
+
get(target, property, receiver) {
|
|
30
|
+
const localValue = Reflect.get(target, property, receiver);
|
|
31
|
+
if (property === "validationBehavior" && localValue === void 0) return formContext.validationBehavior;
|
|
32
|
+
return localValue;
|
|
33
|
+
},
|
|
34
|
+
has(target, property) {
|
|
35
|
+
return Reflect.has(target, property) || property === "validationBehavior" && formContext.validationBehavior !== void 0;
|
|
36
|
+
},
|
|
37
|
+
ownKeys(target) {
|
|
38
|
+
const keys = new Set(Reflect.ownKeys(target));
|
|
39
|
+
if (formContext.validationBehavior !== void 0) keys.add("validationBehavior");
|
|
40
|
+
return Array.from(keys);
|
|
41
|
+
},
|
|
42
|
+
getOwnPropertyDescriptor(target, property) {
|
|
43
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
44
|
+
if (descriptor) return descriptor;
|
|
45
|
+
if (property === "validationBehavior" && formContext.validationBehavior !== void 0) return {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
get: () => formContext.validationBehavior
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A checkbox group allows a user to select multiple items from a list of options.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* <CheckboxGroup>
|
|
59
|
+
* <Checkbox value="one">Option 1</Checkbox>
|
|
60
|
+
* <Checkbox value="two">Option 2</Checkbox>
|
|
61
|
+
* </CheckboxGroup>
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function CheckboxGroup(props) {
|
|
65
|
+
const [local, ariaProps] = splitProps(withFormValidationBehavior(props, useContext(FormContext)), [
|
|
66
|
+
"class",
|
|
67
|
+
"style",
|
|
68
|
+
"slot",
|
|
69
|
+
"ref",
|
|
70
|
+
"description",
|
|
71
|
+
"errorMessage",
|
|
72
|
+
"renderHelpText",
|
|
73
|
+
"children"
|
|
74
|
+
]);
|
|
75
|
+
const state = createCheckboxGroupState(() => ({
|
|
76
|
+
value: ariaProps.value,
|
|
77
|
+
defaultValue: ariaProps.defaultValue,
|
|
78
|
+
onChange: ariaProps.onChange,
|
|
79
|
+
isDisabled: ariaProps.isDisabled,
|
|
80
|
+
isReadOnly: ariaProps.isReadOnly,
|
|
81
|
+
isRequired: ariaProps.isRequired,
|
|
82
|
+
isInvalid: ariaProps.isInvalid,
|
|
83
|
+
validationState: ariaProps.validationState,
|
|
84
|
+
validate: ariaProps.validate,
|
|
85
|
+
validationBehavior: ariaProps.validationBehavior,
|
|
86
|
+
name: ariaProps.name
|
|
87
|
+
}));
|
|
88
|
+
const groupAria = createCheckboxGroup(() => ({
|
|
89
|
+
...ariaProps,
|
|
90
|
+
description: local.description,
|
|
91
|
+
errorMessage: local.errorMessage
|
|
92
|
+
}), state);
|
|
93
|
+
const renderValues = createMemo(() => ({
|
|
94
|
+
isDisabled: state.isDisabled,
|
|
95
|
+
isReadOnly: state.isReadOnly,
|
|
96
|
+
isRequired: ariaProps.isRequired ?? false,
|
|
97
|
+
isInvalid: groupAria.isInvalid,
|
|
98
|
+
state
|
|
99
|
+
}));
|
|
100
|
+
const renderProps = useRenderProps({
|
|
101
|
+
get children() {
|
|
102
|
+
return local.children;
|
|
103
|
+
},
|
|
104
|
+
class: local.class,
|
|
105
|
+
style: local.style,
|
|
106
|
+
defaultClassName: "solidaria-CheckboxGroup"
|
|
107
|
+
}, renderValues);
|
|
108
|
+
const domProps = createMemo(() => filterDOMProps(ariaProps, { global: true }));
|
|
109
|
+
const cleanGroupProps = () => {
|
|
110
|
+
const { ref: _ref, ...rest } = groupAria.groupProps;
|
|
111
|
+
return rest;
|
|
112
|
+
};
|
|
113
|
+
const setGroupRef = (el) => {
|
|
114
|
+
assignRef(local.ref, el);
|
|
115
|
+
};
|
|
116
|
+
const groupDescribedBy = () => {
|
|
117
|
+
const ids = [
|
|
118
|
+
cleanGroupProps()["aria-describedby"],
|
|
119
|
+
local.description ? groupAria.descriptionProps.id : void 0,
|
|
120
|
+
groupAria.isInvalid && local.errorMessage ? groupAria.errorMessageProps.id : void 0
|
|
121
|
+
].filter(Boolean).join(" ").split(" ").filter(Boolean);
|
|
122
|
+
return ids.length ? Array.from(new Set(ids)).join(" ") : void 0;
|
|
123
|
+
};
|
|
124
|
+
const GroupChildren = () => {
|
|
125
|
+
const childRenderValues = {
|
|
126
|
+
get isDisabled() {
|
|
127
|
+
return state.isDisabled;
|
|
128
|
+
},
|
|
129
|
+
get isReadOnly() {
|
|
130
|
+
return state.isReadOnly;
|
|
131
|
+
},
|
|
132
|
+
get isRequired() {
|
|
133
|
+
return state.isRequired();
|
|
134
|
+
},
|
|
135
|
+
get isInvalid() {
|
|
136
|
+
return groupAria.isInvalid;
|
|
137
|
+
},
|
|
138
|
+
get state() {
|
|
139
|
+
return state;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return memo(createMemo(() => {
|
|
143
|
+
const children = local.children;
|
|
144
|
+
if (typeof children === "function") return children.length > 0 ? children(childRenderValues) : children();
|
|
145
|
+
return children;
|
|
146
|
+
}));
|
|
147
|
+
};
|
|
148
|
+
return createComponent(CheckboxGroupStateContext.Provider, {
|
|
149
|
+
value: state,
|
|
150
|
+
get children() {
|
|
151
|
+
var _el$ = getNextElement(_tmpl$2), _el$4 = _el$.firstChild, [_el$5, _co$] = getNextMarker(_el$4.nextSibling), _el$6 = _el$5.nextSibling, [_el$7, _co$2] = getNextMarker(_el$6.nextSibling), _el$8 = _el$7.nextSibling, [_el$9, _co$3] = getNextMarker(_el$8.nextSibling);
|
|
152
|
+
use(setGroupRef, _el$);
|
|
153
|
+
spread(_el$, mergeProps(domProps, cleanGroupProps, {
|
|
154
|
+
get ["aria-describedby"]() {
|
|
155
|
+
return groupDescribedBy();
|
|
156
|
+
},
|
|
157
|
+
get ["class"]() {
|
|
158
|
+
return renderProps.class();
|
|
159
|
+
},
|
|
160
|
+
get style() {
|
|
161
|
+
return renderProps.style();
|
|
162
|
+
},
|
|
163
|
+
get ["data-disabled"]() {
|
|
164
|
+
return state.isDisabled || void 0;
|
|
165
|
+
},
|
|
166
|
+
get ["data-readonly"]() {
|
|
167
|
+
return state.isReadOnly || void 0;
|
|
168
|
+
},
|
|
169
|
+
get ["data-required"]() {
|
|
170
|
+
return ariaProps.isRequired || void 0;
|
|
171
|
+
},
|
|
172
|
+
get ["data-invalid"]() {
|
|
173
|
+
return groupAria.isInvalid || void 0;
|
|
174
|
+
}
|
|
175
|
+
}), false, true);
|
|
176
|
+
insert(_el$, createComponent(GroupChildren, {}), _el$5, _co$);
|
|
177
|
+
insert(_el$, createComponent(Show, {
|
|
178
|
+
get when() {
|
|
179
|
+
return memo(() => !!(local.renderHelpText ?? true))() && local.description;
|
|
180
|
+
},
|
|
181
|
+
get children() {
|
|
182
|
+
var _el$2 = getNextElement(_tmpl$);
|
|
183
|
+
spread(_el$2, mergeProps(() => groupAria.descriptionProps), false, true);
|
|
184
|
+
insert(_el$2, () => local.description);
|
|
185
|
+
runHydrationEvents();
|
|
186
|
+
return _el$2;
|
|
187
|
+
}
|
|
188
|
+
}), _el$7, _co$2);
|
|
189
|
+
insert(_el$, createComponent(Show, {
|
|
190
|
+
get when() {
|
|
191
|
+
return memo(() => !!((local.renderHelpText ?? true) && groupAria.isInvalid))() && local.errorMessage;
|
|
192
|
+
},
|
|
193
|
+
get children() {
|
|
194
|
+
var _el$3 = getNextElement(_tmpl$);
|
|
195
|
+
spread(_el$3, mergeProps(() => groupAria.errorMessageProps), false, true);
|
|
196
|
+
insert(_el$3, () => local.errorMessage);
|
|
197
|
+
runHydrationEvents();
|
|
198
|
+
return _el$3;
|
|
199
|
+
}
|
|
200
|
+
}), _el$9, _co$3);
|
|
201
|
+
runHydrationEvents();
|
|
202
|
+
return _el$;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* A checkbox allows a user to select multiple items from a list of individual items,
|
|
208
|
+
* or to mark one individual item as selected.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```tsx
|
|
212
|
+
* <Checkbox>
|
|
213
|
+
* {({ isSelected }) => (
|
|
214
|
+
* <>
|
|
215
|
+
* <span class={`checkbox ${isSelected ? 'checked' : ''}`}>
|
|
216
|
+
* {isSelected && '✓'}
|
|
217
|
+
* </span>
|
|
218
|
+
* <span>Accept terms</span>
|
|
219
|
+
* </>
|
|
220
|
+
* )}
|
|
221
|
+
* </Checkbox>
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
function Checkbox(props) {
|
|
225
|
+
const [inputElement, setInputElement] = createSignal(null);
|
|
226
|
+
const formContext = useContext(FormContext);
|
|
227
|
+
const contextProps = useContext(CheckboxContext);
|
|
228
|
+
const contextSlotProps = contextProps?.slots?.[props.slot ?? "default"];
|
|
229
|
+
const contextBaseProps = createMemo(() => {
|
|
230
|
+
if (!contextProps) return {};
|
|
231
|
+
const { slots: _slots, ...rest } = contextProps;
|
|
232
|
+
return rest;
|
|
233
|
+
});
|
|
234
|
+
const mergedProps = contextProps ? mergeProps$2(contextBaseProps(), contextSlotProps ?? {}, props) : props;
|
|
235
|
+
const propsWithFormBehavior = withFormValidationBehavior(mergedProps, formContext);
|
|
236
|
+
const inputRefs = createMemo(() => [
|
|
237
|
+
contextBaseProps().inputRef,
|
|
238
|
+
contextSlotProps?.inputRef,
|
|
239
|
+
props.inputRef
|
|
240
|
+
].filter(Boolean));
|
|
241
|
+
const [local, ariaProps] = splitProps(propsWithFormBehavior, [
|
|
242
|
+
"class",
|
|
243
|
+
"style",
|
|
244
|
+
"render",
|
|
245
|
+
"ref",
|
|
246
|
+
"inputRef",
|
|
247
|
+
"slot",
|
|
248
|
+
"isIndeterminate",
|
|
249
|
+
"description",
|
|
250
|
+
"errorMessage",
|
|
251
|
+
"onHoverStart",
|
|
252
|
+
"onHoverEnd",
|
|
253
|
+
"onHoverChange"
|
|
254
|
+
]);
|
|
255
|
+
const descriptionId = createUniqueId();
|
|
256
|
+
const errorMessageId = createUniqueId();
|
|
257
|
+
const inputAriaProps = createMemo(() => {
|
|
258
|
+
const clean = {};
|
|
259
|
+
for (const key in ariaProps) if (!key.startsWith("data-")) clean[key] = ariaProps[key];
|
|
260
|
+
return clean;
|
|
261
|
+
});
|
|
262
|
+
const groupState = useContext(CheckboxGroupStateContext);
|
|
263
|
+
let isSelected;
|
|
264
|
+
let isPressed;
|
|
265
|
+
let isDisabled;
|
|
266
|
+
let isReadOnly;
|
|
267
|
+
let isInvalid;
|
|
268
|
+
let labelProps;
|
|
269
|
+
let inputProps;
|
|
270
|
+
if (groupState) {
|
|
271
|
+
const itemAria = createCheckboxGroupItem(() => ({
|
|
272
|
+
...inputAriaProps(),
|
|
273
|
+
value: inputAriaProps().value ?? "",
|
|
274
|
+
children: typeof mergedProps.children === "function" ? true : mergedProps.children
|
|
275
|
+
}), groupState, inputElement);
|
|
276
|
+
isSelected = itemAria.isSelected;
|
|
277
|
+
isPressed = itemAria.isPressed;
|
|
278
|
+
labelProps = itemAria.labelProps;
|
|
279
|
+
inputProps = () => itemAria.inputProps;
|
|
280
|
+
} else {
|
|
281
|
+
const checkboxAria = createCheckbox(() => ({
|
|
282
|
+
...inputAriaProps(),
|
|
283
|
+
isIndeterminate: local.isIndeterminate,
|
|
284
|
+
children: typeof mergedProps.children === "function" ? true : mergedProps.children
|
|
285
|
+
}), createToggleState(() => ({
|
|
286
|
+
isSelected: ariaProps.isSelected,
|
|
287
|
+
defaultSelected: ariaProps.defaultSelected,
|
|
288
|
+
onChange: ariaProps.onChange,
|
|
289
|
+
isReadOnly: ariaProps.isReadOnly
|
|
290
|
+
})), inputElement);
|
|
291
|
+
isSelected = checkboxAria.isSelected;
|
|
292
|
+
isPressed = checkboxAria.isPressed;
|
|
293
|
+
labelProps = checkboxAria.labelProps;
|
|
294
|
+
inputProps = () => checkboxAria.inputProps;
|
|
295
|
+
}
|
|
296
|
+
isDisabled = () => inputProps().disabled === true;
|
|
297
|
+
isReadOnly = () => inputProps()["aria-readonly"] === true;
|
|
298
|
+
isInvalid = () => inputProps()["aria-invalid"] === true;
|
|
299
|
+
const describedBy = () => {
|
|
300
|
+
const ids = [
|
|
301
|
+
ariaProps["aria-describedby"],
|
|
302
|
+
local.description ? descriptionId : void 0,
|
|
303
|
+
isInvalid() && local.errorMessage ? errorMessageId : void 0
|
|
304
|
+
].filter(Boolean);
|
|
305
|
+
return ids.length ? ids.join(" ") : void 0;
|
|
306
|
+
};
|
|
307
|
+
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
308
|
+
const { isHovered, hoverProps } = createHover({
|
|
309
|
+
get isDisabled() {
|
|
310
|
+
return isDisabled() || isReadOnly();
|
|
311
|
+
},
|
|
312
|
+
onHoverStart: local.onHoverStart,
|
|
313
|
+
onHoverEnd: local.onHoverEnd,
|
|
314
|
+
onHoverChange: local.onHoverChange
|
|
315
|
+
});
|
|
316
|
+
const renderValues = createMemo(() => ({
|
|
317
|
+
isSelected: isSelected(),
|
|
318
|
+
isIndeterminate: local.isIndeterminate ?? false,
|
|
319
|
+
isHovered: isHovered(),
|
|
320
|
+
isPressed: isPressed(),
|
|
321
|
+
isFocused: isFocused(),
|
|
322
|
+
isFocusVisible: isFocusVisible(),
|
|
323
|
+
isDisabled: isDisabled(),
|
|
324
|
+
isReadOnly: isReadOnly(),
|
|
325
|
+
isInvalid: isInvalid(),
|
|
326
|
+
isRequired: ariaProps.isRequired ?? false
|
|
327
|
+
}));
|
|
328
|
+
const renderProps = useRenderProps({
|
|
329
|
+
children: mergedProps.children,
|
|
330
|
+
class: local.class,
|
|
331
|
+
style: local.style,
|
|
332
|
+
defaultClassName: "solidaria-Checkbox"
|
|
333
|
+
}, renderValues);
|
|
334
|
+
const childRenderValues = {
|
|
335
|
+
get isSelected() {
|
|
336
|
+
return isSelected();
|
|
337
|
+
},
|
|
338
|
+
get isIndeterminate() {
|
|
339
|
+
return local.isIndeterminate ?? false;
|
|
340
|
+
},
|
|
341
|
+
get isHovered() {
|
|
342
|
+
return isHovered();
|
|
343
|
+
},
|
|
344
|
+
get isPressed() {
|
|
345
|
+
return isPressed();
|
|
346
|
+
},
|
|
347
|
+
get isFocused() {
|
|
348
|
+
return isFocused();
|
|
349
|
+
},
|
|
350
|
+
get isFocusVisible() {
|
|
351
|
+
return isFocusVisible();
|
|
352
|
+
},
|
|
353
|
+
get isDisabled() {
|
|
354
|
+
return isDisabled();
|
|
355
|
+
},
|
|
356
|
+
get isReadOnly() {
|
|
357
|
+
return isReadOnly();
|
|
358
|
+
},
|
|
359
|
+
get isInvalid() {
|
|
360
|
+
return isInvalid();
|
|
361
|
+
},
|
|
362
|
+
get isRequired() {
|
|
363
|
+
return ariaProps.isRequired ?? false;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const checkboxChildren = () => {
|
|
367
|
+
const children = mergedProps.children;
|
|
368
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
369
|
+
};
|
|
370
|
+
const domProps = createMemo(() => {
|
|
371
|
+
const filtered = filterDOMProps(ariaProps, { global: true });
|
|
372
|
+
delete filtered.id;
|
|
373
|
+
delete filtered.onClick;
|
|
374
|
+
return filtered;
|
|
375
|
+
});
|
|
376
|
+
const cleanLabelProps = () => {
|
|
377
|
+
const { ref: _ref1, ...rest } = labelProps;
|
|
378
|
+
return rest;
|
|
379
|
+
};
|
|
380
|
+
const cleanHoverProps = () => {
|
|
381
|
+
const { ref: _ref2, ...rest } = hoverProps;
|
|
382
|
+
return rest;
|
|
383
|
+
};
|
|
384
|
+
const cleanInputProps = () => {
|
|
385
|
+
const { ref: _ref3, onFocus: _onFocus, onBlur: _onBlur, ...rest } = inputProps();
|
|
386
|
+
return rest;
|
|
387
|
+
};
|
|
388
|
+
const cleanFocusProps = () => {
|
|
389
|
+
const { ref: _ref4, onFocus: _onFocus, onBlur: _onBlur, ...rest } = focusProps;
|
|
390
|
+
return rest;
|
|
391
|
+
};
|
|
392
|
+
const handleInputFocus = (event) => {
|
|
393
|
+
inputProps().onFocus?.(event);
|
|
394
|
+
focusProps.onFocus?.(event);
|
|
395
|
+
};
|
|
396
|
+
const handleInputBlur = (event) => {
|
|
397
|
+
inputProps().onBlur?.(event);
|
|
398
|
+
focusProps.onBlur?.(event);
|
|
399
|
+
};
|
|
400
|
+
const setLabelRef = (el) => {
|
|
401
|
+
assignRef(local.ref, el);
|
|
402
|
+
};
|
|
403
|
+
const setInputRef = (el) => {
|
|
404
|
+
setInputElement(el);
|
|
405
|
+
for (const ref of inputRefs()) assignRef(ref, el);
|
|
406
|
+
};
|
|
407
|
+
const hiddenInput = createComponent(VisuallyHidden, { get children() {
|
|
408
|
+
var _el$0 = getNextElement(_tmpl$3);
|
|
409
|
+
use(setInputRef, _el$0);
|
|
410
|
+
spread(_el$0, mergeProps(cleanInputProps, cleanFocusProps, {
|
|
411
|
+
"onFocus": handleInputFocus,
|
|
412
|
+
"onBlur": handleInputBlur,
|
|
413
|
+
get ["aria-describedby"]() {
|
|
414
|
+
return describedBy();
|
|
415
|
+
}
|
|
416
|
+
}), false, false);
|
|
417
|
+
runHydrationEvents();
|
|
418
|
+
return _el$0;
|
|
419
|
+
} });
|
|
420
|
+
const labelChildren = () => [
|
|
421
|
+
hiddenInput,
|
|
422
|
+
memo(checkboxChildren),
|
|
423
|
+
createComponent(Show, {
|
|
424
|
+
get when() {
|
|
425
|
+
return local.description;
|
|
426
|
+
},
|
|
427
|
+
get children() {
|
|
428
|
+
var _el$1 = getNextElement(_tmpl$4);
|
|
429
|
+
setAttribute(_el$1, "id", descriptionId);
|
|
430
|
+
insert(_el$1, () => local.description);
|
|
431
|
+
return _el$1;
|
|
432
|
+
}
|
|
433
|
+
}),
|
|
434
|
+
createComponent(Show, {
|
|
435
|
+
get when() {
|
|
436
|
+
return memo(() => !!isInvalid())() && local.errorMessage;
|
|
437
|
+
},
|
|
438
|
+
get children() {
|
|
439
|
+
var _el$10 = getNextElement(_tmpl$5);
|
|
440
|
+
setAttribute(_el$10, "id", errorMessageId);
|
|
441
|
+
insert(_el$10, () => local.errorMessage);
|
|
442
|
+
return _el$10;
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
];
|
|
446
|
+
const rootProps = createMemo(() => ({
|
|
447
|
+
...domProps(),
|
|
448
|
+
...cleanLabelProps(),
|
|
449
|
+
...cleanHoverProps(),
|
|
450
|
+
class: renderProps.class(),
|
|
451
|
+
style: renderProps.style(),
|
|
452
|
+
slot: local.slot,
|
|
453
|
+
"data-selected": isSelected() || void 0,
|
|
454
|
+
"data-indeterminate": local.isIndeterminate || void 0,
|
|
455
|
+
"data-pressed": isPressed() || void 0,
|
|
456
|
+
"data-hovered": isHovered() || void 0,
|
|
457
|
+
"data-focused": isFocused() || void 0,
|
|
458
|
+
"data-focus-visible": isFocusVisible() || void 0,
|
|
459
|
+
"data-disabled": isDisabled() || void 0,
|
|
460
|
+
"data-readonly": isReadOnly() || void 0,
|
|
461
|
+
"data-invalid": isInvalid() || void 0,
|
|
462
|
+
"data-required": ariaProps.isRequired || void 0
|
|
463
|
+
}));
|
|
464
|
+
const customRootProps = () => ({
|
|
465
|
+
...rootProps(),
|
|
466
|
+
ref: setLabelRef,
|
|
467
|
+
children: labelChildren()
|
|
468
|
+
});
|
|
469
|
+
return local.render ? local.render(customRootProps(), renderValues()) : (() => {
|
|
470
|
+
var _el$11 = getNextElement(_tmpl$6);
|
|
471
|
+
use(setLabelRef, _el$11);
|
|
472
|
+
spread(_el$11, mergeProps(domProps, cleanLabelProps, cleanHoverProps, {
|
|
473
|
+
get ["class"]() {
|
|
474
|
+
return renderProps.class();
|
|
475
|
+
},
|
|
476
|
+
get style() {
|
|
477
|
+
return renderProps.style();
|
|
478
|
+
},
|
|
479
|
+
get slot() {
|
|
480
|
+
return local.slot;
|
|
481
|
+
},
|
|
482
|
+
get ["data-selected"]() {
|
|
483
|
+
return isSelected() || void 0;
|
|
484
|
+
},
|
|
485
|
+
get ["data-indeterminate"]() {
|
|
486
|
+
return local.isIndeterminate || void 0;
|
|
487
|
+
},
|
|
488
|
+
get ["data-pressed"]() {
|
|
489
|
+
return isPressed() || void 0;
|
|
490
|
+
},
|
|
491
|
+
get ["data-hovered"]() {
|
|
492
|
+
return isHovered() || void 0;
|
|
493
|
+
},
|
|
494
|
+
get ["data-focused"]() {
|
|
495
|
+
return isFocused() || void 0;
|
|
496
|
+
},
|
|
497
|
+
get ["data-focus-visible"]() {
|
|
498
|
+
return isFocusVisible() || void 0;
|
|
499
|
+
},
|
|
500
|
+
get ["data-disabled"]() {
|
|
501
|
+
return isDisabled() || void 0;
|
|
502
|
+
},
|
|
503
|
+
get ["data-readonly"]() {
|
|
504
|
+
return isReadOnly() || void 0;
|
|
505
|
+
},
|
|
506
|
+
get ["data-invalid"]() {
|
|
507
|
+
return isInvalid() || void 0;
|
|
508
|
+
},
|
|
509
|
+
get ["data-required"]() {
|
|
510
|
+
return ariaProps.isRequired || void 0;
|
|
511
|
+
}
|
|
512
|
+
}), false, true);
|
|
513
|
+
insert(_el$11, labelChildren);
|
|
514
|
+
runHydrationEvents();
|
|
515
|
+
return _el$11;
|
|
516
|
+
})();
|
|
517
|
+
}
|
|
518
|
+
const CheckboxFieldContext = createContext(null);
|
|
519
|
+
const InternalCheckboxContext = createContext(null);
|
|
520
|
+
/**
|
|
521
|
+
* A checkbox allows a user to select an item, with support for validation and help text.
|
|
522
|
+
* Wraps a `CheckboxButton` and provides description/error wiring.
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```tsx
|
|
526
|
+
* <CheckboxField>
|
|
527
|
+
* <CheckboxButton>Accept terms</CheckboxButton>
|
|
528
|
+
* <Text slot="description">Required to continue</Text>
|
|
529
|
+
* </CheckboxField>
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
function CheckboxField(props) {
|
|
533
|
+
const [inputElement, setInputElement] = createSignal(null);
|
|
534
|
+
const formContext = useContext(FormContext);
|
|
535
|
+
const contextProps = useContext(CheckboxFieldContext);
|
|
536
|
+
const contextSlotProps = contextProps?.slots?.[props.slot ?? "default"];
|
|
537
|
+
const contextBaseProps = createMemo(() => {
|
|
538
|
+
if (!contextProps) return {};
|
|
539
|
+
const { slots: _slots, ...rest } = contextProps;
|
|
540
|
+
return rest;
|
|
541
|
+
});
|
|
542
|
+
const mergedProps = contextProps ? mergeProps$2(contextBaseProps(), contextSlotProps ?? {}, props) : props;
|
|
543
|
+
const propsWithFormBehavior = withFormValidationBehavior(mergedProps, formContext);
|
|
544
|
+
const inputRefs = createMemo(() => [
|
|
545
|
+
contextBaseProps().inputRef,
|
|
546
|
+
contextSlotProps?.inputRef,
|
|
547
|
+
props.inputRef
|
|
548
|
+
].filter(Boolean));
|
|
549
|
+
const [local, ariaProps] = splitProps(propsWithFormBehavior, [
|
|
550
|
+
"class",
|
|
551
|
+
"style",
|
|
552
|
+
"ref",
|
|
553
|
+
"inputRef",
|
|
554
|
+
"slot",
|
|
555
|
+
"isIndeterminate",
|
|
556
|
+
"children"
|
|
557
|
+
]);
|
|
558
|
+
const inputAriaProps = createMemo(() => {
|
|
559
|
+
const clean = {};
|
|
560
|
+
for (const key in ariaProps) if (!key.startsWith("data-")) clean[key] = ariaProps[key];
|
|
561
|
+
return clean;
|
|
562
|
+
});
|
|
563
|
+
const groupState = useContext(CheckboxGroupStateContext);
|
|
564
|
+
let isSelected;
|
|
565
|
+
let isPressed;
|
|
566
|
+
let labelProps;
|
|
567
|
+
let inputProps;
|
|
568
|
+
let getDescriptionProps;
|
|
569
|
+
let getErrorMessageProps;
|
|
570
|
+
if (groupState) {
|
|
571
|
+
const itemAria = createCheckboxGroupItem(() => ({
|
|
572
|
+
...inputAriaProps(),
|
|
573
|
+
value: inputAriaProps().value ?? "",
|
|
574
|
+
children: true
|
|
575
|
+
}), groupState, inputElement);
|
|
576
|
+
isSelected = itemAria.isSelected;
|
|
577
|
+
isPressed = itemAria.isPressed;
|
|
578
|
+
labelProps = itemAria.labelProps;
|
|
579
|
+
inputProps = () => itemAria.inputProps;
|
|
580
|
+
getDescriptionProps = () => itemAria.descriptionProps;
|
|
581
|
+
getErrorMessageProps = () => itemAria.errorMessageProps;
|
|
582
|
+
} else {
|
|
583
|
+
const checkboxAria = createCheckbox(() => ({
|
|
584
|
+
...inputAriaProps(),
|
|
585
|
+
isIndeterminate: local.isIndeterminate,
|
|
586
|
+
children: true
|
|
587
|
+
}), createToggleState(() => ({
|
|
588
|
+
isSelected: ariaProps.isSelected,
|
|
589
|
+
defaultSelected: ariaProps.defaultSelected,
|
|
590
|
+
onChange: ariaProps.onChange,
|
|
591
|
+
isReadOnly: ariaProps.isReadOnly
|
|
592
|
+
})), inputElement);
|
|
593
|
+
isSelected = checkboxAria.isSelected;
|
|
594
|
+
isPressed = checkboxAria.isPressed;
|
|
595
|
+
labelProps = checkboxAria.labelProps;
|
|
596
|
+
inputProps = () => checkboxAria.inputProps;
|
|
597
|
+
getDescriptionProps = () => checkboxAria.descriptionProps;
|
|
598
|
+
getErrorMessageProps = () => checkboxAria.errorMessageProps;
|
|
599
|
+
}
|
|
600
|
+
const isDisabled = () => inputProps().disabled === true;
|
|
601
|
+
const isReadOnly = () => inputProps()["aria-readonly"] === true;
|
|
602
|
+
const isInvalid = () => inputProps()["aria-invalid"] === true;
|
|
603
|
+
const isIndeterminate = () => local.isIndeterminate ?? false;
|
|
604
|
+
const isRequired = () => ariaProps.isRequired ?? false;
|
|
605
|
+
const setInputRef = (el) => {
|
|
606
|
+
setInputElement(el);
|
|
607
|
+
for (const ref of inputRefs()) assignRef(ref, el);
|
|
608
|
+
};
|
|
609
|
+
const setFieldRef = (el) => {
|
|
610
|
+
assignRef(local.ref, el);
|
|
611
|
+
};
|
|
612
|
+
const internalContext = {
|
|
613
|
+
isSelected,
|
|
614
|
+
isPressed,
|
|
615
|
+
isDisabled,
|
|
616
|
+
isReadOnly,
|
|
617
|
+
isInvalid,
|
|
618
|
+
isIndeterminate,
|
|
619
|
+
isRequired,
|
|
620
|
+
labelProps: () => labelProps,
|
|
621
|
+
inputProps,
|
|
622
|
+
setInputRef,
|
|
623
|
+
defaultClassName: "solidaria-CheckboxButton"
|
|
624
|
+
};
|
|
625
|
+
const textSlots = { slots: {
|
|
626
|
+
get description() {
|
|
627
|
+
return getDescriptionProps();
|
|
628
|
+
},
|
|
629
|
+
get errorMessage() {
|
|
630
|
+
return getErrorMessageProps();
|
|
631
|
+
}
|
|
632
|
+
} };
|
|
633
|
+
const renderValues = createMemo(() => ({
|
|
634
|
+
isSelected: isSelected(),
|
|
635
|
+
isIndeterminate: isIndeterminate(),
|
|
636
|
+
isDisabled: isDisabled(),
|
|
637
|
+
isReadOnly: isReadOnly(),
|
|
638
|
+
isInvalid: isInvalid(),
|
|
639
|
+
isRequired: isRequired()
|
|
640
|
+
}));
|
|
641
|
+
const renderProps = useRenderProps({
|
|
642
|
+
children: mergedProps.children,
|
|
643
|
+
class: local.class,
|
|
644
|
+
style: local.style,
|
|
645
|
+
defaultClassName: "solidaria-CheckboxField"
|
|
646
|
+
}, renderValues);
|
|
647
|
+
const fieldErrorContext = groupState ? null : {
|
|
648
|
+
get validation() {
|
|
649
|
+
return {
|
|
650
|
+
isInvalid: isInvalid(),
|
|
651
|
+
validationDetails: VALID_VALIDITY_STATE,
|
|
652
|
+
validationErrors: []
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
get errorMessageProps() {
|
|
656
|
+
return getErrorMessageProps();
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
const domProps = createMemo(() => {
|
|
660
|
+
const filtered = filterDOMProps(ariaProps, { global: true });
|
|
661
|
+
delete filtered.id;
|
|
662
|
+
delete filtered.onClick;
|
|
663
|
+
return filtered;
|
|
664
|
+
});
|
|
665
|
+
const FieldChildren = () => {
|
|
666
|
+
const childRenderValues = {
|
|
667
|
+
get isSelected() {
|
|
668
|
+
return isSelected();
|
|
669
|
+
},
|
|
670
|
+
get isIndeterminate() {
|
|
671
|
+
return isIndeterminate();
|
|
672
|
+
},
|
|
673
|
+
get isDisabled() {
|
|
674
|
+
return isDisabled();
|
|
675
|
+
},
|
|
676
|
+
get isReadOnly() {
|
|
677
|
+
return isReadOnly();
|
|
678
|
+
},
|
|
679
|
+
get isInvalid() {
|
|
680
|
+
return isInvalid();
|
|
681
|
+
},
|
|
682
|
+
get isRequired() {
|
|
683
|
+
return isRequired();
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
return memo(createMemo(() => {
|
|
687
|
+
const children = mergedProps.children;
|
|
688
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
689
|
+
}));
|
|
690
|
+
};
|
|
691
|
+
return (() => {
|
|
692
|
+
var _el$12 = getNextElement(_tmpl$);
|
|
693
|
+
use(setFieldRef, _el$12);
|
|
694
|
+
spread(_el$12, mergeProps(domProps, {
|
|
695
|
+
get ["class"]() {
|
|
696
|
+
return renderProps.class();
|
|
697
|
+
},
|
|
698
|
+
get style() {
|
|
699
|
+
return renderProps.style();
|
|
700
|
+
},
|
|
701
|
+
get slot() {
|
|
702
|
+
return local.slot;
|
|
703
|
+
},
|
|
704
|
+
get ["data-selected"]() {
|
|
705
|
+
return isSelected() || void 0;
|
|
706
|
+
},
|
|
707
|
+
get ["data-indeterminate"]() {
|
|
708
|
+
return isIndeterminate() || void 0;
|
|
709
|
+
},
|
|
710
|
+
get ["data-disabled"]() {
|
|
711
|
+
return isDisabled() || void 0;
|
|
712
|
+
},
|
|
713
|
+
get ["data-readonly"]() {
|
|
714
|
+
return isReadOnly() || void 0;
|
|
715
|
+
},
|
|
716
|
+
get ["data-invalid"]() {
|
|
717
|
+
return isInvalid() || void 0;
|
|
718
|
+
},
|
|
719
|
+
get ["data-required"]() {
|
|
720
|
+
return isRequired() || void 0;
|
|
721
|
+
}
|
|
722
|
+
}), false, true);
|
|
723
|
+
insert(_el$12, createComponent(InternalCheckboxContext.Provider, {
|
|
724
|
+
value: internalContext,
|
|
725
|
+
get children() {
|
|
726
|
+
return createComponent(Provider, {
|
|
727
|
+
values: [[TextContext, textSlots]],
|
|
728
|
+
get children() {
|
|
729
|
+
return createComponent(Show, {
|
|
730
|
+
when: fieldErrorContext,
|
|
731
|
+
get fallback() {
|
|
732
|
+
return createComponent(FieldChildren, {});
|
|
733
|
+
},
|
|
734
|
+
keyed: true,
|
|
735
|
+
children: (ctx) => createComponent(FieldErrorContext.Provider, {
|
|
736
|
+
value: ctx,
|
|
737
|
+
get children() {
|
|
738
|
+
return createComponent(FieldChildren, {});
|
|
739
|
+
}
|
|
740
|
+
})
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
}));
|
|
746
|
+
runHydrationEvents();
|
|
747
|
+
return _el$12;
|
|
748
|
+
})();
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* A checkbox button is the clickable area of a checkbox, including the indicator and label.
|
|
752
|
+
* Must be rendered inside a `CheckboxField` (or the legacy `Checkbox`).
|
|
753
|
+
*/
|
|
754
|
+
function CheckboxButton(props) {
|
|
755
|
+
const getCtx = createMemo(() => useContext(InternalCheckboxContext));
|
|
756
|
+
return createComponent(Show, {
|
|
757
|
+
get when() {
|
|
758
|
+
return getCtx();
|
|
759
|
+
},
|
|
760
|
+
fallback: null,
|
|
761
|
+
keyed: true,
|
|
762
|
+
children: (ctx) => createComponent(CheckboxButtonImpl, {
|
|
763
|
+
buttonProps: props,
|
|
764
|
+
ctx
|
|
765
|
+
})
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
function CheckboxButtonImpl(props) {
|
|
769
|
+
const { ctx } = props;
|
|
770
|
+
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
771
|
+
const { isHovered, hoverProps } = createHover({
|
|
772
|
+
get isDisabled() {
|
|
773
|
+
return ctx.isDisabled() || ctx.isReadOnly();
|
|
774
|
+
},
|
|
775
|
+
onHoverStart: props.buttonProps.onHoverStart,
|
|
776
|
+
onHoverEnd: props.buttonProps.onHoverEnd,
|
|
777
|
+
onHoverChange: props.buttonProps.onHoverChange
|
|
778
|
+
});
|
|
779
|
+
const renderValues = createMemo(() => ({
|
|
780
|
+
isSelected: ctx.isSelected(),
|
|
781
|
+
isIndeterminate: ctx.isIndeterminate(),
|
|
782
|
+
isHovered: isHovered(),
|
|
783
|
+
isPressed: ctx.isPressed(),
|
|
784
|
+
isFocused: isFocused(),
|
|
785
|
+
isFocusVisible: isFocusVisible(),
|
|
786
|
+
isDisabled: ctx.isDisabled(),
|
|
787
|
+
isReadOnly: ctx.isReadOnly(),
|
|
788
|
+
isInvalid: ctx.isInvalid(),
|
|
789
|
+
isRequired: ctx.isRequired()
|
|
790
|
+
}));
|
|
791
|
+
const renderProps = useRenderProps({
|
|
792
|
+
children: props.buttonProps.children,
|
|
793
|
+
class: props.buttonProps.class,
|
|
794
|
+
style: props.buttonProps.style,
|
|
795
|
+
defaultClassName: ctx.defaultClassName
|
|
796
|
+
}, renderValues);
|
|
797
|
+
const childRenderValues = {
|
|
798
|
+
get isSelected() {
|
|
799
|
+
return ctx.isSelected();
|
|
800
|
+
},
|
|
801
|
+
get isIndeterminate() {
|
|
802
|
+
return ctx.isIndeterminate();
|
|
803
|
+
},
|
|
804
|
+
get isHovered() {
|
|
805
|
+
return isHovered();
|
|
806
|
+
},
|
|
807
|
+
get isPressed() {
|
|
808
|
+
return ctx.isPressed();
|
|
809
|
+
},
|
|
810
|
+
get isFocused() {
|
|
811
|
+
return isFocused();
|
|
812
|
+
},
|
|
813
|
+
get isFocusVisible() {
|
|
814
|
+
return isFocusVisible();
|
|
815
|
+
},
|
|
816
|
+
get isDisabled() {
|
|
817
|
+
return ctx.isDisabled();
|
|
818
|
+
},
|
|
819
|
+
get isReadOnly() {
|
|
820
|
+
return ctx.isReadOnly();
|
|
821
|
+
},
|
|
822
|
+
get isInvalid() {
|
|
823
|
+
return ctx.isInvalid();
|
|
824
|
+
},
|
|
825
|
+
get isRequired() {
|
|
826
|
+
return ctx.isRequired();
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
const cleanLabelProps = () => {
|
|
830
|
+
const { ref: _ref1, ...rest } = ctx.labelProps();
|
|
831
|
+
return rest;
|
|
832
|
+
};
|
|
833
|
+
const cleanHoverProps = () => {
|
|
834
|
+
const { ref: _ref2, ...rest } = hoverProps;
|
|
835
|
+
return rest;
|
|
836
|
+
};
|
|
837
|
+
const cleanInputProps = () => {
|
|
838
|
+
const { ref: _ref3, onFocus: _onFocus, onBlur: _onBlur, ...rest } = ctx.inputProps();
|
|
839
|
+
return rest;
|
|
840
|
+
};
|
|
841
|
+
const cleanFocusProps = () => {
|
|
842
|
+
const { ref: _ref4, onFocus: _onFocus, onBlur: _onBlur, ...rest } = focusProps;
|
|
843
|
+
return rest;
|
|
844
|
+
};
|
|
845
|
+
const handleInputFocus = (event) => {
|
|
846
|
+
ctx.inputProps().onFocus?.(event);
|
|
847
|
+
focusProps.onFocus?.(event);
|
|
848
|
+
};
|
|
849
|
+
const handleInputBlur = (event) => {
|
|
850
|
+
ctx.inputProps().onBlur?.(event);
|
|
851
|
+
focusProps.onBlur?.(event);
|
|
852
|
+
};
|
|
853
|
+
const setButtonRef = (el) => {
|
|
854
|
+
assignRef(props.buttonProps.ref, el);
|
|
855
|
+
};
|
|
856
|
+
const buttonChildren = () => {
|
|
857
|
+
const children = props.buttonProps.children;
|
|
858
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
859
|
+
};
|
|
860
|
+
return (() => {
|
|
861
|
+
var _el$13 = getNextElement(_tmpl$7), _el$15 = _el$13.firstChild, [_el$16, _co$4] = getNextMarker(_el$15.nextSibling), _el$17 = _el$16.nextSibling, [_el$18, _co$5] = getNextMarker(_el$17.nextSibling);
|
|
862
|
+
use(setButtonRef, _el$13);
|
|
863
|
+
spread(_el$13, mergeProps(cleanLabelProps, cleanHoverProps, {
|
|
864
|
+
get ["class"]() {
|
|
865
|
+
return renderProps.class();
|
|
866
|
+
},
|
|
867
|
+
get style() {
|
|
868
|
+
return renderProps.style();
|
|
869
|
+
},
|
|
870
|
+
get slot() {
|
|
871
|
+
return props.buttonProps.slot;
|
|
872
|
+
},
|
|
873
|
+
get ["data-selected"]() {
|
|
874
|
+
return ctx.isSelected() || void 0;
|
|
875
|
+
},
|
|
876
|
+
get ["data-indeterminate"]() {
|
|
877
|
+
return ctx.isIndeterminate() || void 0;
|
|
878
|
+
},
|
|
879
|
+
get ["data-pressed"]() {
|
|
880
|
+
return ctx.isPressed() || void 0;
|
|
881
|
+
},
|
|
882
|
+
get ["data-hovered"]() {
|
|
883
|
+
return isHovered() || void 0;
|
|
884
|
+
},
|
|
885
|
+
get ["data-focused"]() {
|
|
886
|
+
return isFocused() || void 0;
|
|
887
|
+
},
|
|
888
|
+
get ["data-focus-visible"]() {
|
|
889
|
+
return isFocusVisible() || void 0;
|
|
890
|
+
},
|
|
891
|
+
get ["data-disabled"]() {
|
|
892
|
+
return ctx.isDisabled() || void 0;
|
|
893
|
+
},
|
|
894
|
+
get ["data-readonly"]() {
|
|
895
|
+
return ctx.isReadOnly() || void 0;
|
|
896
|
+
},
|
|
897
|
+
get ["data-invalid"]() {
|
|
898
|
+
return ctx.isInvalid() || void 0;
|
|
899
|
+
},
|
|
900
|
+
get ["data-required"]() {
|
|
901
|
+
return ctx.isRequired() || void 0;
|
|
902
|
+
}
|
|
903
|
+
}), false, true);
|
|
904
|
+
insert(_el$13, createComponent(VisuallyHidden, { get children() {
|
|
905
|
+
var _el$14 = getNextElement(_tmpl$3);
|
|
906
|
+
var _ref$ = ctx.setInputRef;
|
|
907
|
+
typeof _ref$ === "function" ? use(_ref$, _el$14) : ctx.setInputRef = _el$14;
|
|
908
|
+
spread(_el$14, mergeProps(cleanInputProps, cleanFocusProps, {
|
|
909
|
+
"onFocus": handleInputFocus,
|
|
910
|
+
"onBlur": handleInputBlur
|
|
911
|
+
}), false, false);
|
|
912
|
+
runHydrationEvents();
|
|
913
|
+
return _el$14;
|
|
914
|
+
} }), _el$16, _co$4);
|
|
915
|
+
insert(_el$13, buttonChildren, _el$18, _co$5);
|
|
916
|
+
runHydrationEvents();
|
|
917
|
+
return _el$13;
|
|
918
|
+
})();
|
|
919
|
+
}
|
|
920
|
+
//#endregion
|
|
921
|
+
export { Checkbox, CheckboxButton, CheckboxContext, CheckboxField, CheckboxFieldContext, CheckboxGroup, CheckboxGroupContext, CheckboxGroupStateContext };
|
|
922
|
+
|
|
923
|
+
//# sourceMappingURL=Checkbox.js.map
|