@ark-ui/react 3.5.0 → 3.6.1
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/README.md +3 -0
- package/dist/components/dialog/dialog-root.d.cts +1 -1
- package/dist/components/dialog/dialog-root.d.ts +1 -1
- package/dist/components/field/use-field.cjs +91 -56
- package/dist/components/field/use-field.d.cts +7 -61
- package/dist/components/field/use-field.d.ts +7 -61
- package/dist/components/field/use-field.js +92 -57
- package/dist/components/fieldset/fieldset-context.cjs +10 -0
- package/dist/components/fieldset/fieldset-context.d.cts +7 -0
- package/dist/components/fieldset/fieldset-context.d.ts +7 -0
- package/dist/components/fieldset/fieldset-context.js +6 -0
- package/dist/components/fieldset/fieldset-error-text.cjs +21 -0
- package/dist/components/fieldset/fieldset-error-text.d.cts +8 -0
- package/dist/components/fieldset/fieldset-error-text.d.ts +8 -0
- package/dist/components/fieldset/fieldset-error-text.js +17 -0
- package/dist/components/fieldset/fieldset-helper-text.cjs +21 -0
- package/dist/components/fieldset/fieldset-helper-text.d.cts +8 -0
- package/dist/components/fieldset/fieldset-helper-text.d.ts +8 -0
- package/dist/components/fieldset/fieldset-helper-text.js +17 -0
- package/dist/components/fieldset/fieldset-legend.cjs +19 -0
- package/dist/components/fieldset/fieldset-legend.d.cts +8 -0
- package/dist/components/fieldset/fieldset-legend.d.ts +8 -0
- package/dist/components/fieldset/fieldset-legend.js +15 -0
- package/dist/components/fieldset/fieldset-root-provider.cjs +24 -0
- package/dist/components/fieldset/fieldset-root-provider.d.cts +13 -0
- package/dist/components/fieldset/fieldset-root-provider.d.ts +13 -0
- package/dist/components/fieldset/fieldset-root-provider.js +20 -0
- package/dist/components/fieldset/fieldset-root.cjs +27 -0
- package/dist/components/fieldset/fieldset-root.d.cts +9 -0
- package/dist/components/fieldset/fieldset-root.d.ts +9 -0
- package/dist/components/fieldset/fieldset-root.js +23 -0
- package/dist/components/fieldset/fieldset.anatomy.cjs +17 -0
- package/dist/components/fieldset/fieldset.anatomy.d.cts +3 -0
- package/dist/components/fieldset/fieldset.anatomy.d.ts +3 -0
- package/dist/components/fieldset/fieldset.anatomy.js +12 -0
- package/dist/components/fieldset/fieldset.cjs +19 -0
- package/dist/components/fieldset/fieldset.d.cts +6 -0
- package/dist/components/fieldset/fieldset.d.ts +6 -0
- package/dist/components/fieldset/fieldset.js +6 -0
- package/dist/components/fieldset/index.cjs +25 -0
- package/dist/components/fieldset/index.d.cts +9 -0
- package/dist/components/fieldset/index.d.ts +9 -0
- package/dist/components/fieldset/index.js +10 -0
- package/dist/components/fieldset/use-fieldset-context.cjs +16 -0
- package/dist/components/fieldset/use-fieldset-context.d.cts +6 -0
- package/dist/components/fieldset/use-fieldset-context.d.ts +6 -0
- package/dist/components/fieldset/use-fieldset-context.js +11 -0
- package/dist/components/fieldset/use-fieldset.cjs +85 -0
- package/dist/components/fieldset/use-fieldset.d.cts +29 -0
- package/dist/components/fieldset/use-fieldset.d.ts +29 -0
- package/dist/components/fieldset/use-fieldset.js +81 -0
- package/dist/components/highlight/highlight.cjs +26 -0
- package/dist/components/highlight/highlight.d.cts +8 -0
- package/dist/components/highlight/highlight.d.ts +8 -0
- package/dist/components/highlight/highlight.js +22 -0
- package/dist/components/highlight/index.cjs +11 -0
- package/dist/components/highlight/index.d.cts +2 -0
- package/dist/components/highlight/index.d.ts +2 -0
- package/dist/components/highlight/index.js +2 -0
- package/dist/components/highlight/use-highlight.cjs +49 -0
- package/dist/components/highlight/use-highlight.d.cts +30 -0
- package/dist/components/highlight/use-highlight.d.ts +30 -0
- package/dist/components/highlight/use-highlight.js +45 -0
- package/dist/components/index.cjs +54 -0
- package/dist/components/index.d.cts +3 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +29 -0
- package/dist/components/select/select-hidden-select.cjs +8 -1
- package/dist/components/select/select-hidden-select.js +8 -1
- package/dist/components/time-picker/index.cjs +39 -0
- package/dist/components/time-picker/index.d.cts +17 -0
- package/dist/components/time-picker/index.d.ts +17 -0
- package/dist/components/time-picker/index.js +17 -0
- package/dist/components/time-picker/time-picker-cell.cjs +29 -0
- package/dist/components/time-picker/time-picker-cell.d.cts +14 -0
- package/dist/components/time-picker/time-picker-cell.d.ts +14 -0
- package/dist/components/time-picker/time-picker-cell.js +25 -0
- package/dist/components/time-picker/time-picker-clear-trigger.cjs +21 -0
- package/dist/components/time-picker/time-picker-clear-trigger.d.cts +8 -0
- package/dist/components/time-picker/time-picker-clear-trigger.d.ts +8 -0
- package/dist/components/time-picker/time-picker-clear-trigger.js +17 -0
- package/dist/components/time-picker/time-picker-column.cjs +22 -0
- package/dist/components/time-picker/time-picker-column.d.cts +9 -0
- package/dist/components/time-picker/time-picker-column.d.ts +9 -0
- package/dist/components/time-picker/time-picker-column.js +18 -0
- package/dist/components/time-picker/time-picker-content.cjs +30 -0
- package/dist/components/time-picker/time-picker-content.d.cts +8 -0
- package/dist/components/time-picker/time-picker-content.d.ts +8 -0
- package/dist/components/time-picker/time-picker-content.js +26 -0
- package/dist/components/time-picker/time-picker-context.cjs +10 -0
- package/dist/components/time-picker/time-picker-context.d.cts +7 -0
- package/dist/components/time-picker/time-picker-context.d.ts +7 -0
- package/dist/components/time-picker/time-picker-context.js +6 -0
- package/dist/components/time-picker/time-picker-control.cjs +21 -0
- package/dist/components/time-picker/time-picker-control.d.cts +8 -0
- package/dist/components/time-picker/time-picker-control.d.ts +8 -0
- package/dist/components/time-picker/time-picker-control.js +17 -0
- package/dist/components/time-picker/time-picker-input.cjs +19 -0
- package/dist/components/time-picker/time-picker-input.d.cts +8 -0
- package/dist/components/time-picker/time-picker-input.d.ts +8 -0
- package/dist/components/time-picker/time-picker-input.js +15 -0
- package/dist/components/time-picker/time-picker-label.cjs +19 -0
- package/dist/components/time-picker/time-picker-label.d.cts +8 -0
- package/dist/components/time-picker/time-picker-label.d.ts +8 -0
- package/dist/components/time-picker/time-picker-label.js +15 -0
- package/dist/components/time-picker/time-picker-positioner.cjs +26 -0
- package/dist/components/time-picker/time-picker-positioner.d.cts +8 -0
- package/dist/components/time-picker/time-picker-positioner.d.ts +8 -0
- package/dist/components/time-picker/time-picker-positioner.js +22 -0
- package/dist/components/time-picker/time-picker-root-provider.cjs +30 -0
- package/dist/components/time-picker/time-picker-root-provider.d.cts +14 -0
- package/dist/components/time-picker/time-picker-root-provider.d.ts +14 -0
- package/dist/components/time-picker/time-picker-root-provider.js +26 -0
- package/dist/components/time-picker/time-picker-root.cjs +48 -0
- package/dist/components/time-picker/time-picker-root.d.cts +11 -0
- package/dist/components/time-picker/time-picker-root.d.ts +11 -0
- package/dist/components/time-picker/time-picker-root.js +44 -0
- package/dist/components/time-picker/time-picker-spacer.cjs +19 -0
- package/dist/components/time-picker/time-picker-spacer.d.cts +8 -0
- package/dist/components/time-picker/time-picker-spacer.d.ts +8 -0
- package/dist/components/time-picker/time-picker-spacer.js +15 -0
- package/dist/components/time-picker/time-picker-trigger.cjs +21 -0
- package/dist/components/time-picker/time-picker-trigger.d.cts +8 -0
- package/dist/components/time-picker/time-picker-trigger.d.ts +8 -0
- package/dist/components/time-picker/time-picker-trigger.js +17 -0
- package/dist/components/time-picker/time-picker.cjs +33 -0
- package/dist/components/time-picker/time-picker.d.cts +14 -0
- package/dist/components/time-picker/time-picker.d.ts +14 -0
- package/dist/components/time-picker/time-picker.js +13 -0
- package/dist/components/time-picker/use-time-picker-column-props-context.cjs +15 -0
- package/dist/components/time-picker/use-time-picker-column-props-context.d.cts +7 -0
- package/dist/components/time-picker/use-time-picker-column-props-context.d.ts +7 -0
- package/dist/components/time-picker/use-time-picker-column-props-context.js +10 -0
- package/dist/components/time-picker/use-time-picker-context.cjs +15 -0
- package/dist/components/time-picker/use-time-picker-context.d.cts +6 -0
- package/dist/components/time-picker/use-time-picker-context.d.ts +6 -0
- package/dist/components/time-picker/use-time-picker-context.js +10 -0
- package/dist/components/time-picker/use-time-picker.cjs +60 -0
- package/dist/components/time-picker/use-time-picker.d.cts +31 -0
- package/dist/components/time-picker/use-time-picker.d.ts +31 -0
- package/dist/components/time-picker/use-time-picker.js +37 -0
- package/dist/components/toast/index.d.cts +1 -1
- package/dist/components/toast/index.d.ts +1 -1
- package/dist/index.cjs +54 -0
- package/dist/index.js +29 -0
- package/dist/node_modules/@internationalized/date/dist/CalendarDate.cjs +52 -0
- package/dist/node_modules/@internationalized/date/dist/CalendarDate.js +48 -0
- package/dist/node_modules/@internationalized/date/dist/manipulation.cjs +108 -0
- package/dist/node_modules/@internationalized/date/dist/manipulation.js +99 -0
- package/dist/node_modules/@internationalized/date/dist/queries.cjs +13 -0
- package/dist/node_modules/@internationalized/date/dist/queries.js +9 -0
- package/dist/node_modules/@internationalized/date/dist/string.cjs +38 -0
- package/dist/node_modules/@internationalized/date/dist/string.js +33 -0
- package/dist/node_modules/@swc/helpers/esm/_check_private_redeclaration.cjs +13 -0
- package/dist/node_modules/@swc/helpers/esm/_check_private_redeclaration.js +8 -0
- package/dist/node_modules/@swc/helpers/esm/_class_private_field_init.cjs +14 -0
- package/dist/node_modules/@swc/helpers/esm/_class_private_field_init.js +9 -0
- package/package.json +97 -60
package/README.md
CHANGED
|
@@ -31,6 +31,8 @@ Ark UI is available for the following JavaScript frameworks:
|
|
|
31
31
|
- [Date Picker](https://ark-ui.com/react/docs/components/date-picker)
|
|
32
32
|
- [Dialog](https://ark-ui.com/react/docs/components/dialog)
|
|
33
33
|
- [Editable](https://ark-ui.com/react/docs/components/editable)
|
|
34
|
+
- [Field](https://ark-ui.com/react/docs/components/field)
|
|
35
|
+
- [Fieldset](https://ark-ui.com/react/docs/components/fieldset)
|
|
34
36
|
- [File Upload](https://ark-ui.com/react/docs/components/file-upload)
|
|
35
37
|
- [Hover Card](https://ark-ui.com/react/docs/components/hover-card)
|
|
36
38
|
- [Menu](https://ark-ui.com/react/docs/components/menu)
|
|
@@ -51,6 +53,7 @@ Ark UI is available for the following JavaScript frameworks:
|
|
|
51
53
|
- [Switch](https://ark-ui.com/react/docs/components/switch)
|
|
52
54
|
- [Tabs](https://ark-ui.com/react/docs/components/tabs)
|
|
53
55
|
- [Tags Input](https://ark-ui.com/react/docs/components/tags-input)
|
|
56
|
+
- [Time Picker](https://ark-ui.com/react/docs/components/time-picker)
|
|
54
57
|
- [Toast](https://ark-ui.com/react/docs/components/toast)
|
|
55
58
|
- [Toggle Group](https://ark-ui.com/react/docs/components/toggle-group)
|
|
56
59
|
- [Tooltip](https://ark-ui.com/react/docs/components/tooltip)
|
|
@@ -4,7 +4,7 @@ import { UseDialogProps } from './use-dialog';
|
|
|
4
4
|
|
|
5
5
|
export interface DialogRootBaseProps extends UseDialogProps, UsePresenceProps {
|
|
6
6
|
}
|
|
7
|
-
export interface DialogRootProps extends
|
|
7
|
+
export interface DialogRootProps extends DialogRootBaseProps {
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
}
|
|
10
10
|
export declare const DialogRoot: (props: DialogRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,7 @@ import { UseDialogProps } from './use-dialog';
|
|
|
4
4
|
|
|
5
5
|
export interface DialogRootBaseProps extends UseDialogProps, UsePresenceProps {
|
|
6
6
|
}
|
|
7
|
-
export interface DialogRootProps extends
|
|
7
|
+
export interface DialogRootProps extends DialogRootBaseProps {
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
}
|
|
10
10
|
export declare const DialogRoot: (props: DialogRootProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,12 +5,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
|
|
6
6
|
const domQuery = require('@zag-js/dom-query');
|
|
7
7
|
const react = require('react');
|
|
8
|
+
const useFieldsetContext = require('../fieldset/use-fieldset-context.cjs');
|
|
8
9
|
const field_anatomy = require('./field.anatomy.cjs');
|
|
9
10
|
|
|
10
11
|
const useField = (props) => {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const fieldset = useFieldsetContext.useFieldsetContext();
|
|
13
|
+
const {
|
|
14
|
+
disabled = Boolean(fieldset?.disabled),
|
|
15
|
+
invalid = false,
|
|
16
|
+
readOnly = false,
|
|
17
|
+
required = false
|
|
18
|
+
} = props;
|
|
19
|
+
const hasErrorText = react.useRef(false);
|
|
20
|
+
const hasHelperText = react.useRef(false);
|
|
14
21
|
const id = props.id ?? react.useId();
|
|
15
22
|
const rootRef = react.useRef(null);
|
|
16
23
|
const errorTextId = `field::${id}::error-text`;
|
|
@@ -22,65 +29,93 @@ const useField = (props) => {
|
|
|
22
29
|
const win = domQuery.getWindow(rootNode);
|
|
23
30
|
const doc = win.document;
|
|
24
31
|
const checkTextElements = () => {
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
hasErrorText.current = !!doc.getElementById(errorTextId);
|
|
33
|
+
hasHelperText.current = !!doc.getElementById(helperTextId);
|
|
27
34
|
};
|
|
28
35
|
checkTextElements();
|
|
29
36
|
const observer = new win.MutationObserver(checkTextElements);
|
|
30
37
|
observer.observe(rootNode, { childList: true, subtree: true });
|
|
31
38
|
return () => observer.disconnect();
|
|
32
39
|
}, [errorTextId, helperTextId]);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
readOnly
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
40
|
+
const labelIds = react.useMemo(() => {
|
|
41
|
+
const ids = [];
|
|
42
|
+
if (hasErrorText.current && invalid) ids.push(errorTextId);
|
|
43
|
+
if (hasHelperText.current) ids.push(helperTextId);
|
|
44
|
+
return ids.join(" ") || void 0;
|
|
45
|
+
}, [invalid, errorTextId, helperTextId]);
|
|
46
|
+
const getRootProps = react.useMemo(
|
|
47
|
+
() => () => ({
|
|
48
|
+
...field_anatomy.parts.root.attrs,
|
|
49
|
+
ref: rootRef,
|
|
50
|
+
role: "group",
|
|
51
|
+
"data-disabled": dataAttr(disabled),
|
|
52
|
+
"data-invalid": dataAttr(invalid),
|
|
53
|
+
"data-readonly": dataAttr(readOnly)
|
|
54
|
+
}),
|
|
55
|
+
[disabled, invalid, readOnly]
|
|
56
|
+
);
|
|
57
|
+
const getLabelProps = react.useMemo(
|
|
58
|
+
() => () => ({
|
|
59
|
+
...field_anatomy.parts.label.attrs,
|
|
60
|
+
id: labelId,
|
|
61
|
+
"data-disabled": dataAttr(disabled),
|
|
62
|
+
"data-invalid": dataAttr(invalid),
|
|
63
|
+
"data-readonly": dataAttr(readOnly),
|
|
64
|
+
htmlFor: id
|
|
65
|
+
}),
|
|
66
|
+
[disabled, invalid, readOnly, id, labelId]
|
|
67
|
+
);
|
|
68
|
+
const getControlProps = react.useMemo(
|
|
69
|
+
() => () => ({
|
|
70
|
+
"aria-describedby": labelIds,
|
|
71
|
+
"aria-invalid": ariaAttr(invalid),
|
|
72
|
+
"aria-required": ariaAttr(required),
|
|
73
|
+
"aria-readonly": ariaAttr(readOnly),
|
|
74
|
+
id,
|
|
75
|
+
required,
|
|
76
|
+
disabled,
|
|
77
|
+
readOnly
|
|
78
|
+
}),
|
|
79
|
+
[labelIds, invalid, required, readOnly, id, disabled]
|
|
80
|
+
);
|
|
81
|
+
const getInputProps = react.useMemo(
|
|
82
|
+
() => () => ({
|
|
83
|
+
...getControlProps(),
|
|
84
|
+
...field_anatomy.parts.input.attrs
|
|
85
|
+
}),
|
|
86
|
+
[getControlProps]
|
|
87
|
+
);
|
|
88
|
+
const getTextareaProps = react.useMemo(
|
|
89
|
+
() => () => ({
|
|
90
|
+
...getControlProps(),
|
|
91
|
+
...field_anatomy.parts.textarea.attrs
|
|
92
|
+
}),
|
|
93
|
+
[getControlProps]
|
|
94
|
+
);
|
|
95
|
+
const getSelectProps = react.useMemo(
|
|
96
|
+
() => () => ({
|
|
97
|
+
...getControlProps(),
|
|
98
|
+
...field_anatomy.parts.select.attrs
|
|
99
|
+
}),
|
|
100
|
+
[getControlProps]
|
|
101
|
+
);
|
|
102
|
+
const getHelperTextProps = react.useMemo(
|
|
103
|
+
() => () => ({
|
|
104
|
+
id: helperTextId,
|
|
105
|
+
...field_anatomy.parts.helperText.attrs
|
|
106
|
+
}),
|
|
107
|
+
[helperTextId]
|
|
108
|
+
);
|
|
109
|
+
const getErrorTextProps = react.useMemo(
|
|
110
|
+
() => () => ({
|
|
111
|
+
id: errorTextId,
|
|
112
|
+
...field_anatomy.parts.errorText.attrs,
|
|
113
|
+
"aria-live": "polite"
|
|
114
|
+
}),
|
|
115
|
+
[errorTextId]
|
|
116
|
+
);
|
|
82
117
|
return {
|
|
83
|
-
ariaDescribedby: labelIds
|
|
118
|
+
ariaDescribedby: labelIds,
|
|
84
119
|
ids: {
|
|
85
120
|
control: id,
|
|
86
121
|
label: labelId,
|
|
@@ -103,7 +138,7 @@ const useField = (props) => {
|
|
|
103
138
|
getErrorTextProps
|
|
104
139
|
};
|
|
105
140
|
};
|
|
106
|
-
const dataAttr = (condition) => condition ? "" : void 0;
|
|
141
|
+
const dataAttr = (condition) => condition ? "true" : void 0;
|
|
107
142
|
const ariaAttr = (condition) => condition ? true : void 0;
|
|
108
143
|
|
|
109
144
|
exports.useField = useField;
|
|
@@ -22,7 +22,7 @@ export interface UseFieldProps {
|
|
|
22
22
|
}
|
|
23
23
|
export type UseFieldReturn = ReturnType<typeof useField>;
|
|
24
24
|
export declare const useField: (props: UseFieldProps) => {
|
|
25
|
-
ariaDescribedby: string;
|
|
25
|
+
ariaDescribedby: string | undefined;
|
|
26
26
|
ids: {
|
|
27
27
|
control: string;
|
|
28
28
|
label: string;
|
|
@@ -36,65 +36,11 @@ export declare const useField: (props: UseFieldProps) => {
|
|
|
36
36
|
invalid: boolean;
|
|
37
37
|
readOnly: boolean;
|
|
38
38
|
required: boolean;
|
|
39
|
-
getLabelProps: () =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"data-scope": string;
|
|
46
|
-
"data-part": string;
|
|
47
|
-
};
|
|
48
|
-
getRootProps: () => {
|
|
49
|
-
role: string;
|
|
50
|
-
'data-disabled': Booleanish;
|
|
51
|
-
'data-invalid': Booleanish;
|
|
52
|
-
'data-readonly': Booleanish;
|
|
53
|
-
"data-scope": string;
|
|
54
|
-
"data-part": string;
|
|
55
|
-
};
|
|
56
|
-
getInputProps: () => {
|
|
57
|
-
"data-scope": string;
|
|
58
|
-
"data-part": string;
|
|
59
|
-
'aria-describedby': string | undefined;
|
|
60
|
-
'aria-invalid': boolean | undefined;
|
|
61
|
-
'aria-required': boolean | undefined;
|
|
62
|
-
'aria-readonly': boolean | undefined;
|
|
63
|
-
id: string;
|
|
64
|
-
required: boolean;
|
|
65
|
-
disabled: boolean;
|
|
66
|
-
readOnly: boolean;
|
|
67
|
-
};
|
|
68
|
-
getTextareaProps: () => {
|
|
69
|
-
"data-scope": string;
|
|
70
|
-
"data-part": string;
|
|
71
|
-
'aria-describedby': string | undefined;
|
|
72
|
-
'aria-invalid': boolean | undefined;
|
|
73
|
-
'aria-required': boolean | undefined;
|
|
74
|
-
'aria-readonly': boolean | undefined;
|
|
75
|
-
id: string;
|
|
76
|
-
required: boolean;
|
|
77
|
-
disabled: boolean;
|
|
78
|
-
readOnly: boolean;
|
|
79
|
-
};
|
|
80
|
-
getSelectProps: () => {
|
|
81
|
-
"data-scope": string;
|
|
82
|
-
"data-part": string;
|
|
83
|
-
'aria-describedby': string | undefined;
|
|
84
|
-
'aria-invalid': boolean | undefined;
|
|
85
|
-
'aria-required': boolean | undefined;
|
|
86
|
-
'aria-readonly': boolean | undefined;
|
|
87
|
-
id: string;
|
|
88
|
-
required: boolean;
|
|
89
|
-
disabled: boolean;
|
|
90
|
-
readOnly: boolean;
|
|
91
|
-
};
|
|
92
|
-
getHelperTextProps: () => {
|
|
93
|
-
"data-scope": string;
|
|
94
|
-
"data-part": string;
|
|
95
|
-
id: string;
|
|
96
|
-
};
|
|
39
|
+
getLabelProps: () => HTMLProps<"label">;
|
|
40
|
+
getRootProps: () => HTMLProps<"div">;
|
|
41
|
+
getInputProps: () => HTMLProps<"input">;
|
|
42
|
+
getTextareaProps: () => HTMLProps<"textarea">;
|
|
43
|
+
getSelectProps: () => HTMLProps<"select">;
|
|
44
|
+
getHelperTextProps: () => HTMLProps<"span">;
|
|
97
45
|
getErrorTextProps: () => HTMLProps<"span">;
|
|
98
46
|
};
|
|
99
|
-
type Booleanish = boolean | 'true' | 'false';
|
|
100
|
-
export {};
|
|
@@ -22,7 +22,7 @@ export interface UseFieldProps {
|
|
|
22
22
|
}
|
|
23
23
|
export type UseFieldReturn = ReturnType<typeof useField>;
|
|
24
24
|
export declare const useField: (props: UseFieldProps) => {
|
|
25
|
-
ariaDescribedby: string;
|
|
25
|
+
ariaDescribedby: string | undefined;
|
|
26
26
|
ids: {
|
|
27
27
|
control: string;
|
|
28
28
|
label: string;
|
|
@@ -36,65 +36,11 @@ export declare const useField: (props: UseFieldProps) => {
|
|
|
36
36
|
invalid: boolean;
|
|
37
37
|
readOnly: boolean;
|
|
38
38
|
required: boolean;
|
|
39
|
-
getLabelProps: () =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"data-scope": string;
|
|
46
|
-
"data-part": string;
|
|
47
|
-
};
|
|
48
|
-
getRootProps: () => {
|
|
49
|
-
role: string;
|
|
50
|
-
'data-disabled': Booleanish;
|
|
51
|
-
'data-invalid': Booleanish;
|
|
52
|
-
'data-readonly': Booleanish;
|
|
53
|
-
"data-scope": string;
|
|
54
|
-
"data-part": string;
|
|
55
|
-
};
|
|
56
|
-
getInputProps: () => {
|
|
57
|
-
"data-scope": string;
|
|
58
|
-
"data-part": string;
|
|
59
|
-
'aria-describedby': string | undefined;
|
|
60
|
-
'aria-invalid': boolean | undefined;
|
|
61
|
-
'aria-required': boolean | undefined;
|
|
62
|
-
'aria-readonly': boolean | undefined;
|
|
63
|
-
id: string;
|
|
64
|
-
required: boolean;
|
|
65
|
-
disabled: boolean;
|
|
66
|
-
readOnly: boolean;
|
|
67
|
-
};
|
|
68
|
-
getTextareaProps: () => {
|
|
69
|
-
"data-scope": string;
|
|
70
|
-
"data-part": string;
|
|
71
|
-
'aria-describedby': string | undefined;
|
|
72
|
-
'aria-invalid': boolean | undefined;
|
|
73
|
-
'aria-required': boolean | undefined;
|
|
74
|
-
'aria-readonly': boolean | undefined;
|
|
75
|
-
id: string;
|
|
76
|
-
required: boolean;
|
|
77
|
-
disabled: boolean;
|
|
78
|
-
readOnly: boolean;
|
|
79
|
-
};
|
|
80
|
-
getSelectProps: () => {
|
|
81
|
-
"data-scope": string;
|
|
82
|
-
"data-part": string;
|
|
83
|
-
'aria-describedby': string | undefined;
|
|
84
|
-
'aria-invalid': boolean | undefined;
|
|
85
|
-
'aria-required': boolean | undefined;
|
|
86
|
-
'aria-readonly': boolean | undefined;
|
|
87
|
-
id: string;
|
|
88
|
-
required: boolean;
|
|
89
|
-
disabled: boolean;
|
|
90
|
-
readOnly: boolean;
|
|
91
|
-
};
|
|
92
|
-
getHelperTextProps: () => {
|
|
93
|
-
"data-scope": string;
|
|
94
|
-
"data-part": string;
|
|
95
|
-
id: string;
|
|
96
|
-
};
|
|
39
|
+
getLabelProps: () => HTMLProps<"label">;
|
|
40
|
+
getRootProps: () => HTMLProps<"div">;
|
|
41
|
+
getInputProps: () => HTMLProps<"input">;
|
|
42
|
+
getTextareaProps: () => HTMLProps<"textarea">;
|
|
43
|
+
getSelectProps: () => HTMLProps<"select">;
|
|
44
|
+
getHelperTextProps: () => HTMLProps<"span">;
|
|
97
45
|
getErrorTextProps: () => HTMLProps<"span">;
|
|
98
46
|
};
|
|
99
|
-
type Booleanish = boolean | 'true' | 'false';
|
|
100
|
-
export {};
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { getWindow } from '@zag-js/dom-query';
|
|
3
|
-
import {
|
|
3
|
+
import { useRef, useId, useLayoutEffect, useMemo } from 'react';
|
|
4
|
+
import { useFieldsetContext } from '../fieldset/use-fieldset-context.js';
|
|
4
5
|
import { parts } from './field.anatomy.js';
|
|
5
6
|
|
|
6
7
|
const useField = (props) => {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const fieldset = useFieldsetContext();
|
|
9
|
+
const {
|
|
10
|
+
disabled = Boolean(fieldset?.disabled),
|
|
11
|
+
invalid = false,
|
|
12
|
+
readOnly = false,
|
|
13
|
+
required = false
|
|
14
|
+
} = props;
|
|
15
|
+
const hasErrorText = useRef(false);
|
|
16
|
+
const hasHelperText = useRef(false);
|
|
10
17
|
const id = props.id ?? useId();
|
|
11
18
|
const rootRef = useRef(null);
|
|
12
19
|
const errorTextId = `field::${id}::error-text`;
|
|
@@ -18,65 +25,93 @@ const useField = (props) => {
|
|
|
18
25
|
const win = getWindow(rootNode);
|
|
19
26
|
const doc = win.document;
|
|
20
27
|
const checkTextElements = () => {
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
hasErrorText.current = !!doc.getElementById(errorTextId);
|
|
29
|
+
hasHelperText.current = !!doc.getElementById(helperTextId);
|
|
23
30
|
};
|
|
24
31
|
checkTextElements();
|
|
25
32
|
const observer = new win.MutationObserver(checkTextElements);
|
|
26
33
|
observer.observe(rootNode, { childList: true, subtree: true });
|
|
27
34
|
return () => observer.disconnect();
|
|
28
35
|
}, [errorTextId, helperTextId]);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
readOnly
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
36
|
+
const labelIds = useMemo(() => {
|
|
37
|
+
const ids = [];
|
|
38
|
+
if (hasErrorText.current && invalid) ids.push(errorTextId);
|
|
39
|
+
if (hasHelperText.current) ids.push(helperTextId);
|
|
40
|
+
return ids.join(" ") || void 0;
|
|
41
|
+
}, [invalid, errorTextId, helperTextId]);
|
|
42
|
+
const getRootProps = useMemo(
|
|
43
|
+
() => () => ({
|
|
44
|
+
...parts.root.attrs,
|
|
45
|
+
ref: rootRef,
|
|
46
|
+
role: "group",
|
|
47
|
+
"data-disabled": dataAttr(disabled),
|
|
48
|
+
"data-invalid": dataAttr(invalid),
|
|
49
|
+
"data-readonly": dataAttr(readOnly)
|
|
50
|
+
}),
|
|
51
|
+
[disabled, invalid, readOnly]
|
|
52
|
+
);
|
|
53
|
+
const getLabelProps = useMemo(
|
|
54
|
+
() => () => ({
|
|
55
|
+
...parts.label.attrs,
|
|
56
|
+
id: labelId,
|
|
57
|
+
"data-disabled": dataAttr(disabled),
|
|
58
|
+
"data-invalid": dataAttr(invalid),
|
|
59
|
+
"data-readonly": dataAttr(readOnly),
|
|
60
|
+
htmlFor: id
|
|
61
|
+
}),
|
|
62
|
+
[disabled, invalid, readOnly, id, labelId]
|
|
63
|
+
);
|
|
64
|
+
const getControlProps = useMemo(
|
|
65
|
+
() => () => ({
|
|
66
|
+
"aria-describedby": labelIds,
|
|
67
|
+
"aria-invalid": ariaAttr(invalid),
|
|
68
|
+
"aria-required": ariaAttr(required),
|
|
69
|
+
"aria-readonly": ariaAttr(readOnly),
|
|
70
|
+
id,
|
|
71
|
+
required,
|
|
72
|
+
disabled,
|
|
73
|
+
readOnly
|
|
74
|
+
}),
|
|
75
|
+
[labelIds, invalid, required, readOnly, id, disabled]
|
|
76
|
+
);
|
|
77
|
+
const getInputProps = useMemo(
|
|
78
|
+
() => () => ({
|
|
79
|
+
...getControlProps(),
|
|
80
|
+
...parts.input.attrs
|
|
81
|
+
}),
|
|
82
|
+
[getControlProps]
|
|
83
|
+
);
|
|
84
|
+
const getTextareaProps = useMemo(
|
|
85
|
+
() => () => ({
|
|
86
|
+
...getControlProps(),
|
|
87
|
+
...parts.textarea.attrs
|
|
88
|
+
}),
|
|
89
|
+
[getControlProps]
|
|
90
|
+
);
|
|
91
|
+
const getSelectProps = useMemo(
|
|
92
|
+
() => () => ({
|
|
93
|
+
...getControlProps(),
|
|
94
|
+
...parts.select.attrs
|
|
95
|
+
}),
|
|
96
|
+
[getControlProps]
|
|
97
|
+
);
|
|
98
|
+
const getHelperTextProps = useMemo(
|
|
99
|
+
() => () => ({
|
|
100
|
+
id: helperTextId,
|
|
101
|
+
...parts.helperText.attrs
|
|
102
|
+
}),
|
|
103
|
+
[helperTextId]
|
|
104
|
+
);
|
|
105
|
+
const getErrorTextProps = useMemo(
|
|
106
|
+
() => () => ({
|
|
107
|
+
id: errorTextId,
|
|
108
|
+
...parts.errorText.attrs,
|
|
109
|
+
"aria-live": "polite"
|
|
110
|
+
}),
|
|
111
|
+
[errorTextId]
|
|
112
|
+
);
|
|
78
113
|
return {
|
|
79
|
-
ariaDescribedby: labelIds
|
|
114
|
+
ariaDescribedby: labelIds,
|
|
80
115
|
ids: {
|
|
81
116
|
control: id,
|
|
82
117
|
label: labelId,
|
|
@@ -99,7 +134,7 @@ const useField = (props) => {
|
|
|
99
134
|
getErrorTextProps
|
|
100
135
|
};
|
|
101
136
|
};
|
|
102
|
-
const dataAttr = (condition) => condition ? "" : void 0;
|
|
137
|
+
const dataAttr = (condition) => condition ? "true" : void 0;
|
|
103
138
|
const ariaAttr = (condition) => condition ? true : void 0;
|
|
104
139
|
|
|
105
140
|
export { useField };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const useFieldsetContext = require('./use-fieldset-context.cjs');
|
|
7
|
+
|
|
8
|
+
const FieldsetContext = (props) => props.children(useFieldsetContext.useFieldsetContext());
|
|
9
|
+
|
|
10
|
+
exports.FieldsetContext = FieldsetContext;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { UseFieldsetContext } from './use-fieldset-context';
|
|
3
|
+
|
|
4
|
+
export interface FieldsetContextProps {
|
|
5
|
+
children: (context: UseFieldsetContext) => ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const FieldsetContext: (props: FieldsetContextProps) => ReactNode;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { UseFieldsetContext } from './use-fieldset-context';
|
|
3
|
+
|
|
4
|
+
export interface FieldsetContextProps {
|
|
5
|
+
children: (context: UseFieldsetContext) => ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const FieldsetContext: (props: FieldsetContextProps) => ReactNode;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
const react$1 = require('@zag-js/react');
|
|
8
|
+
const react = require('react');
|
|
9
|
+
const factory = require('../factory.cjs');
|
|
10
|
+
const useFieldsetContext = require('./use-fieldset-context.cjs');
|
|
11
|
+
|
|
12
|
+
const FieldsetErrorText = react.forwardRef(
|
|
13
|
+
(props, ref) => {
|
|
14
|
+
const fieldset = useFieldsetContext.useFieldsetContext();
|
|
15
|
+
const mergedProps = react$1.mergeProps(fieldset.getErrorTextProps(), props);
|
|
16
|
+
return fieldset.invalid ? /* @__PURE__ */ jsxRuntime.jsx(factory.ark.span, { ...mergedProps, ref }) : null;
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
FieldsetErrorText.displayName = "FieldsetErrorText";
|
|
20
|
+
|
|
21
|
+
exports.FieldsetErrorText = FieldsetErrorText;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HTMLProps, PolymorphicProps } from '../factory';
|
|
2
|
+
import { ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface FieldsetErrorTextBaseProps extends PolymorphicProps {
|
|
5
|
+
}
|
|
6
|
+
export interface FieldsetErrorTextProps extends HTMLProps<'span'>, FieldsetErrorTextBaseProps {
|
|
7
|
+
}
|
|
8
|
+
export declare const FieldsetErrorText: ForwardRefExoticComponent<FieldsetErrorTextProps & RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HTMLProps, PolymorphicProps } from '../factory';
|
|
2
|
+
import { ForwardRefExoticComponent, RefAttributes } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface FieldsetErrorTextBaseProps extends PolymorphicProps {
|
|
5
|
+
}
|
|
6
|
+
export interface FieldsetErrorTextProps extends HTMLProps<'span'>, FieldsetErrorTextBaseProps {
|
|
7
|
+
}
|
|
8
|
+
export declare const FieldsetErrorText: ForwardRefExoticComponent<FieldsetErrorTextProps & RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { mergeProps } from '@zag-js/react';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import { ark } from '../factory.js';
|
|
6
|
+
import { useFieldsetContext } from './use-fieldset-context.js';
|
|
7
|
+
|
|
8
|
+
const FieldsetErrorText = forwardRef(
|
|
9
|
+
(props, ref) => {
|
|
10
|
+
const fieldset = useFieldsetContext();
|
|
11
|
+
const mergedProps = mergeProps(fieldset.getErrorTextProps(), props);
|
|
12
|
+
return fieldset.invalid ? /* @__PURE__ */ jsx(ark.span, { ...mergedProps, ref }) : null;
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
FieldsetErrorText.displayName = "FieldsetErrorText";
|
|
16
|
+
|
|
17
|
+
export { FieldsetErrorText };
|