@proyecto-viviana/solidaria-components 0.2.5 → 0.3.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/LICENSE +21 -0
- package/README.md +39 -272
- package/dist/ActionBar.d.ts +79 -0
- package/dist/ActionBar.d.ts.map +1 -0
- package/dist/ActionGroup.d.ts +74 -0
- package/dist/ActionGroup.d.ts.map +1 -0
- package/dist/Alert.d.ts +70 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +27 -8
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +28 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +51 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +33 -8
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +130 -0
- package/dist/Collection.d.ts.map +1 -0
- package/dist/Color.d.ts +210 -9
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +42 -0
- package/dist/ColorEditor.d.ts.map +1 -0
- package/dist/ComboBox.d.ts +146 -16
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +40 -0
- package/dist/ContextualHelpTrigger.d.ts.map +1 -0
- package/dist/DateField.d.ts +35 -8
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +101 -5
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DateRangePickerContext.d.ts +30 -0
- package/dist/DateRangePickerContext.d.ts.map +1 -0
- package/dist/Dialog.d.ts +5 -5
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Disclosure.d.ts +25 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +80 -0
- package/dist/DragAndDrop.d.ts.map +1 -0
- package/dist/DragPreview.d.ts +14 -0
- package/dist/DragPreview.d.ts.map +1 -0
- package/dist/DropZone.d.ts +27 -0
- package/dist/DropZone.d.ts.map +1 -0
- package/dist/FieldError.d.ts +27 -0
- package/dist/FieldError.d.ts.map +1 -0
- package/dist/FileTrigger.d.ts +26 -0
- package/dist/FileTrigger.d.ts.map +1 -0
- package/dist/Focusable.d.ts +27 -0
- package/dist/Focusable.d.ts.map +1 -0
- package/dist/Form.d.ts +41 -0
- package/dist/Form.d.ts.map +1 -0
- package/dist/GridList.d.ts +69 -10
- package/dist/GridList.d.ts.map +1 -1
- package/dist/HiddenDateInput.d.ts +26 -0
- package/dist/HiddenDateInput.d.ts.map +1 -0
- package/dist/HiddenTimeInput.d.ts +25 -0
- package/dist/HiddenTimeInput.d.ts.map +1 -0
- package/dist/Icon.d.ts +57 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/Keyboard.d.ts +13 -0
- package/dist/Keyboard.d.ts.map +1 -0
- package/dist/Landmark.d.ts +3 -3
- package/dist/Landmark.d.ts.map +1 -1
- package/dist/Link.d.ts +10 -4
- package/dist/Link.d.ts.map +1 -1
- package/dist/ListBox.d.ts +73 -11
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +38 -0
- package/dist/ListDropTargetDelegate.d.ts.map +1 -0
- package/dist/Menu.d.ts +79 -10
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +4 -4
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +6 -4
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +10 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +32 -7
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +27 -0
- package/dist/Pressable.d.ts.map +1 -0
- package/dist/ProgressBar.d.ts +6 -4
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/RadioGroup.d.ts +43 -9
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RangeCalendar.d.ts +39 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +75 -0
- package/dist/RouterProvider.d.ts.map +1 -0
- package/dist/SearchField.d.ts +23 -21
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +48 -7
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +30 -0
- package/dist/SelectionIndicator.d.ts.map +1 -0
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +41 -0
- package/dist/SharedElementTransition.d.ts.map +1 -0
- package/dist/Slider.d.ts +15 -8
- package/dist/Slider.d.ts.map +1 -1
- package/dist/StepList.d.ts +90 -0
- package/dist/StepList.d.ts.map +1 -0
- package/dist/Switch.d.ts +11 -5
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Table.d.ts +222 -19
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +47 -10
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +22 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +10 -0
- package/dist/Text.d.ts.map +1 -0
- package/dist/TextField.d.ts +19 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +32 -7
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/Toast.d.ts +29 -14
- package/dist/Toast.d.ts.map +1 -1
- package/dist/ToggleButton.d.ts +36 -0
- package/dist/ToggleButton.d.ts.map +1 -0
- package/dist/ToggleButtonGroup.d.ts +33 -0
- package/dist/ToggleButtonGroup.d.ts.map +1 -0
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +58 -7
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +102 -11
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +61 -0
- package/dist/Virtualizer.d.ts.map +1 -0
- package/dist/VirtualizerLayouts.d.ts +82 -0
- package/dist/VirtualizerLayouts.d.ts.map +1 -0
- package/dist/VisuallyHidden.d.ts +4 -2
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +6 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23342 -10644
- package/dist/index.js.map +1 -7
- package/dist/index.jsx +18110 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +93 -0
- package/dist/useDragAndDrop.d.ts.map +1 -0
- package/dist/utils.d.ts +8 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +79 -0
- package/dist/virtualizer/Layout.d.ts.map +1 -0
- package/package.json +33 -32
- package/src/ActionBar.tsx +251 -0
- package/src/ActionGroup.tsx +277 -0
- package/src/Alert.tsx +152 -0
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +227 -72
- package/src/Button.tsx +315 -74
- package/src/Calendar.tsx +347 -141
- package/src/Checkbox.tsx +414 -123
- package/src/Collection.tsx +350 -0
- package/src/Color.tsx +1325 -284
- package/src/ColorEditor.tsx +213 -0
- package/src/ComboBox.tsx +644 -245
- package/src/ContextualHelpTrigger.tsx +195 -0
- package/src/DateField.tsx +274 -106
- package/src/DatePicker.tsx +892 -111
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +173 -104
- package/src/Disclosure.tsx +158 -105
- package/src/DragAndDrop.tsx +340 -0
- package/src/DragPreview.tsx +47 -0
- package/src/DropZone.tsx +233 -0
- package/src/FieldError.tsx +89 -0
- package/src/FileTrigger.tsx +83 -0
- package/src/Focusable.tsx +103 -0
- package/src/Form.tsx +140 -0
- package/src/GridList.tsx +542 -128
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +133 -0
- package/src/Keyboard.tsx +26 -0
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +132 -69
- package/src/ListBox.tsx +656 -106
- package/src/ListDropTargetDelegate.ts +283 -0
- package/src/Menu.tsx +1234 -132
- package/src/Meter.tsx +44 -58
- package/src/Modal.tsx +262 -166
- package/src/NumberField.tsx +267 -151
- package/src/Popover.tsx +452 -343
- package/src/Pressable.tsx +108 -0
- package/src/ProgressBar.tsx +54 -59
- package/src/RadioGroup.tsx +533 -121
- package/src/RangeCalendar.tsx +249 -150
- package/src/RouterProvider.tsx +223 -0
- package/src/SearchField.tsx +460 -133
- package/src/Select.tsx +804 -233
- package/src/SelectionIndicator.tsx +108 -0
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +264 -0
- package/src/Slider.tsx +148 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1551 -225
- package/src/Tabs.tsx +377 -123
- package/src/TagGroup.tsx +233 -135
- package/src/Text.tsx +18 -0
- package/src/TextField.tsx +413 -86
- package/src/TimeField.tsx +232 -222
- package/src/Toast.tsx +306 -160
- package/src/ToggleButton.tsx +169 -0
- package/src/ToggleButtonGroup.tsx +141 -0
- package/src/Toolbar.tsx +61 -70
- package/src/Tooltip.tsx +473 -116
- package/src/Tree.tsx +1514 -175
- package/src/Virtualizer.tsx +730 -0
- package/src/VirtualizerLayouts.ts +280 -0
- package/src/VisuallyHidden.tsx +32 -38
- package/src/contexts.ts +29 -36
- package/src/index.ts +972 -620
- package/src/useDragAndDrop.ts +367 -0
- package/src/utils.tsx +69 -50
- package/src/virtualizer/Layout.ts +192 -0
- package/dist/index.ssr.js +0 -9785
- package/dist/index.ssr.js.map +0 -7
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileTrigger primitive for solidaria-components.
|
|
3
|
+
*
|
|
4
|
+
* Opens the native file picker from any pressable child.
|
|
5
|
+
* Parity target: react-aria-components/src/FileTrigger.tsx
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type JSX, createSignal, splitProps } from "solid-js";
|
|
9
|
+
import { createPress, type PressEvent } from "@proyecto-viviana/solidaria";
|
|
10
|
+
|
|
11
|
+
export interface FileTriggerProps extends Omit<
|
|
12
|
+
JSX.InputHTMLAttributes<HTMLInputElement>,
|
|
13
|
+
"type" | "onChange" | "children" | "onSelect"
|
|
14
|
+
> {
|
|
15
|
+
/** Mime types accepted by the file picker. */
|
|
16
|
+
acceptedFileTypes?: ReadonlyArray<string>;
|
|
17
|
+
/** Whether multiple files can be selected. */
|
|
18
|
+
allowsMultiple?: boolean;
|
|
19
|
+
/** Default camera capture mode for mobile devices. */
|
|
20
|
+
defaultCamera?: "user" | "environment";
|
|
21
|
+
/** Enables directory selection in supported browsers. */
|
|
22
|
+
acceptDirectory?: boolean;
|
|
23
|
+
/** Called when user selection changes. */
|
|
24
|
+
onSelect?: (files: FileList | null) => void;
|
|
25
|
+
/** Trigger content (typically a button). */
|
|
26
|
+
children?: JSX.Element;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A FileTrigger allows a user to access the file system using a custom trigger.
|
|
31
|
+
*/
|
|
32
|
+
export function FileTrigger(props: FileTriggerProps): JSX.Element {
|
|
33
|
+
const [local, inputProps] = splitProps(props, [
|
|
34
|
+
"acceptedFileTypes",
|
|
35
|
+
"allowsMultiple",
|
|
36
|
+
"defaultCamera",
|
|
37
|
+
"acceptDirectory",
|
|
38
|
+
"onSelect",
|
|
39
|
+
"children",
|
|
40
|
+
"disabled",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const [inputRef, setInputRef] = createSignal<HTMLInputElement | null>(null);
|
|
44
|
+
|
|
45
|
+
const openFilePicker = () => {
|
|
46
|
+
const input = inputRef();
|
|
47
|
+
if (!input) return;
|
|
48
|
+
if (input.value) input.value = "";
|
|
49
|
+
input.click();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const { pressProps } = createPress({
|
|
53
|
+
get isDisabled() {
|
|
54
|
+
return !!local.disabled;
|
|
55
|
+
},
|
|
56
|
+
onPress: (_e: PressEvent) => {
|
|
57
|
+
openFilePicker();
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const onInputChange: JSX.EventHandler<HTMLInputElement, Event> = (e) => {
|
|
62
|
+
local.onSelect?.(e.currentTarget.files);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<span {...pressProps}>{local.children}</span>
|
|
68
|
+
<input
|
|
69
|
+
{...inputProps}
|
|
70
|
+
ref={setInputRef}
|
|
71
|
+
type="file"
|
|
72
|
+
style={{ display: "none" }}
|
|
73
|
+
accept={local.acceptedFileTypes?.join(",")}
|
|
74
|
+
multiple={local.allowsMultiple}
|
|
75
|
+
capture={local.defaultCamera}
|
|
76
|
+
disabled={local.disabled}
|
|
77
|
+
// @ts-expect-error Non-standard attribute supported by WebKit browsers.
|
|
78
|
+
webkitdirectory={local.acceptDirectory ? "" : undefined}
|
|
79
|
+
onChange={onInputChange}
|
|
80
|
+
/>
|
|
81
|
+
</>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focusable component for solidaria-components
|
|
3
|
+
*
|
|
4
|
+
* A render-prop component that wraps createFocusable to make an element
|
|
5
|
+
* focusable and capable of auto focus. Port of React Aria's Focusable.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type JSX,
|
|
10
|
+
children as resolveChildren,
|
|
11
|
+
createEffect,
|
|
12
|
+
onCleanup,
|
|
13
|
+
splitProps,
|
|
14
|
+
} from "solid-js";
|
|
15
|
+
import { createFocusable, type CreateFocusableProps } from "@proyecto-viviana/solidaria";
|
|
16
|
+
|
|
17
|
+
export interface FocusableProps extends CreateFocusableProps {
|
|
18
|
+
/** A single child element to make focusable. */
|
|
19
|
+
children: JSX.Element;
|
|
20
|
+
/** Ref callback. */
|
|
21
|
+
ref?: HTMLElement | ((el: HTMLElement) => void);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Makes its child element focusable and capable of auto focus.
|
|
26
|
+
* Applies focus and keyboard event handlers from createFocusable.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <Focusable onFocus={() => console.log('focused')}>
|
|
31
|
+
* <div tabIndex={0}>Focusable content</div>
|
|
32
|
+
* </Focusable>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function Focusable(props: FocusableProps): JSX.Element {
|
|
36
|
+
const [local, focusableProps] = splitProps(props, ["children", "ref"]);
|
|
37
|
+
|
|
38
|
+
let ref!: HTMLElement;
|
|
39
|
+
const { focusableProps: domProps } = createFocusable(focusableProps, () => ref);
|
|
40
|
+
|
|
41
|
+
const resolved = resolveChildren(() => local.children);
|
|
42
|
+
|
|
43
|
+
createEffect(() => {
|
|
44
|
+
const child = resolved() as HTMLElement;
|
|
45
|
+
if (child instanceof HTMLElement) {
|
|
46
|
+
ref = child;
|
|
47
|
+
if (typeof local.ref === "function") {
|
|
48
|
+
local.ref(child);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Apply focusable props to the child element
|
|
52
|
+
const props = domProps;
|
|
53
|
+
const listeners: Array<[string, EventListener]> = [];
|
|
54
|
+
const addListener = (eventName: string, handler: unknown) => {
|
|
55
|
+
if (typeof handler === "function") {
|
|
56
|
+
const listener = handler as EventListener;
|
|
57
|
+
child.addEventListener(eventName, listener);
|
|
58
|
+
listeners.push([eventName, listener]);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
addListener("focus", props.onFocus);
|
|
63
|
+
addListener("blur", props.onBlur);
|
|
64
|
+
addListener("keydown", props.onKeyDown);
|
|
65
|
+
addListener("keyup", props.onKeyUp);
|
|
66
|
+
|
|
67
|
+
// Apply non-event focusable props (e.g. tabIndex/aria/data attrs).
|
|
68
|
+
// Keep explicit child tabIndex to mirror mergeProps(child.props precedence).
|
|
69
|
+
for (const [key, value] of Object.entries(props)) {
|
|
70
|
+
if (key === "ref" || (key.startsWith("on") && typeof value === "function")) continue;
|
|
71
|
+
|
|
72
|
+
if (key === "tabIndex") {
|
|
73
|
+
if (child.hasAttribute("tabindex")) continue;
|
|
74
|
+
if (value == null || value === false) {
|
|
75
|
+
child.removeAttribute("tabindex");
|
|
76
|
+
} else {
|
|
77
|
+
child.tabIndex = Number(value);
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (key.startsWith("aria-") || key.startsWith("data-") || key === "id" || key === "role") {
|
|
83
|
+
if (child.hasAttribute(key)) continue;
|
|
84
|
+
if (value == null || value === false) {
|
|
85
|
+
child.removeAttribute(key);
|
|
86
|
+
} else if (value === true) {
|
|
87
|
+
child.setAttribute(key, "");
|
|
88
|
+
} else {
|
|
89
|
+
child.setAttribute(key, String(value));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onCleanup(() => {
|
|
95
|
+
for (const [eventName, listener] of listeners) {
|
|
96
|
+
child.removeEventListener(eventName, listener);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return <>{resolved()}</>;
|
|
103
|
+
}
|
package/src/Form.tsx
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form primitive for solidaria-components.
|
|
3
|
+
*
|
|
4
|
+
* Provides form-level validation behavior and server validation context.
|
|
5
|
+
* Port direction: react-aria-components/src/Form.tsx
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type JSX, createContext, splitProps } from "solid-js";
|
|
9
|
+
import {
|
|
10
|
+
FormValidationContext,
|
|
11
|
+
type ValidationErrors,
|
|
12
|
+
type ValidationBehavior,
|
|
13
|
+
} from "@proyecto-viviana/solid-stately";
|
|
14
|
+
import {
|
|
15
|
+
type ClassNameOrFunction,
|
|
16
|
+
type StyleOrFunction,
|
|
17
|
+
type RenderChildren,
|
|
18
|
+
type SlotProps,
|
|
19
|
+
useRenderProps,
|
|
20
|
+
filterDOMProps,
|
|
21
|
+
} from "./utils";
|
|
22
|
+
|
|
23
|
+
type RefLike<T> = ((el: T) => void) | { current?: T | null } | undefined;
|
|
24
|
+
|
|
25
|
+
function assignRef<T>(ref: RefLike<T>, el: T): void {
|
|
26
|
+
if (!ref) return;
|
|
27
|
+
if (typeof ref === "function") {
|
|
28
|
+
ref(el);
|
|
29
|
+
} else {
|
|
30
|
+
ref.current = el;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface FormRenderProps {
|
|
35
|
+
validationBehavior: ValidationBehavior;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface FormProps
|
|
39
|
+
extends
|
|
40
|
+
Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "children" | "class" | "style" | "ref">,
|
|
41
|
+
SlotProps {
|
|
42
|
+
/** Server-side validation errors keyed by field name. */
|
|
43
|
+
validationErrors?: ValidationErrors;
|
|
44
|
+
/** Validation behavior mode. */
|
|
45
|
+
validationBehavior?: ValidationBehavior;
|
|
46
|
+
/** Character encodings accepted by the server. React-style alias for Solid's `accept-charset`. */
|
|
47
|
+
acceptCharset?: string;
|
|
48
|
+
/** Browser auto-capitalization hint. React-style alias for Solid's `autocapitalize`. */
|
|
49
|
+
autoCapitalize?: JSX.HTMLAttributes<HTMLFormElement>["autoCapitalize"];
|
|
50
|
+
/** Browser autocomplete behavior. React-style alias for Solid's `autocomplete`. */
|
|
51
|
+
autoComplete?: JSX.FormHTMLAttributes<HTMLFormElement>["autocomplete"];
|
|
52
|
+
/** Form encoding type. React-style alias for Solid's `enctype`. */
|
|
53
|
+
encType?: JSX.FormHTMLAttributes<HTMLFormElement>["enctype"];
|
|
54
|
+
/** The children of the component. */
|
|
55
|
+
children?: RenderChildren<FormRenderProps>;
|
|
56
|
+
/** The CSS className for the element. */
|
|
57
|
+
class?: ClassNameOrFunction<FormRenderProps>;
|
|
58
|
+
/** The inline style for the element. */
|
|
59
|
+
style?: StyleOrFunction<FormRenderProps>;
|
|
60
|
+
/** Ref for the underlying form element. */
|
|
61
|
+
ref?: RefLike<HTMLFormElement>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const FormContext = createContext<FormProps | null>(null);
|
|
65
|
+
|
|
66
|
+
const formDOMPropNames = new Set([
|
|
67
|
+
"accept-charset",
|
|
68
|
+
"acceptCharset",
|
|
69
|
+
"action",
|
|
70
|
+
"autocapitalize",
|
|
71
|
+
"autoCapitalize",
|
|
72
|
+
"autocomplete",
|
|
73
|
+
"autoComplete",
|
|
74
|
+
"encoding",
|
|
75
|
+
"enctype",
|
|
76
|
+
"encType",
|
|
77
|
+
"method",
|
|
78
|
+
"name",
|
|
79
|
+
"rel",
|
|
80
|
+
"target",
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
function filterFormDOMProps(props: object): Record<string, unknown> {
|
|
84
|
+
const filtered = filterDOMProps<Record<string, unknown>>(props, { global: true });
|
|
85
|
+
|
|
86
|
+
for (const key in props) {
|
|
87
|
+
if (Object.prototype.hasOwnProperty.call(props, key) && formDOMPropNames.has(key)) {
|
|
88
|
+
filtered[key] = (props as Record<string, unknown>)[key];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return filtered;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function Form(props: FormProps): JSX.Element {
|
|
96
|
+
const [local, domProps] = splitProps(props, [
|
|
97
|
+
"validationErrors",
|
|
98
|
+
"validationBehavior",
|
|
99
|
+
"children",
|
|
100
|
+
"class",
|
|
101
|
+
"style",
|
|
102
|
+
"ref",
|
|
103
|
+
"slot",
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
const validationBehavior: ValidationBehavior = local.validationBehavior ?? "native";
|
|
107
|
+
const errors = local.validationErrors ?? {};
|
|
108
|
+
const renderProps = useRenderProps(
|
|
109
|
+
{
|
|
110
|
+
get children() {
|
|
111
|
+
return local.children;
|
|
112
|
+
},
|
|
113
|
+
class: local.class,
|
|
114
|
+
style: local.style,
|
|
115
|
+
defaultClassName: "solidaria-Form",
|
|
116
|
+
},
|
|
117
|
+
() => ({
|
|
118
|
+
validationBehavior,
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const filteredDomProps = filterFormDOMProps(domProps);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<form
|
|
126
|
+
{...filteredDomProps}
|
|
127
|
+
ref={(el) => assignRef(local.ref, el)}
|
|
128
|
+
noValidate={validationBehavior !== "native"}
|
|
129
|
+
class={renderProps.class()}
|
|
130
|
+
style={renderProps.style()}
|
|
131
|
+
slot={local.slot}
|
|
132
|
+
>
|
|
133
|
+
<FormContext.Provider value={{ ...props, validationBehavior }}>
|
|
134
|
+
<FormValidationContext.Provider value={errors}>
|
|
135
|
+
{renderProps.renderChildren()}
|
|
136
|
+
</FormValidationContext.Provider>
|
|
137
|
+
</FormContext.Provider>
|
|
138
|
+
</form>
|
|
139
|
+
);
|
|
140
|
+
}
|