@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.
Files changed (158) hide show
  1. package/README.md +3 -0
  2. package/dist/components/dialog/dialog-root.d.cts +1 -1
  3. package/dist/components/dialog/dialog-root.d.ts +1 -1
  4. package/dist/components/field/use-field.cjs +91 -56
  5. package/dist/components/field/use-field.d.cts +7 -61
  6. package/dist/components/field/use-field.d.ts +7 -61
  7. package/dist/components/field/use-field.js +92 -57
  8. package/dist/components/fieldset/fieldset-context.cjs +10 -0
  9. package/dist/components/fieldset/fieldset-context.d.cts +7 -0
  10. package/dist/components/fieldset/fieldset-context.d.ts +7 -0
  11. package/dist/components/fieldset/fieldset-context.js +6 -0
  12. package/dist/components/fieldset/fieldset-error-text.cjs +21 -0
  13. package/dist/components/fieldset/fieldset-error-text.d.cts +8 -0
  14. package/dist/components/fieldset/fieldset-error-text.d.ts +8 -0
  15. package/dist/components/fieldset/fieldset-error-text.js +17 -0
  16. package/dist/components/fieldset/fieldset-helper-text.cjs +21 -0
  17. package/dist/components/fieldset/fieldset-helper-text.d.cts +8 -0
  18. package/dist/components/fieldset/fieldset-helper-text.d.ts +8 -0
  19. package/dist/components/fieldset/fieldset-helper-text.js +17 -0
  20. package/dist/components/fieldset/fieldset-legend.cjs +19 -0
  21. package/dist/components/fieldset/fieldset-legend.d.cts +8 -0
  22. package/dist/components/fieldset/fieldset-legend.d.ts +8 -0
  23. package/dist/components/fieldset/fieldset-legend.js +15 -0
  24. package/dist/components/fieldset/fieldset-root-provider.cjs +24 -0
  25. package/dist/components/fieldset/fieldset-root-provider.d.cts +13 -0
  26. package/dist/components/fieldset/fieldset-root-provider.d.ts +13 -0
  27. package/dist/components/fieldset/fieldset-root-provider.js +20 -0
  28. package/dist/components/fieldset/fieldset-root.cjs +27 -0
  29. package/dist/components/fieldset/fieldset-root.d.cts +9 -0
  30. package/dist/components/fieldset/fieldset-root.d.ts +9 -0
  31. package/dist/components/fieldset/fieldset-root.js +23 -0
  32. package/dist/components/fieldset/fieldset.anatomy.cjs +17 -0
  33. package/dist/components/fieldset/fieldset.anatomy.d.cts +3 -0
  34. package/dist/components/fieldset/fieldset.anatomy.d.ts +3 -0
  35. package/dist/components/fieldset/fieldset.anatomy.js +12 -0
  36. package/dist/components/fieldset/fieldset.cjs +19 -0
  37. package/dist/components/fieldset/fieldset.d.cts +6 -0
  38. package/dist/components/fieldset/fieldset.d.ts +6 -0
  39. package/dist/components/fieldset/fieldset.js +6 -0
  40. package/dist/components/fieldset/index.cjs +25 -0
  41. package/dist/components/fieldset/index.d.cts +9 -0
  42. package/dist/components/fieldset/index.d.ts +9 -0
  43. package/dist/components/fieldset/index.js +10 -0
  44. package/dist/components/fieldset/use-fieldset-context.cjs +16 -0
  45. package/dist/components/fieldset/use-fieldset-context.d.cts +6 -0
  46. package/dist/components/fieldset/use-fieldset-context.d.ts +6 -0
  47. package/dist/components/fieldset/use-fieldset-context.js +11 -0
  48. package/dist/components/fieldset/use-fieldset.cjs +85 -0
  49. package/dist/components/fieldset/use-fieldset.d.cts +29 -0
  50. package/dist/components/fieldset/use-fieldset.d.ts +29 -0
  51. package/dist/components/fieldset/use-fieldset.js +81 -0
  52. package/dist/components/highlight/highlight.cjs +26 -0
  53. package/dist/components/highlight/highlight.d.cts +8 -0
  54. package/dist/components/highlight/highlight.d.ts +8 -0
  55. package/dist/components/highlight/highlight.js +22 -0
  56. package/dist/components/highlight/index.cjs +11 -0
  57. package/dist/components/highlight/index.d.cts +2 -0
  58. package/dist/components/highlight/index.d.ts +2 -0
  59. package/dist/components/highlight/index.js +2 -0
  60. package/dist/components/highlight/use-highlight.cjs +49 -0
  61. package/dist/components/highlight/use-highlight.d.cts +30 -0
  62. package/dist/components/highlight/use-highlight.d.ts +30 -0
  63. package/dist/components/highlight/use-highlight.js +45 -0
  64. package/dist/components/index.cjs +54 -0
  65. package/dist/components/index.d.cts +3 -0
  66. package/dist/components/index.d.ts +3 -0
  67. package/dist/components/index.js +29 -0
  68. package/dist/components/select/select-hidden-select.cjs +8 -1
  69. package/dist/components/select/select-hidden-select.js +8 -1
  70. package/dist/components/time-picker/index.cjs +39 -0
  71. package/dist/components/time-picker/index.d.cts +17 -0
  72. package/dist/components/time-picker/index.d.ts +17 -0
  73. package/dist/components/time-picker/index.js +17 -0
  74. package/dist/components/time-picker/time-picker-cell.cjs +29 -0
  75. package/dist/components/time-picker/time-picker-cell.d.cts +14 -0
  76. package/dist/components/time-picker/time-picker-cell.d.ts +14 -0
  77. package/dist/components/time-picker/time-picker-cell.js +25 -0
  78. package/dist/components/time-picker/time-picker-clear-trigger.cjs +21 -0
  79. package/dist/components/time-picker/time-picker-clear-trigger.d.cts +8 -0
  80. package/dist/components/time-picker/time-picker-clear-trigger.d.ts +8 -0
  81. package/dist/components/time-picker/time-picker-clear-trigger.js +17 -0
  82. package/dist/components/time-picker/time-picker-column.cjs +22 -0
  83. package/dist/components/time-picker/time-picker-column.d.cts +9 -0
  84. package/dist/components/time-picker/time-picker-column.d.ts +9 -0
  85. package/dist/components/time-picker/time-picker-column.js +18 -0
  86. package/dist/components/time-picker/time-picker-content.cjs +30 -0
  87. package/dist/components/time-picker/time-picker-content.d.cts +8 -0
  88. package/dist/components/time-picker/time-picker-content.d.ts +8 -0
  89. package/dist/components/time-picker/time-picker-content.js +26 -0
  90. package/dist/components/time-picker/time-picker-context.cjs +10 -0
  91. package/dist/components/time-picker/time-picker-context.d.cts +7 -0
  92. package/dist/components/time-picker/time-picker-context.d.ts +7 -0
  93. package/dist/components/time-picker/time-picker-context.js +6 -0
  94. package/dist/components/time-picker/time-picker-control.cjs +21 -0
  95. package/dist/components/time-picker/time-picker-control.d.cts +8 -0
  96. package/dist/components/time-picker/time-picker-control.d.ts +8 -0
  97. package/dist/components/time-picker/time-picker-control.js +17 -0
  98. package/dist/components/time-picker/time-picker-input.cjs +19 -0
  99. package/dist/components/time-picker/time-picker-input.d.cts +8 -0
  100. package/dist/components/time-picker/time-picker-input.d.ts +8 -0
  101. package/dist/components/time-picker/time-picker-input.js +15 -0
  102. package/dist/components/time-picker/time-picker-label.cjs +19 -0
  103. package/dist/components/time-picker/time-picker-label.d.cts +8 -0
  104. package/dist/components/time-picker/time-picker-label.d.ts +8 -0
  105. package/dist/components/time-picker/time-picker-label.js +15 -0
  106. package/dist/components/time-picker/time-picker-positioner.cjs +26 -0
  107. package/dist/components/time-picker/time-picker-positioner.d.cts +8 -0
  108. package/dist/components/time-picker/time-picker-positioner.d.ts +8 -0
  109. package/dist/components/time-picker/time-picker-positioner.js +22 -0
  110. package/dist/components/time-picker/time-picker-root-provider.cjs +30 -0
  111. package/dist/components/time-picker/time-picker-root-provider.d.cts +14 -0
  112. package/dist/components/time-picker/time-picker-root-provider.d.ts +14 -0
  113. package/dist/components/time-picker/time-picker-root-provider.js +26 -0
  114. package/dist/components/time-picker/time-picker-root.cjs +48 -0
  115. package/dist/components/time-picker/time-picker-root.d.cts +11 -0
  116. package/dist/components/time-picker/time-picker-root.d.ts +11 -0
  117. package/dist/components/time-picker/time-picker-root.js +44 -0
  118. package/dist/components/time-picker/time-picker-spacer.cjs +19 -0
  119. package/dist/components/time-picker/time-picker-spacer.d.cts +8 -0
  120. package/dist/components/time-picker/time-picker-spacer.d.ts +8 -0
  121. package/dist/components/time-picker/time-picker-spacer.js +15 -0
  122. package/dist/components/time-picker/time-picker-trigger.cjs +21 -0
  123. package/dist/components/time-picker/time-picker-trigger.d.cts +8 -0
  124. package/dist/components/time-picker/time-picker-trigger.d.ts +8 -0
  125. package/dist/components/time-picker/time-picker-trigger.js +17 -0
  126. package/dist/components/time-picker/time-picker.cjs +33 -0
  127. package/dist/components/time-picker/time-picker.d.cts +14 -0
  128. package/dist/components/time-picker/time-picker.d.ts +14 -0
  129. package/dist/components/time-picker/time-picker.js +13 -0
  130. package/dist/components/time-picker/use-time-picker-column-props-context.cjs +15 -0
  131. package/dist/components/time-picker/use-time-picker-column-props-context.d.cts +7 -0
  132. package/dist/components/time-picker/use-time-picker-column-props-context.d.ts +7 -0
  133. package/dist/components/time-picker/use-time-picker-column-props-context.js +10 -0
  134. package/dist/components/time-picker/use-time-picker-context.cjs +15 -0
  135. package/dist/components/time-picker/use-time-picker-context.d.cts +6 -0
  136. package/dist/components/time-picker/use-time-picker-context.d.ts +6 -0
  137. package/dist/components/time-picker/use-time-picker-context.js +10 -0
  138. package/dist/components/time-picker/use-time-picker.cjs +60 -0
  139. package/dist/components/time-picker/use-time-picker.d.cts +31 -0
  140. package/dist/components/time-picker/use-time-picker.d.ts +31 -0
  141. package/dist/components/time-picker/use-time-picker.js +37 -0
  142. package/dist/components/toast/index.d.cts +1 -1
  143. package/dist/components/toast/index.d.ts +1 -1
  144. package/dist/index.cjs +54 -0
  145. package/dist/index.js +29 -0
  146. package/dist/node_modules/@internationalized/date/dist/CalendarDate.cjs +52 -0
  147. package/dist/node_modules/@internationalized/date/dist/CalendarDate.js +48 -0
  148. package/dist/node_modules/@internationalized/date/dist/manipulation.cjs +108 -0
  149. package/dist/node_modules/@internationalized/date/dist/manipulation.js +99 -0
  150. package/dist/node_modules/@internationalized/date/dist/queries.cjs +13 -0
  151. package/dist/node_modules/@internationalized/date/dist/queries.js +9 -0
  152. package/dist/node_modules/@internationalized/date/dist/string.cjs +38 -0
  153. package/dist/node_modules/@internationalized/date/dist/string.js +33 -0
  154. package/dist/node_modules/@swc/helpers/esm/_check_private_redeclaration.cjs +13 -0
  155. package/dist/node_modules/@swc/helpers/esm/_check_private_redeclaration.js +8 -0
  156. package/dist/node_modules/@swc/helpers/esm/_class_private_field_init.cjs +14 -0
  157. package/dist/node_modules/@swc/helpers/esm/_class_private_field_init.js +9 -0
  158. 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 UseDialogProps, UsePresenceProps {
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 UseDialogProps, UsePresenceProps {
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 { required = false, disabled = false, invalid = false, readOnly = false } = props;
12
- const [hasErrorText, setHasErrorText] = react.useState(false);
13
- const [hasHelperText, setHasHelperText] = react.useState(false);
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
- setHasErrorText(!!doc.getElementById(errorTextId));
26
- setHasHelperText(!!doc.getElementById(helperTextId));
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 getRootProps = () => ({
34
- ...field_anatomy.parts.root.attrs,
35
- role: "group",
36
- "data-disabled": dataAttr(disabled),
37
- "data-invalid": dataAttr(invalid),
38
- "data-readonly": dataAttr(readOnly)
39
- });
40
- const getLabelProps = () => ({
41
- ...field_anatomy.parts.label.attrs,
42
- id: labelId,
43
- "data-disabled": dataAttr(disabled),
44
- "data-invalid": dataAttr(invalid),
45
- "data-readonly": dataAttr(readOnly),
46
- htmlFor: id
47
- });
48
- const labelIds = [];
49
- if (hasErrorText && invalid) labelIds.push(errorTextId);
50
- if (hasHelperText) labelIds.push(helperTextId);
51
- const getControlProps = () => ({
52
- "aria-describedby": labelIds.join(" ") || void 0,
53
- "aria-invalid": ariaAttr(invalid),
54
- "aria-required": ariaAttr(required),
55
- "aria-readonly": ariaAttr(readOnly),
56
- id,
57
- required,
58
- disabled,
59
- readOnly
60
- });
61
- const getInputProps = () => ({
62
- ...getControlProps(),
63
- ...field_anatomy.parts.input.attrs
64
- });
65
- const getTextareaProps = () => ({
66
- ...getControlProps(),
67
- ...field_anatomy.parts.textarea.attrs
68
- });
69
- const getSelectProps = () => ({
70
- ...getControlProps(),
71
- ...field_anatomy.parts.select.attrs
72
- });
73
- const getHelperTextProps = () => ({
74
- id: helperTextId,
75
- ...field_anatomy.parts.helperText.attrs
76
- });
77
- const getErrorTextProps = () => ({
78
- id: errorTextId,
79
- ...field_anatomy.parts.errorText.attrs,
80
- "aria-live": "polite"
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.join(" "),
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
- id: string;
41
- 'data-disabled': Booleanish;
42
- 'data-invalid': Booleanish;
43
- 'data-readonly': Booleanish;
44
- htmlFor: string;
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
- id: string;
41
- 'data-disabled': Booleanish;
42
- 'data-invalid': Booleanish;
43
- 'data-readonly': Booleanish;
44
- htmlFor: string;
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 { useState, useId, useRef, useLayoutEffect } from 'react';
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 { required = false, disabled = false, invalid = false, readOnly = false } = props;
8
- const [hasErrorText, setHasErrorText] = useState(false);
9
- const [hasHelperText, setHasHelperText] = useState(false);
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
- setHasErrorText(!!doc.getElementById(errorTextId));
22
- setHasHelperText(!!doc.getElementById(helperTextId));
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 getRootProps = () => ({
30
- ...parts.root.attrs,
31
- role: "group",
32
- "data-disabled": dataAttr(disabled),
33
- "data-invalid": dataAttr(invalid),
34
- "data-readonly": dataAttr(readOnly)
35
- });
36
- const getLabelProps = () => ({
37
- ...parts.label.attrs,
38
- id: labelId,
39
- "data-disabled": dataAttr(disabled),
40
- "data-invalid": dataAttr(invalid),
41
- "data-readonly": dataAttr(readOnly),
42
- htmlFor: id
43
- });
44
- const labelIds = [];
45
- if (hasErrorText && invalid) labelIds.push(errorTextId);
46
- if (hasHelperText) labelIds.push(helperTextId);
47
- const getControlProps = () => ({
48
- "aria-describedby": labelIds.join(" ") || void 0,
49
- "aria-invalid": ariaAttr(invalid),
50
- "aria-required": ariaAttr(required),
51
- "aria-readonly": ariaAttr(readOnly),
52
- id,
53
- required,
54
- disabled,
55
- readOnly
56
- });
57
- const getInputProps = () => ({
58
- ...getControlProps(),
59
- ...parts.input.attrs
60
- });
61
- const getTextareaProps = () => ({
62
- ...getControlProps(),
63
- ...parts.textarea.attrs
64
- });
65
- const getSelectProps = () => ({
66
- ...getControlProps(),
67
- ...parts.select.attrs
68
- });
69
- const getHelperTextProps = () => ({
70
- id: helperTextId,
71
- ...parts.helperText.attrs
72
- });
73
- const getErrorTextProps = () => ({
74
- id: errorTextId,
75
- ...parts.errorText.attrs,
76
- "aria-live": "polite"
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.join(" "),
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,6 @@
1
+ 'use client';
2
+ import { useFieldsetContext } from './use-fieldset-context.js';
3
+
4
+ const FieldsetContext = (props) => props.children(useFieldsetContext());
5
+
6
+ export { FieldsetContext };
@@ -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 };