@zayne-labs/ui-react 0.9.6 → 0.9.10

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 (84) hide show
  1. package/dist/esm/await-parts-BJ6C-y1f.d.ts +36 -0
  2. package/dist/esm/chunk-BIFY3R2A.js +627 -0
  3. package/dist/esm/chunk-BIFY3R2A.js.map +1 -0
  4. package/dist/esm/chunk-CLGH26AQ.js +337 -0
  5. package/dist/esm/chunk-CLGH26AQ.js.map +1 -0
  6. package/dist/esm/chunk-CWUEUCR5.js +3 -0
  7. package/dist/esm/chunk-CWUEUCR5.js.map +1 -0
  8. package/dist/esm/chunk-EYWTW54R.js +42 -0
  9. package/dist/esm/chunk-EYWTW54R.js.map +1 -0
  10. package/dist/esm/chunk-G5BNZM66.js +32 -0
  11. package/dist/esm/chunk-G5BNZM66.js.map +1 -0
  12. package/dist/esm/{chunk-7LEVEBD2.js → chunk-JC52CA2O.js} +30 -18
  13. package/dist/esm/chunk-JC52CA2O.js.map +1 -0
  14. package/dist/esm/chunk-KLEJZWKY.js +45 -0
  15. package/dist/esm/chunk-KLEJZWKY.js.map +1 -0
  16. package/dist/esm/{chunk-V5DSTESN.js → chunk-M7YXNGT6.js} +3 -3
  17. package/dist/esm/{chunk-V5DSTESN.js.map → chunk-M7YXNGT6.js.map} +1 -1
  18. package/dist/esm/chunk-MT2MQDK2.js +13 -0
  19. package/dist/esm/chunk-MT2MQDK2.js.map +1 -0
  20. package/dist/esm/{chunk-ET4KZBFA.js → chunk-N4274N5K.js} +7 -6
  21. package/dist/esm/chunk-N4274N5K.js.map +1 -0
  22. package/dist/esm/chunk-V5ZPMMIH.js +121 -0
  23. package/dist/esm/chunk-V5ZPMMIH.js.map +1 -0
  24. package/dist/esm/{chunk-2P3P5AXH.js → chunk-Y5VBSXZS.js} +14 -7
  25. package/dist/esm/chunk-Y5VBSXZS.js.map +1 -0
  26. package/dist/esm/{chunk-IUEPHHGO.js → chunk-YO5LJ7ZJ.js} +2 -2
  27. package/dist/esm/{chunk-IUEPHHGO.js.map → chunk-YO5LJ7ZJ.js.map} +1 -1
  28. package/dist/esm/chunk-Z6JJE4G6.js +68 -0
  29. package/dist/esm/chunk-Z6JJE4G6.js.map +1 -0
  30. package/dist/esm/{chunk-DW3FXTFL.js → chunk-ZNL6YLIM.js} +9 -9
  31. package/dist/esm/chunk-ZNL6YLIM.js.map +1 -0
  32. package/dist/esm/chunk-ZSDYJOYB.js +274 -0
  33. package/dist/esm/chunk-ZSDYJOYB.js.map +1 -0
  34. package/dist/esm/components/common/await/index.d.ts +10 -12
  35. package/dist/esm/components/common/await/index.js +5 -23
  36. package/dist/esm/components/common/await/index.js.map +1 -1
  37. package/dist/esm/components/common/error-boundary/index.d.ts +4 -28
  38. package/dist/esm/components/common/error-boundary/index.js +1 -1
  39. package/dist/esm/components/common/for/index.d.ts +7 -21
  40. package/dist/esm/components/common/for/index.js +1 -1
  41. package/dist/esm/components/common/index.d.ts +13 -0
  42. package/dist/esm/components/common/index.js +14 -0
  43. package/dist/esm/components/common/show/index.js +2 -2
  44. package/dist/esm/components/common/slot/index.d.ts +7 -3
  45. package/dist/esm/components/common/slot/index.js +1 -1
  46. package/dist/esm/components/common/suspense-with-boundary/index.d.ts +3 -3
  47. package/dist/esm/components/common/suspense-with-boundary/index.js +2 -11
  48. package/dist/esm/components/common/suspense-with-boundary/index.js.map +1 -1
  49. package/dist/esm/components/common/switch/index.d.ts +5 -5
  50. package/dist/esm/components/common/switch/index.js +3 -40
  51. package/dist/esm/components/common/switch/index.js.map +1 -1
  52. package/dist/esm/components/common/teleport/index.js +1 -29
  53. package/dist/esm/components/common/teleport/index.js.map +1 -1
  54. package/dist/esm/components/ui/card/index.js +4 -43
  55. package/dist/esm/components/ui/card/index.js.map +1 -1
  56. package/dist/esm/components/ui/carousel/index.js +14 -273
  57. package/dist/esm/components/ui/carousel/index.js.map +1 -1
  58. package/dist/esm/components/ui/drag-scroll/index.js +2 -119
  59. package/dist/esm/components/ui/drag-scroll/index.js.map +1 -1
  60. package/dist/esm/components/ui/drop-zone/index.d.ts +8 -181
  61. package/dist/esm/components/ui/drop-zone/index.js +15 -327
  62. package/dist/esm/components/ui/drop-zone/index.js.map +1 -1
  63. package/dist/esm/components/ui/form/index.js +7 -625
  64. package/dist/esm/components/ui/form/index.js.map +1 -1
  65. package/dist/esm/components/ui/index.d.ts +11 -0
  66. package/dist/esm/components/ui/index.js +21 -0
  67. package/dist/esm/drop-zone-parts-CvseSoXA.d.ts +186 -0
  68. package/dist/esm/error-boundary-BD0X61Sg.d.ts +28 -0
  69. package/dist/esm/for-8C6fFbN6.d.ts +21 -0
  70. package/dist/esm/{lib/utils/getSlotMap/index.d.ts → getSlotMap-DTkxtGhd.d.ts} +15 -11
  71. package/dist/esm/lib/utils/{getSlot/index.d.ts → index.d.ts} +1 -0
  72. package/dist/esm/lib/utils/index.js +5 -0
  73. package/dist/esm/lib/utils/index.js.map +1 -0
  74. package/dist/esm/{types-CeWumkhm.d.ts → types-mdfDDNrr.d.ts} +9 -6
  75. package/dist/style.css +1 -1
  76. package/package.json +17 -16
  77. package/dist/esm/chunk-2P3P5AXH.js.map +0 -1
  78. package/dist/esm/chunk-7LEVEBD2.js.map +0 -1
  79. package/dist/esm/chunk-DW3FXTFL.js.map +0 -1
  80. package/dist/esm/chunk-ET4KZBFA.js.map +0 -1
  81. package/dist/esm/lib/utils/getSlot/index.js +0 -4
  82. package/dist/esm/lib/utils/getSlotMap/index.js +0 -4
  83. /package/dist/esm/{lib/utils/getSlot → components/common}/index.js.map +0 -0
  84. /package/dist/esm/{lib/utils/getSlotMap → components/ui}/index.js.map +0 -0
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ import { a as GetSlotComponentProps } from './getSlotMap-DTkxtGhd.js';
3
+ import { E as ErrorBoundaryProps } from './types-mdfDDNrr.js';
4
+ import { SuspenseWithBoundaryProps } from './components/common/suspense-with-boundary/index.js';
5
+
6
+ type RenderPropFn<TValue> = (result: TValue) => React.ReactNode;
7
+ type ChildrenType<TValue> = React.ReactNode | RenderPropFn<TValue>;
8
+ type AwaitRootProps<TValue> = Pick<SuspenseWithBoundaryProps, "errorFallback" | "fallback"> & {
9
+ asChild?: boolean;
10
+ children: ChildrenType<TValue>;
11
+ promise: Promise<TValue>;
12
+ wrapperVariant?: "all" | "none" | "only-errorBoundary" | "only-suspense";
13
+ };
14
+ declare function AwaitRoot<TValue>(props: AwaitRootProps<TValue>): React.JSX.Element;
15
+ type AwaitSuccessProps<TValue = unknown> = GetSlotComponentProps<"default", ChildrenType<TValue>>;
16
+ declare function AwaitSuccess<TPromiseOrValue, TValue = Awaited<TPromiseOrValue>>(props: Pick<AwaitSuccessProps<TValue>, "children">): React.ReactNode;
17
+ type AwaitPendingProps = GetSlotComponentProps<"pending", React.SuspenseProps["fallback"]>;
18
+ declare const AwaitPending: {
19
+ (props: Pick<AwaitPendingProps, "children">): React.ReactNode;
20
+ readonly slotName?: "pending" | undefined;
21
+ readonly slotSymbol?: symbol;
22
+ };
23
+ type AwaitErrorProps = GetSlotComponentProps<"error", ErrorBoundaryProps["fallback"]>;
24
+ declare const AwaitError: {
25
+ (props: Pick<AwaitErrorProps, "children"> & {
26
+ asChild?: boolean;
27
+ }): React.ReactNode;
28
+ readonly slotName?: "error" | undefined;
29
+ readonly slotSymbol?: symbol;
30
+ };
31
+
32
+ declare namespace awaitParts {
33
+ export { AwaitError as Error, AwaitPending as Pending, AwaitRoot as Root, AwaitSuccess as Success };
34
+ }
35
+
36
+ export { AwaitRoot as A, awaitParts as a, AwaitSuccess as b, AwaitPending as c, AwaitError as d };
@@ -0,0 +1,627 @@
1
+ import { dataAttr } from './chunk-DNYM6XGW.js';
2
+ import { cnMerge } from './chunk-OHG7GB7O.js';
3
+ import { getElementList } from './chunk-ZNL6YLIM.js';
4
+ import { getMultipleSlots } from './chunk-YO5LJ7ZJ.js';
5
+ import { slot_parts_exports } from './chunk-Y5VBSXZS.js';
6
+ import { __export } from './chunk-PZ5AY32C.js';
7
+ import * as React2 from 'react';
8
+ import { useMemo, Fragment, useId, useRef, useEffect, createElement } from 'react';
9
+ import { on, toArray } from '@zayne-labs/toolkit-core';
10
+ import { createCustomContext, useToggle, useCallbackRef, ContextError } from '@zayne-labs/toolkit-react';
11
+ import { composeTwoEventHandlers, composeRefs } from '@zayne-labs/toolkit-react/utils';
12
+ import { defineEnum, isString, isObject } from '@zayne-labs/toolkit-type-helpers';
13
+ import { useFormState, useWatch, FormProvider, Controller, useFormContext } from 'react-hook-form';
14
+ export { useFormContext } from 'react-hook-form';
15
+
16
+ var EyeIconClosed = (props) => /* @__PURE__ */ React2.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React2.createElement(
17
+ "path",
18
+ {
19
+ fill: "currentColor",
20
+ d: "M15.175 8.325q.725.725 1.063 1.65t.237 1.9q0 .375-.275.638t-.65.262t-.638-.262t-.262-.638q.125-.65-.075-1.25T13.95 9.6t-1.025-.65t-1.275-.1q-.375 0-.638-.275t-.262-.65t.263-.637t.637-.263q.95-.1 1.875.238t1.65 1.062M12 6q-.475 0-.925.037t-.9.138q-.425.075-.763-.125t-.462-.6t.088-.775t.612-.45q.575-.125 1.163-.175T12 4q3.425 0 6.263 1.8t4.337 4.85q.1.2.15.413t.05.437t-.038.438t-.137.412q-.45 1-1.112 1.875t-1.463 1.6q-.3.275-.7.225t-.65-.4t-.212-.763t.337-.687q.6-.575 1.1-1.25t.875-1.45q-1.25-2.525-3.613-4.012T12 6m0 13q-3.35 0-6.125-1.812T1.5 12.425q-.125-.2-.187-.437T1.25 11.5t.05-.475t.175-.45q.5-1 1.163-1.912T4.15 7L2.075 4.9q-.275-.3-.262-.712T2.1 3.5t.7-.275t.7.275l17 17q.275.275.288.688t-.288.712q-.275.275-.7.275t-.7-.275l-3.5-3.45q-.875.275-1.775.413T12 19M5.55 8.4q-.725.65-1.325 1.425T3.2 11.5q1.25 2.525 3.613 4.013T12 17q.5 0 .975-.062t.975-.138l-.9-.95q-.275.075-.525.113T12 16q-1.875 0-3.188-1.312T7.5 11.5q0-.275.038-.525t.112-.525zm4.2 4.2"
21
+ }
22
+ ));
23
+ var EyeIconOpen = (props) => /* @__PURE__ */ React2.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React2.createElement(
24
+ "path",
25
+ {
26
+ fill: "currentColor",
27
+ d: "M12 16q1.875 0 3.188-1.312T16.5 11.5t-1.312-3.187T12 7T8.813 8.313T7.5 11.5t1.313 3.188T12 16m0-1.8q-1.125 0-1.912-.788T9.3 11.5t.788-1.912T12 8.8t1.913.788t.787 1.912t-.787 1.913T12 14.2m0 4.8q-3.35 0-6.113-1.8t-4.362-4.75q-.125-.225-.187-.462t-.063-.488t.063-.488t.187-.462q1.6-2.95 4.363-4.75T12 4t6.113 1.8t4.362 4.75q.125.225.188.463t.062.487t-.062.488t-.188.462q-1.6 2.95-4.362 4.75T12 19m0-2q2.825 0 5.188-1.487T20.8 11.5q-1.25-2.525-3.613-4.012T12 6T6.813 7.488T3.2 11.5q1.25 2.525 3.613 4.013T12 17"
28
+ }
29
+ ));
30
+
31
+ // src/components/ui/form/utils.ts
32
+ var getFieldErrorMessage = (options) => {
33
+ const { errors, fieldName, type } = options;
34
+ if (!fieldName || !errors || Object.keys(errors).length === 0) return;
35
+ if (type === "root") {
36
+ return errors.root?.[fieldName]?.message;
37
+ }
38
+ const pathParts = fieldName.includes(".") ? fieldName.split(".") : null;
39
+ if (!pathParts) {
40
+ const errorMessage2 = errors[fieldName]?.message;
41
+ return isString(errorMessage2) ? errorMessage2 : null;
42
+ }
43
+ let extractedError = errors;
44
+ for (const part of pathParts) {
45
+ const currentError = extractedError[part];
46
+ if (!isObject(currentError)) break;
47
+ extractedError = currentError;
48
+ }
49
+ const errorMessage = isString(extractedError.message) ? extractedError.message : null;
50
+ return errorMessage;
51
+ };
52
+ var getEyeIcon = (options) => {
53
+ const { classNames, iconType, renderIconProps, withEyeIcon } = options;
54
+ if (!withEyeIcon) {
55
+ return null;
56
+ }
57
+ if (withEyeIcon === true) {
58
+ const defaultIconMap = {
59
+ closed: createElement(EyeIconClosed, {
60
+ className: cnMerge("size-full", classNames?.eyeIcon)
61
+ }),
62
+ open: createElement(EyeIconOpen, {
63
+ className: cnMerge("size-full", classNames?.eyeIcon)
64
+ })
65
+ };
66
+ return defaultIconMap[iconType];
67
+ }
68
+ if (withEyeIcon.renderIcon) {
69
+ return withEyeIcon.renderIcon(renderIconProps);
70
+ }
71
+ if (withEyeIcon[iconType]) {
72
+ return withEyeIcon[iconType];
73
+ }
74
+ return null;
75
+ };
76
+
77
+ // src/components/ui/form/form-context.ts
78
+ var useFormMethodsContext = (options = {}) => {
79
+ const { strict = true } = options;
80
+ const formContext = useFormContext();
81
+ if (strict && !formContext) {
82
+ throw new ContextError(
83
+ `useFormRootContext returned "null". Did you forget to wrap the necessary components within FormRoot?`
84
+ );
85
+ }
86
+ return formContext;
87
+ };
88
+ var [LaxFormRootProvider, useLaxFormRootContext] = createCustomContext({
89
+ hookName: "useLaxFormRootContext",
90
+ name: "LaxFormRootContext",
91
+ providerName: "FormRoot",
92
+ strict: false
93
+ });
94
+ var [StrictFormFieldProvider, useStrictFormFieldContext] = createCustomContext(
95
+ {
96
+ hookName: "useFormFieldContext",
97
+ name: "StrictFormFieldContext",
98
+ providerName: "FormField"
99
+ }
100
+ );
101
+ var [LaxFormFieldProvider, useLaxFormFieldContext] = createCustomContext({
102
+ hookName: "useLaxFormFieldContext",
103
+ name: "LaxFormFieldContext",
104
+ providerName: "FormField",
105
+ strict: false
106
+ });
107
+ var useLaxFormFieldState = (options) => {
108
+ const { control = options?.control } = useFormMethodsContext({ strict: false }) ?? {};
109
+ const { name = options?.name } = useLaxFormFieldContext() ?? {};
110
+ const getFormState = control ? useFormState : () => ({});
111
+ const { disabled, errors } = getFormState({ control, name });
112
+ const errorMessage = getFieldErrorMessage({ errors, fieldName: name, type: "regular" });
113
+ return {
114
+ errors,
115
+ isDisabled: disabled,
116
+ isInvalid: Boolean(errorMessage)
117
+ };
118
+ };
119
+
120
+ // src/components/ui/form/form.tsx
121
+ function FormRoot(props) {
122
+ const { children, className, methods, withEyeIcon, ...restOfProps } = props;
123
+ const formContextValue = useMemo(() => ({ withEyeIcon }), [withEyeIcon]);
124
+ return /* @__PURE__ */ React2.createElement(FormProvider, { ...methods }, /* @__PURE__ */ React2.createElement(LaxFormRootProvider, { value: formContextValue }, /* @__PURE__ */ React2.createElement(
125
+ "form",
126
+ {
127
+ className: cnMerge("flex flex-col", className),
128
+ ...restOfProps,
129
+ "data-scope": "form",
130
+ "data-part": "root",
131
+ "data-slot": "form-root"
132
+ },
133
+ children
134
+ )));
135
+ }
136
+ function FormField(props) {
137
+ const { children, className, name, withWrapper = true } = props;
138
+ const { isDisabled, isInvalid } = useLaxFormFieldState({ name });
139
+ const uniqueId = useId();
140
+ const fieldContextValue = useMemo(
141
+ () => ({
142
+ formDescriptionId: `${name}-(${uniqueId})-form-item-description`,
143
+ formItemId: `${name}-(${uniqueId})-form-item`,
144
+ formMessageId: `${name}-(${uniqueId})-form-item-message`,
145
+ name
146
+ }),
147
+ [name, uniqueId]
148
+ );
149
+ const WrapperElement = withWrapper ? "div" : Fragment;
150
+ const wrapperElementProps = withWrapper && {
151
+ className: cnMerge("flex flex-col", className),
152
+ "data-part": "field",
153
+ "data-scope": "form",
154
+ "data-slot": "form-field",
155
+ /* eslint-disable perfectionist/sort-objects -- order of attributes does not matter */
156
+ "data-disabled": dataAttr(isDisabled),
157
+ "data-invalid": dataAttr(isInvalid)
158
+ /* eslint-enable perfectionist/sort-objects -- order of attributes does not matter */
159
+ };
160
+ return /* @__PURE__ */ React2.createElement(StrictFormFieldProvider, { value: fieldContextValue }, /* @__PURE__ */ React2.createElement(LaxFormFieldProvider, { value: fieldContextValue }, /* @__PURE__ */ React2.createElement(WrapperElement, { ...wrapperElementProps }, children)));
161
+ }
162
+ function FormFieldController(props) {
163
+ const { control } = useFormMethodsContext();
164
+ const { name } = useStrictFormFieldContext();
165
+ const { render, ...restOfProps } = props;
166
+ return /* @__PURE__ */ React2.createElement(Controller, { name, control, render, ...restOfProps });
167
+ }
168
+ function FormFieldControlledField(props) {
169
+ const { name } = props;
170
+ const uniqueId = useId();
171
+ const fieldContextValue = useMemo(
172
+ () => ({
173
+ formDescriptionId: `${name}-(${uniqueId})-form-item-description`,
174
+ formItemId: `${name}-(${uniqueId})-form-item`,
175
+ formMessageId: `${name}-(${uniqueId})-form-item-message`,
176
+ name
177
+ }),
178
+ [name, uniqueId]
179
+ );
180
+ return /* @__PURE__ */ React2.createElement(StrictFormFieldProvider, { value: fieldContextValue }, /* @__PURE__ */ React2.createElement(LaxFormFieldProvider, { value: fieldContextValue }, /* @__PURE__ */ React2.createElement(Controller, { ...props })));
181
+ }
182
+ function FormFieldContext(props) {
183
+ const { children, render } = props;
184
+ const fieldContextValues = useStrictFormFieldContext();
185
+ if (typeof children === "function") {
186
+ return children(fieldContextValues);
187
+ }
188
+ return render(fieldContextValues);
189
+ }
190
+ function FormLabel(props) {
191
+ const { formItemId, name } = useStrictFormFieldContext();
192
+ const { children, className, ...restOfProps } = props;
193
+ const { isDisabled, isInvalid } = useLaxFormFieldState({ name });
194
+ return /* @__PURE__ */ React2.createElement(
195
+ "label",
196
+ {
197
+ "data-scope": "form",
198
+ "data-part": "label",
199
+ "data-slot": "form-label",
200
+ "data-disabled": dataAttr(isDisabled),
201
+ "data-invalid": dataAttr(isInvalid),
202
+ htmlFor: formItemId,
203
+ className,
204
+ ...restOfProps
205
+ },
206
+ children
207
+ );
208
+ }
209
+ function FormInputGroup(props) {
210
+ const { children, className, ...restOfProps } = props;
211
+ const { isDisabled, isInvalid } = useLaxFormFieldState();
212
+ const {
213
+ regularChildren,
214
+ slots: [leftItemSlot, rightItemSlot]
215
+ } = getMultipleSlots(children, [FormInputLeftItem, FormInputRightItem]);
216
+ return /* @__PURE__ */ React2.createElement(
217
+ "div",
218
+ {
219
+ "data-scope": "form",
220
+ "data-part": "input-group",
221
+ "data-slot": "form-input-group",
222
+ "data-invalid": dataAttr(isInvalid),
223
+ "data-disabled": dataAttr(isDisabled),
224
+ className: cnMerge("flex items-center justify-between gap-2", className),
225
+ ...restOfProps
226
+ },
227
+ leftItemSlot,
228
+ regularChildren,
229
+ rightItemSlot
230
+ );
231
+ }
232
+ function FormInputLeftItem(props) {
233
+ const { as: Element = "span", children, className, ...restOfProps } = props;
234
+ return /* @__PURE__ */ React2.createElement(
235
+ Element,
236
+ {
237
+ "data-scope": "form",
238
+ "data-part": "left-item",
239
+ "data-slot": "form-left-item",
240
+ className: cnMerge("inline-flex items-center justify-center", className),
241
+ ...restOfProps
242
+ },
243
+ children
244
+ );
245
+ }
246
+ FormInputLeftItem.slotSymbol = Symbol("input-left-item");
247
+ function FormInputRightItem(props) {
248
+ const { as: Element = "span", children, className, ...restOfProps } = props;
249
+ return /* @__PURE__ */ React2.createElement(
250
+ Element,
251
+ {
252
+ "data-scope": "form",
253
+ "data-part": "right-item",
254
+ "data-slot": "form-right-item",
255
+ className: cnMerge("inline-flex items-center justify-center", className),
256
+ ...restOfProps
257
+ },
258
+ children
259
+ );
260
+ }
261
+ FormInputRightItem.slotSymbol = Symbol("input-right-item");
262
+ var inputTypesWithoutFullWith = /* @__PURE__ */ new Set(["checkbox", "radio"]);
263
+ function FormInputPrimitive(props) {
264
+ const fieldContextValues = useLaxFormFieldContext();
265
+ const formRootContextValues = useLaxFormRootContext();
266
+ const {
267
+ className,
268
+ classNames,
269
+ control,
270
+ fieldState,
271
+ id = fieldContextValues?.formItemId,
272
+ name = fieldContextValues?.name,
273
+ rules,
274
+ type = "text",
275
+ withEyeIcon = formRootContextValues?.withEyeIcon ?? true,
276
+ ...restOfProps
277
+ } = props;
278
+ const fieldStateFromLaxFormField = useLaxFormFieldState({ control, name });
279
+ const { isDisabled, isInvalid } = fieldState ?? fieldStateFromLaxFormField;
280
+ const [isPasswordVisible, toggleVisibility] = useToggle(false);
281
+ const shouldHaveEyeIcon = withEyeIcon && type === "password";
282
+ const WrapperElement = shouldHaveEyeIcon ? FormInputGroup : Fragment;
283
+ const wrapperElementProps = shouldHaveEyeIcon && {
284
+ className: cnMerge("w-full", classNames?.inputGroup, isInvalid && classNames?.error)
285
+ };
286
+ const { register } = useFormMethodsContext({ strict: false }) ?? {};
287
+ const eyeIcon = getEyeIcon({
288
+ classNames,
289
+ iconType: isPasswordVisible ? "closed" : "open",
290
+ renderIconProps: { isPasswordVisible },
291
+ withEyeIcon
292
+ });
293
+ return /* @__PURE__ */ React2.createElement(WrapperElement, { ...wrapperElementProps }, /* @__PURE__ */ React2.createElement(
294
+ "input",
295
+ {
296
+ "data-scope": "form",
297
+ "data-part": "input",
298
+ "data-slot": "form-input",
299
+ "aria-describedby": !isInvalid ? fieldContextValues?.formDescriptionId : `${fieldContextValues?.formDescriptionId} ${fieldContextValues?.formMessageId}`,
300
+ "aria-invalid": dataAttr(isInvalid),
301
+ "data-invalid": dataAttr(isInvalid),
302
+ "data-disabled": dataAttr(isDisabled),
303
+ id,
304
+ name,
305
+ type: type === "password" && isPasswordVisible ? "text" : type,
306
+ className: cnMerge(
307
+ !inputTypesWithoutFullWith.has(type) && "flex w-full",
308
+ `focus-visible:outline-hidden placeholder:text-shadcn-muted-foreground bg-transparent
309
+ text-sm file:border-0 file:bg-transparent disabled:cursor-not-allowed disabled:opacity-50`,
310
+ className,
311
+ classNames?.input,
312
+ type !== "password" && isInvalid && classNames?.error
313
+ ),
314
+ ...Boolean(name) && register?.(name, rules),
315
+ ...restOfProps
316
+ }
317
+ ), shouldHaveEyeIcon && /* @__PURE__ */ React2.createElement(
318
+ FormInputRightItem,
319
+ {
320
+ as: "button",
321
+ type: "button",
322
+ onClick: toggleVisibility,
323
+ className: "size-5 shrink-0 lg:size-6"
324
+ },
325
+ eyeIcon
326
+ ));
327
+ }
328
+ function FormTextAreaPrimitive(props) {
329
+ const fieldContextValues = useLaxFormFieldContext();
330
+ const {
331
+ className,
332
+ classNames,
333
+ control,
334
+ fieldState,
335
+ id = fieldContextValues?.formItemId,
336
+ name = fieldContextValues?.name,
337
+ rules,
338
+ ...restOfProps
339
+ } = props;
340
+ const fieldStateFromLaxFormField = useLaxFormFieldState({ control, name });
341
+ const { isDisabled, isInvalid } = fieldState ?? fieldStateFromLaxFormField;
342
+ const { register } = useFormMethodsContext({ strict: false }) ?? {};
343
+ return /* @__PURE__ */ React2.createElement(
344
+ "textarea",
345
+ {
346
+ "data-scope": "form",
347
+ "data-part": "textarea",
348
+ "data-slot": "form-textarea",
349
+ "aria-describedby": !isInvalid ? fieldContextValues?.formDescriptionId : `${fieldContextValues?.formDescriptionId} ${fieldContextValues?.formMessageId}`,
350
+ "aria-invalid": dataAttr(isInvalid),
351
+ "data-disabled": dataAttr(isDisabled),
352
+ "data-invalid": dataAttr(isInvalid),
353
+ id,
354
+ name,
355
+ className: cnMerge(
356
+ `placeholder:text-shadcn-muted-foreground focus-visible:outline-hidden w-full bg-transparent
357
+ text-sm disabled:cursor-not-allowed disabled:opacity-50`,
358
+ className,
359
+ classNames?.base,
360
+ isInvalid && classNames?.error
361
+ ),
362
+ ...Boolean(name) && register?.(name, rules),
363
+ ...restOfProps
364
+ }
365
+ );
366
+ }
367
+ function FormSelectPrimitive(props) {
368
+ const fieldContextValues = useLaxFormFieldContext();
369
+ const {
370
+ className,
371
+ classNames,
372
+ control,
373
+ fieldState,
374
+ id = fieldContextValues?.formItemId,
375
+ name = fieldContextValues?.name,
376
+ rules,
377
+ ...restOfProps
378
+ } = props;
379
+ const fieldStateFromLaxFormField = useLaxFormFieldState({ control, name });
380
+ const { isDisabled, isInvalid } = fieldState ?? fieldStateFromLaxFormField;
381
+ const { register } = useFormMethodsContext({ strict: false }) ?? {};
382
+ return /* @__PURE__ */ React2.createElement(
383
+ "select",
384
+ {
385
+ defaultValue: "",
386
+ "data-scope": "form",
387
+ "data-part": "select",
388
+ "data-slot": "form-select",
389
+ "aria-describedby": !isInvalid ? fieldContextValues?.formDescriptionId : `${fieldContextValues?.formDescriptionId} ${fieldContextValues?.formMessageId}`,
390
+ "aria-invalid": dataAttr(isInvalid),
391
+ "data-disabled": dataAttr(isDisabled),
392
+ "data-invalid": dataAttr(isInvalid),
393
+ id,
394
+ name,
395
+ className: cnMerge(
396
+ `placeholder:text-shadcn-muted-foreground focus-visible:outline-hidden w-full bg-transparent
397
+ text-sm disabled:cursor-not-allowed disabled:opacity-50`,
398
+ className,
399
+ classNames?.base,
400
+ isInvalid && classNames?.error
401
+ ),
402
+ ...Boolean(name) && register?.(name, rules),
403
+ ...restOfProps
404
+ }
405
+ );
406
+ }
407
+ var InputTypeMap = defineEnum({
408
+ select: FormSelectPrimitive,
409
+ textarea: FormTextAreaPrimitive
410
+ });
411
+ function FormInput(props) {
412
+ const { onBlur, onChange, ref, rules, type, ...restOfProps } = props;
413
+ const { name } = useStrictFormFieldContext();
414
+ const { register } = useFormMethodsContext();
415
+ const SelectedInput = type === "textarea" || type === "select" ? InputTypeMap[type] : FormInputPrimitive;
416
+ const registerProps = name ? register(name, rules) : null;
417
+ return /* @__PURE__ */ React2.createElement(
418
+ SelectedInput,
419
+ {
420
+ type,
421
+ name,
422
+ ...registerProps,
423
+ ...restOfProps,
424
+ ref: composeRefs(registerProps?.ref, ref),
425
+ onChange: composeTwoEventHandlers(registerProps?.onChange, onChange),
426
+ onBlur: composeTwoEventHandlers(registerProps?.onBlur, onBlur)
427
+ }
428
+ );
429
+ }
430
+ function FormTextArea(props) {
431
+ return /* @__PURE__ */ React2.createElement(FormInput, { ...props, type: "textarea" });
432
+ }
433
+ function FormSelect(props) {
434
+ return /* @__PURE__ */ React2.createElement(FormInput, { ...props, type: "select" });
435
+ }
436
+ function FormDescription(props) {
437
+ const { className, ...restOfProps } = props;
438
+ const { formDescriptionId } = useLaxFormFieldContext() ?? {};
439
+ return /* @__PURE__ */ React2.createElement("p", { id: formDescriptionId, className: cnMerge("text-[12px]", className), ...restOfProps });
440
+ }
441
+ var FormErrorMessagePrimitive = (props) => {
442
+ const fieldContextValues = useLaxFormFieldContext();
443
+ const rootContextValues = useFormMethodsContext({ strict: false });
444
+ const {
445
+ children,
446
+ className,
447
+ classNames,
448
+ control = rootContextValues?.control,
449
+ disableErrorAnimation = false,
450
+ disableScrollToErrorField = false,
451
+ fieldName = fieldContextValues?.name,
452
+ render,
453
+ type = "regular"
454
+ } = props;
455
+ const { errors } = useLaxFormFieldState({ control, name: fieldName });
456
+ const { formMessageId } = useLaxFormFieldContext() ?? {};
457
+ const errorParagraphRef = useRef(null);
458
+ const wrapperRef = useRef(null);
459
+ const errorAnimationClass = classNames?.errorMessageAnimation ?? "animate-shake";
460
+ const getErrorElements = useCallbackRef(
461
+ () => wrapperRef.current?.children ?? [errorParagraphRef.current]
462
+ );
463
+ useEffect(() => {
464
+ if (disableErrorAnimation) return;
465
+ if (!errors || Object.keys(errors).length === 0) return;
466
+ const errorMessageElements = getErrorElements();
467
+ if (errorMessageElements.length === 0) return;
468
+ for (const element of errorMessageElements) {
469
+ if (!element) continue;
470
+ element.classList.add(errorAnimationClass);
471
+ const onAnimationEnd = () => element.classList.remove(errorAnimationClass);
472
+ on("animationend", element, onAnimationEnd, { once: true });
473
+ }
474
+ }, [disableErrorAnimation, errorAnimationClass, errors, getErrorElements]);
475
+ useEffect(() => {
476
+ if (disableScrollToErrorField) return;
477
+ if (!errors || Object.keys(errors).length === 0) return;
478
+ const errorMessageElements = getErrorElements();
479
+ const firstErrorElement = errorMessageElements[0];
480
+ if (!firstErrorElement) return;
481
+ const inputField = document.querySelector(`[name='${fieldName}']`);
482
+ const isFocusableInput = inputField?.matches(
483
+ ":is(input, select, textarea, [contenteditable='true'])"
484
+ );
485
+ if (isFocusableInput) return;
486
+ requestAnimationFrame(() => {
487
+ const rect = firstErrorElement.getBoundingClientRect();
488
+ const topWithOffset = rect.top - 100;
489
+ window.scrollTo({
490
+ behavior: "smooth",
491
+ top: window.scrollY + topWithOffset
492
+ });
493
+ });
494
+ }, [disableScrollToErrorField, fieldName, errors, getErrorElements]);
495
+ const fieldErrorMessage = getFieldErrorMessage({ errors, fieldName, type });
496
+ if (!fieldErrorMessage) {
497
+ return null;
498
+ }
499
+ const errorMessageArray = toArray(fieldErrorMessage);
500
+ if (errorMessageArray.length === 0) {
501
+ return null;
502
+ }
503
+ const getRenderProps = (options) => {
504
+ const { index } = options;
505
+ return {
506
+ className: cnMerge(className, classNames?.errorMessage),
507
+ "data-index": index,
508
+ "data-part": "error-message",
509
+ "data-scope": "form",
510
+ "data-slot": "form-error-message",
511
+ id: formMessageId,
512
+ ref: (node) => {
513
+ if (!node || errorParagraphRef.current) return;
514
+ errorParagraphRef.current = node;
515
+ }
516
+ };
517
+ };
518
+ const getRenderState = (options) => {
519
+ const { errorMessage, index } = options;
520
+ return {
521
+ errorMessage,
522
+ errorMessageArray,
523
+ index
524
+ };
525
+ };
526
+ const [ErrorMessageList] = getElementList("base");
527
+ const WrapperComponent = "div";
528
+ const wrapperComponentProps = errorMessageArray.length > 1 && {
529
+ className: cnMerge("flex flex-col", classNames?.container),
530
+ "data-part": "error-message-container",
531
+ "data-scope": "form",
532
+ "data-slot": "form-error-message-container",
533
+ ref: wrapperRef
534
+ };
535
+ const selectedChildren = typeof children === "function" ? children : render;
536
+ return /* @__PURE__ */ React2.createElement(WrapperComponent, { ...wrapperComponentProps }, /* @__PURE__ */ React2.createElement(
537
+ ErrorMessageList,
538
+ {
539
+ each: errorMessageArray,
540
+ render: (errorMessage, index) => {
541
+ return selectedChildren({
542
+ props: getRenderProps({ index }),
543
+ state: getRenderState({ errorMessage, index })
544
+ });
545
+ }
546
+ }
547
+ ));
548
+ };
549
+ function FormErrorMessage(props) {
550
+ const fieldContextValues = useLaxFormFieldContext();
551
+ const { className, errorField = fieldContextValues?.name, type = "regular" } = props;
552
+ const { control } = useFormMethodsContext();
553
+ return /* @__PURE__ */ React2.createElement(
554
+ FormErrorMessagePrimitive,
555
+ {
556
+ control,
557
+ fieldName: errorField,
558
+ type,
559
+ render: ({ props: renderProps, state }) => /* @__PURE__ */ React2.createElement(
560
+ "p",
561
+ {
562
+ key: state.errorMessage,
563
+ ...renderProps,
564
+ className: cnMerge(
565
+ "text-[13px] text-red-600",
566
+ "data-[index=0]:mt-1",
567
+ renderProps.className,
568
+ className
569
+ )
570
+ },
571
+ state.errorMessage
572
+ )
573
+ }
574
+ );
575
+ }
576
+ function FormSubmit(props) {
577
+ const { as: Element = "button", asChild, children, type = "submit", ...restOfProps } = props;
578
+ const Component = asChild ? slot_parts_exports.Root : Element;
579
+ return /* @__PURE__ */ React2.createElement(Component, { "data-part": "submit", "data-scope": "form", "data-slot": "form-submit", type, ...restOfProps }, children);
580
+ }
581
+ function FormSubscribeToFieldValue(props) {
582
+ const fieldContextValues = useLaxFormFieldContext();
583
+ const { children, name = fieldContextValues?.name, render } = props;
584
+ const { control } = useFormMethodsContext();
585
+ const formValue = useWatch({ control, name });
586
+ const fieldProps = { value: formValue };
587
+ const selectedChildren = typeof children === "function" ? children : render;
588
+ const resolvedChildren = selectedChildren(fieldProps);
589
+ return resolvedChildren;
590
+ }
591
+ function FormSubscribeToFormState(props) {
592
+ const fieldContextValues = useLaxFormFieldContext();
593
+ const { children, control, name = fieldContextValues?.name, render } = props;
594
+ const formState = useFormState({ control, name });
595
+ const selectedChildren = typeof children === "function" ? children : render;
596
+ const resolvedChildren = selectedChildren(formState);
597
+ return resolvedChildren;
598
+ }
599
+
600
+ // src/components/ui/form/form-parts.ts
601
+ var form_parts_exports = {};
602
+ __export(form_parts_exports, {
603
+ ControlledField: () => FormFieldControlledField,
604
+ Description: () => FormDescription,
605
+ ErrorMessage: () => FormErrorMessage,
606
+ ErrorMessagePrimitive: () => FormErrorMessagePrimitive,
607
+ Field: () => FormField,
608
+ FieldContext: () => FormFieldContext,
609
+ FieldController: () => FormFieldController,
610
+ Input: () => FormInput,
611
+ InputGroup: () => FormInputGroup,
612
+ InputLeftItem: () => FormInputLeftItem,
613
+ InputPrimitive: () => FormInputPrimitive,
614
+ InputRightItem: () => FormInputRightItem,
615
+ Label: () => FormLabel,
616
+ Root: () => FormRoot,
617
+ Select: () => FormSelect,
618
+ Submit: () => FormSubmit,
619
+ SubscribeToFieldValue: () => FormSubscribeToFieldValue,
620
+ SubscribeToFormState: () => FormSubscribeToFormState,
621
+ TextArea: () => FormTextArea,
622
+ TextAreaPrimitive: () => FormTextAreaPrimitive
623
+ });
624
+
625
+ export { FormDescription, FormErrorMessage, FormErrorMessagePrimitive, FormField, FormFieldContext, FormFieldControlledField, FormFieldController, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormLabel, FormRoot, FormSelect, FormSelectPrimitive, FormSubmit, FormSubscribeToFieldValue, FormSubscribeToFormState, FormTextArea, FormTextAreaPrimitive, form_parts_exports, useStrictFormFieldContext };
626
+ //# sourceMappingURL=chunk-BIFY3R2A.js.map
627
+ //# sourceMappingURL=chunk-BIFY3R2A.js.map