@zayne-labs/ui-react 0.9.16 → 0.9.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/await-Fe4LFRKd.js +89 -0
- package/dist/esm/await-Fe4LFRKd.js.map +1 -0
- package/dist/esm/card-DRjs-vtv.js +54 -0
- package/dist/esm/card-DRjs-vtv.js.map +1 -0
- package/dist/esm/carousel-Dznupnx8.js +270 -0
- package/dist/esm/carousel-Dznupnx8.js.map +1 -0
- package/dist/esm/chunk-Cl8Af3a2.js +11 -0
- package/dist/esm/cn-_FbtIrlZ.js +8 -0
- package/dist/esm/cn-_FbtIrlZ.js.map +1 -0
- package/dist/esm/common-BYWy8Q78.js +0 -0
- package/dist/esm/components/common/await/index.d.ts +6 -14
- package/dist/esm/components/common/await/index.js +10 -8
- package/dist/esm/components/common/error-boundary/index.d.ts +2 -17
- package/dist/esm/components/common/error-boundary/index.js +6 -4
- package/dist/esm/components/common/for/index.d.ts +2 -10
- package/dist/esm/components/common/for/index.js +3 -4
- package/dist/esm/components/common/index.d.ts +11 -13
- package/dist/esm/components/common/index.js +13 -14
- package/dist/esm/components/common/show/index.d.ts +2 -26
- package/dist/esm/components/common/show/index.js +7 -5
- package/dist/esm/components/common/slot/index.d.ts +2 -12
- package/dist/esm/components/common/slot/index.js +3 -4
- package/dist/esm/components/common/suspense-with-boundary/index.d.ts +3 -11
- package/dist/esm/components/common/suspense-with-boundary/index.js +4 -5
- package/dist/esm/components/common/switch/index.d.ts +2 -25
- package/dist/esm/components/common/switch/index.js +7 -5
- package/dist/esm/components/common/teleport/index.d.ts +2 -12
- package/dist/esm/components/common/teleport/index.js +3 -4
- package/dist/esm/components/ui/card/index.d.ts +2 -17
- package/dist/esm/components/ui/card/index.js +5 -6
- package/dist/esm/components/ui/carousel/index.d.ts +2 -95
- package/dist/esm/components/ui/carousel/index.js +18 -16
- package/dist/esm/components/ui/drag-scroll/index.d.ts +2 -21
- package/dist/esm/components/ui/drag-scroll/index.js +4 -5
- package/dist/esm/components/ui/drop-zone/index.d.ts +3 -11
- package/dist/esm/components/ui/drop-zone/index.js +18 -16
- package/dist/esm/components/ui/form/index.d.ts +2 -228
- package/dist/esm/components/ui/form/index.js +10 -8
- package/dist/esm/components/ui/index.d.ts +7 -11
- package/dist/esm/components/ui/index.js +19 -20
- package/dist/esm/drag-scroll-BLjij7aI.js +111 -0
- package/dist/esm/drag-scroll-BLjij7aI.js.map +1 -0
- package/dist/esm/drop-zone-_YK9C3Xj.js +313 -0
- package/dist/esm/drop-zone-_YK9C3Xj.js.map +1 -0
- package/dist/esm/error-boundary-B3ycUZ1t.js +126 -0
- package/dist/esm/error-boundary-B3ycUZ1t.js.map +1 -0
- package/dist/esm/for-aTw1TgJo.js +42 -0
- package/dist/esm/for-aTw1TgJo.js.map +1 -0
- package/dist/esm/form-DytCfL6R.js +590 -0
- package/dist/esm/form-DytCfL6R.js.map +1 -0
- package/dist/esm/getSlot-BIcGgBwN.js +85 -0
- package/dist/esm/getSlot-BIcGgBwN.js.map +1 -0
- package/dist/esm/{getSlotMap-DTkxtGhd.d.ts → getSlotMap-DA_uhXqU.d.ts} +17 -16
- package/dist/esm/index--1COprHP.d.ts +32 -0
- package/dist/esm/index-1UCPJf7B.d.ts +19 -0
- package/dist/esm/index-ASoFjmZ6.d.ts +196 -0
- package/dist/esm/index-BC0r1cBF.d.ts +104 -0
- package/dist/esm/index-BSJ30pGj.d.ts +68 -0
- package/dist/esm/{for-BH5FhFuV.d.ts → index-BhpBx8dH.d.ts} +14 -6
- package/dist/esm/index-BuSQsDCX.d.ts +22 -0
- package/dist/esm/index-C0XZoIZD.d.ts +35 -0
- package/dist/esm/index-CTZr4PTO.d.ts +24 -0
- package/dist/esm/index-CqlM1M0j.d.ts +14 -0
- package/dist/esm/index-D-j2Cn1J.d.ts +61 -0
- package/dist/esm/index-DQ1yFGd2.d.ts +229 -0
- package/dist/esm/index-DnaUCh8d.d.ts +15 -0
- package/dist/esm/index-TBkPiipk.d.ts +49 -0
- package/dist/esm/lib/utils/index.d.ts +3 -61
- package/dist/esm/lib/utils/index.js +4 -5
- package/dist/esm/show-BgYrfIxJ.js +41 -0
- package/dist/esm/show-BgYrfIxJ.js.map +1 -0
- package/dist/esm/slot-RXTKo4L7.js +58 -0
- package/dist/esm/slot-RXTKo4L7.js.map +1 -0
- package/dist/esm/suspense-with-boundary-TrQxYRG6.js +21 -0
- package/dist/esm/suspense-with-boundary-TrQxYRG6.js.map +1 -0
- package/dist/esm/switch-PF5xTJfr.js +42 -0
- package/dist/esm/switch-PF5xTJfr.js.map +1 -0
- package/dist/esm/teleport-dlSjWj_t.js +32 -0
- package/dist/esm/teleport-dlSjWj_t.js.map +1 -0
- package/dist/esm/utils-D4YNWj2X.js +89 -0
- package/dist/esm/utils-D4YNWj2X.js.map +1 -0
- package/package.json +4 -3
- package/dist/esm/await-parts-BJ6C-y1f.d.ts +0 -36
- package/dist/esm/chunk-6QJYHPBL.js +0 -45
- package/dist/esm/chunk-6QJYHPBL.js.map +0 -1
- package/dist/esm/chunk-BJ7WR4XW.js +0 -274
- package/dist/esm/chunk-BJ7WR4XW.js.map +0 -1
- package/dist/esm/chunk-CWUEUCR5.js +0 -3
- package/dist/esm/chunk-CWUEUCR5.js.map +0 -1
- package/dist/esm/chunk-D6QZA3UT.js +0 -56
- package/dist/esm/chunk-D6QZA3UT.js.map +0 -1
- package/dist/esm/chunk-EYWTW54R.js +0 -42
- package/dist/esm/chunk-EYWTW54R.js.map +0 -1
- package/dist/esm/chunk-G5BNZM66.js +0 -32
- package/dist/esm/chunk-G5BNZM66.js.map +0 -1
- package/dist/esm/chunk-JC52CA2O.js +0 -113
- package/dist/esm/chunk-JC52CA2O.js.map +0 -1
- package/dist/esm/chunk-M7YXNGT6.js +0 -48
- package/dist/esm/chunk-M7YXNGT6.js.map +0 -1
- package/dist/esm/chunk-MRYXZN2P.js +0 -336
- package/dist/esm/chunk-MRYXZN2P.js.map +0 -1
- package/dist/esm/chunk-MT2MQDK2.js +0 -13
- package/dist/esm/chunk-MT2MQDK2.js.map +0 -1
- package/dist/esm/chunk-N4274N5K.js +0 -50
- package/dist/esm/chunk-N4274N5K.js.map +0 -1
- package/dist/esm/chunk-NXZZXJRH.js +0 -41
- package/dist/esm/chunk-NXZZXJRH.js.map +0 -1
- package/dist/esm/chunk-OHG7GB7O.js +0 -8
- package/dist/esm/chunk-OHG7GB7O.js.map +0 -1
- package/dist/esm/chunk-P5QP73HG.js +0 -626
- package/dist/esm/chunk-P5QP73HG.js.map +0 -1
- package/dist/esm/chunk-PZ5AY32C.js +0 -9
- package/dist/esm/chunk-PZ5AY32C.js.map +0 -1
- package/dist/esm/chunk-V5ZPMMIH.js +0 -121
- package/dist/esm/chunk-V5ZPMMIH.js.map +0 -1
- package/dist/esm/chunk-YO5LJ7ZJ.js +0 -74
- package/dist/esm/chunk-YO5LJ7ZJ.js.map +0 -1
- package/dist/esm/chunk-YSDKXBU7.js +0 -68
- package/dist/esm/chunk-YSDKXBU7.js.map +0 -1
- package/dist/esm/components/common/await/index.js.map +0 -1
- package/dist/esm/components/common/error-boundary/index.js.map +0 -1
- package/dist/esm/components/common/for/index.js.map +0 -1
- package/dist/esm/components/common/index.js.map +0 -1
- package/dist/esm/components/common/show/index.js.map +0 -1
- package/dist/esm/components/common/slot/index.js.map +0 -1
- package/dist/esm/components/common/suspense-with-boundary/index.js.map +0 -1
- package/dist/esm/components/common/switch/index.js.map +0 -1
- package/dist/esm/components/common/teleport/index.js.map +0 -1
- package/dist/esm/components/ui/card/index.js.map +0 -1
- package/dist/esm/components/ui/carousel/index.js.map +0 -1
- package/dist/esm/components/ui/drag-scroll/index.js.map +0 -1
- package/dist/esm/components/ui/drop-zone/index.js.map +0 -1
- package/dist/esm/components/ui/form/index.js.map +0 -1
- package/dist/esm/components/ui/index.js.map +0 -1
- package/dist/esm/drop-zone-parts-CvseSoXA.d.ts +0 -186
- package/dist/esm/error-boundary-BD0X61Sg.d.ts +0 -28
- package/dist/esm/lib/utils/index.js.map +0 -1
- package/dist/esm/types-mdfDDNrr.d.ts +0 -25
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import { getMultipleSlots$1 as getMultipleSlots } from "./getSlot-BIcGgBwN.js";
|
|
3
|
+
import { SlotRoot } from "./slot-RXTKo4L7.js";
|
|
4
|
+
import { getElementList } from "./for-aTw1TgJo.js";
|
|
5
|
+
import { cnMerge } from "./cn-_FbtIrlZ.js";
|
|
6
|
+
import { Fragment, createElement, useEffect, useId, useMemo, useRef } from "react";
|
|
7
|
+
import { dataAttr, on, toArray } from "@zayne-labs/toolkit-core";
|
|
8
|
+
import { defineEnum, isObject } from "@zayne-labs/toolkit-type-helpers";
|
|
9
|
+
import { ContextError, createCustomContext, useCallbackRef, useToggle } from "@zayne-labs/toolkit-react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { composeRefs, composeTwoEventHandlers } from "@zayne-labs/toolkit-react/utils";
|
|
12
|
+
import { Controller, FormProvider, useFormContext, useFormContext as useFormRootContext, useFormState, useWatch } from "react-hook-form";
|
|
13
|
+
|
|
14
|
+
//#region src/components/ui/form/icons.tsx
|
|
15
|
+
const EyeIconClosed = (props) => /* @__PURE__ */ jsx("svg", {
|
|
16
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
17
|
+
width: "1em",
|
|
18
|
+
height: "1em",
|
|
19
|
+
viewBox: "0 0 24 24",
|
|
20
|
+
...props,
|
|
21
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
22
|
+
fill: "currentColor",
|
|
23
|
+
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"
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
const EyeIconOpen = (props) => /* @__PURE__ */ jsx("svg", {
|
|
27
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
28
|
+
width: "1em",
|
|
29
|
+
height: "1em",
|
|
30
|
+
viewBox: "0 0 24 24",
|
|
31
|
+
...props,
|
|
32
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
33
|
+
fill: "currentColor",
|
|
34
|
+
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"
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/components/ui/form/utils.ts
|
|
40
|
+
const getFieldErrorMessage = (options) => {
|
|
41
|
+
const { errors, fieldName, type } = options;
|
|
42
|
+
if (!fieldName || !errors || Object.keys(errors).length === 0) return;
|
|
43
|
+
if (type === "root") return errors.root?.[fieldName]?.message;
|
|
44
|
+
const pathParts = fieldName.includes(".") ? fieldName.split(".") : null;
|
|
45
|
+
if (!pathParts) {
|
|
46
|
+
const errorMessage$1 = errors[fieldName]?.message;
|
|
47
|
+
return errorMessage$1;
|
|
48
|
+
}
|
|
49
|
+
let extractedError = errors;
|
|
50
|
+
for (const part of pathParts) {
|
|
51
|
+
const currentError = extractedError[part];
|
|
52
|
+
if (!isObject(currentError)) break;
|
|
53
|
+
extractedError = currentError;
|
|
54
|
+
}
|
|
55
|
+
const errorMessage = extractedError.message;
|
|
56
|
+
return errorMessage;
|
|
57
|
+
};
|
|
58
|
+
const getEyeIcon = (options) => {
|
|
59
|
+
const { classNames, iconType, renderIconProps, withEyeIcon } = options;
|
|
60
|
+
if (!withEyeIcon) return null;
|
|
61
|
+
if (withEyeIcon === true) {
|
|
62
|
+
const defaultIconMap = {
|
|
63
|
+
closed: createElement(EyeIconClosed, { className: cnMerge("size-full", classNames?.eyeIcon) }),
|
|
64
|
+
open: createElement(EyeIconOpen, { className: cnMerge("size-full", classNames?.eyeIcon) })
|
|
65
|
+
};
|
|
66
|
+
return defaultIconMap[iconType];
|
|
67
|
+
}
|
|
68
|
+
if (withEyeIcon.renderIcon) return withEyeIcon.renderIcon(renderIconProps);
|
|
69
|
+
if (withEyeIcon[iconType]) return withEyeIcon[iconType];
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/components/ui/form/form-context.ts
|
|
75
|
+
const useFormMethodsContext = (options = {}) => {
|
|
76
|
+
const { strict = true } = options;
|
|
77
|
+
const formContext = useFormContext();
|
|
78
|
+
if (strict && !formContext) throw new ContextError(`useFormRootContext returned "null". Did you forget to wrap the necessary components within FormRoot?`);
|
|
79
|
+
return formContext;
|
|
80
|
+
};
|
|
81
|
+
const [LaxFormRootProvider, useLaxFormRootContext] = createCustomContext({
|
|
82
|
+
hookName: "useLaxFormRootContext",
|
|
83
|
+
name: "LaxFormRootContext",
|
|
84
|
+
providerName: "FormRoot",
|
|
85
|
+
strict: false
|
|
86
|
+
});
|
|
87
|
+
const [StrictFormFieldProvider, useStrictFormFieldContext] = createCustomContext({
|
|
88
|
+
hookName: "useFormFieldContext",
|
|
89
|
+
name: "StrictFormFieldContext",
|
|
90
|
+
providerName: "FormField"
|
|
91
|
+
});
|
|
92
|
+
const [LaxFormFieldProvider, useLaxFormFieldContext] = createCustomContext({
|
|
93
|
+
hookName: "useLaxFormFieldContext",
|
|
94
|
+
name: "LaxFormFieldContext",
|
|
95
|
+
providerName: "FormField",
|
|
96
|
+
strict: false
|
|
97
|
+
});
|
|
98
|
+
const useLaxFormFieldState = (options) => {
|
|
99
|
+
const { control = options?.control } = useFormMethodsContext({ strict: false }) ?? {};
|
|
100
|
+
const { name = options?.name } = useLaxFormFieldContext() ?? {};
|
|
101
|
+
const getFormState = control ? useFormState : () => ({});
|
|
102
|
+
const { disabled, errors } = getFormState({
|
|
103
|
+
control,
|
|
104
|
+
name
|
|
105
|
+
});
|
|
106
|
+
const errorMessage = getFieldErrorMessage({
|
|
107
|
+
errors,
|
|
108
|
+
fieldName: name,
|
|
109
|
+
type: "regular"
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
errors,
|
|
113
|
+
isDisabled: disabled,
|
|
114
|
+
isInvalid: Boolean(errorMessage)
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/components/ui/form/form.tsx
|
|
120
|
+
function FormRoot(props) {
|
|
121
|
+
const { children, className, methods, withEyeIcon,...restOfProps } = props;
|
|
122
|
+
const formContextValue = useMemo(() => ({ withEyeIcon }), [withEyeIcon]);
|
|
123
|
+
return /* @__PURE__ */ jsx(FormProvider, {
|
|
124
|
+
...methods,
|
|
125
|
+
children: /* @__PURE__ */ jsx(LaxFormRootProvider, {
|
|
126
|
+
value: formContextValue,
|
|
127
|
+
children: /* @__PURE__ */ jsx("form", {
|
|
128
|
+
className: cnMerge("flex flex-col", className),
|
|
129
|
+
...restOfProps,
|
|
130
|
+
"data-scope": "form",
|
|
131
|
+
"data-part": "root",
|
|
132
|
+
"data-slot": "form-root",
|
|
133
|
+
children
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function FormField(props) {
|
|
139
|
+
const { children, className, name, withWrapper = true } = props;
|
|
140
|
+
const { isDisabled, isInvalid } = useLaxFormFieldState({ name });
|
|
141
|
+
const uniqueId = useId();
|
|
142
|
+
const fieldContextValue = useMemo(() => ({
|
|
143
|
+
formDescriptionId: `${name}-(${uniqueId})-form-item-description`,
|
|
144
|
+
formItemId: `${name}-(${uniqueId})-form-item`,
|
|
145
|
+
formMessageId: `${name}-(${uniqueId})-form-item-message`,
|
|
146
|
+
name
|
|
147
|
+
}), [name, uniqueId]);
|
|
148
|
+
const WrapperElement = withWrapper ? "div" : Fragment;
|
|
149
|
+
const wrapperElementProps = withWrapper && {
|
|
150
|
+
className: cnMerge("flex flex-col", className),
|
|
151
|
+
"data-part": "field",
|
|
152
|
+
"data-scope": "form",
|
|
153
|
+
"data-slot": "form-field",
|
|
154
|
+
"data-disabled": dataAttr(isDisabled),
|
|
155
|
+
"data-invalid": dataAttr(isInvalid)
|
|
156
|
+
};
|
|
157
|
+
return /* @__PURE__ */ jsx(StrictFormFieldProvider, {
|
|
158
|
+
value: fieldContextValue,
|
|
159
|
+
children: /* @__PURE__ */ jsx(LaxFormFieldProvider, {
|
|
160
|
+
value: fieldContextValue,
|
|
161
|
+
children: /* @__PURE__ */ jsx(WrapperElement, {
|
|
162
|
+
...wrapperElementProps,
|
|
163
|
+
children
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function FormFieldController(props) {
|
|
169
|
+
const { control } = useFormMethodsContext();
|
|
170
|
+
const { name } = useStrictFormFieldContext();
|
|
171
|
+
const { render,...restOfProps } = props;
|
|
172
|
+
return /* @__PURE__ */ jsx(Controller, {
|
|
173
|
+
name,
|
|
174
|
+
control,
|
|
175
|
+
render,
|
|
176
|
+
...restOfProps
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function FormFieldControlledField(props) {
|
|
180
|
+
const { name } = props;
|
|
181
|
+
const uniqueId = useId();
|
|
182
|
+
const fieldContextValue = useMemo(() => ({
|
|
183
|
+
formDescriptionId: `${name}-(${uniqueId})-form-item-description`,
|
|
184
|
+
formItemId: `${name}-(${uniqueId})-form-item`,
|
|
185
|
+
formMessageId: `${name}-(${uniqueId})-form-item-message`,
|
|
186
|
+
name
|
|
187
|
+
}), [name, uniqueId]);
|
|
188
|
+
return /* @__PURE__ */ jsx(StrictFormFieldProvider, {
|
|
189
|
+
value: fieldContextValue,
|
|
190
|
+
children: /* @__PURE__ */ jsx(LaxFormFieldProvider, {
|
|
191
|
+
value: fieldContextValue,
|
|
192
|
+
children: /* @__PURE__ */ jsx(Controller, { ...props })
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function FormFieldContext(props) {
|
|
197
|
+
const { children, render } = props;
|
|
198
|
+
const fieldContextValues = useStrictFormFieldContext();
|
|
199
|
+
if (typeof children === "function") return children(fieldContextValues);
|
|
200
|
+
return render(fieldContextValues);
|
|
201
|
+
}
|
|
202
|
+
function FormLabel(props) {
|
|
203
|
+
const { formItemId, name } = useStrictFormFieldContext();
|
|
204
|
+
const { children, className,...restOfProps } = props;
|
|
205
|
+
const { isDisabled, isInvalid } = useLaxFormFieldState({ name });
|
|
206
|
+
return /* @__PURE__ */ jsx("label", {
|
|
207
|
+
"data-scope": "form",
|
|
208
|
+
"data-part": "label",
|
|
209
|
+
"data-slot": "form-label",
|
|
210
|
+
"data-disabled": dataAttr(isDisabled),
|
|
211
|
+
"data-invalid": dataAttr(isInvalid),
|
|
212
|
+
htmlFor: formItemId,
|
|
213
|
+
className,
|
|
214
|
+
...restOfProps,
|
|
215
|
+
children
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function FormInputGroup(props) {
|
|
219
|
+
const { children, className,...restOfProps } = props;
|
|
220
|
+
const { isDisabled, isInvalid } = useLaxFormFieldState();
|
|
221
|
+
const { regularChildren, slots: [leftItemSlot, rightItemSlot] } = getMultipleSlots(children, [FormInputLeftItem, FormInputRightItem]);
|
|
222
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
223
|
+
"data-scope": "form",
|
|
224
|
+
"data-part": "input-group",
|
|
225
|
+
"data-slot": "form-input-group",
|
|
226
|
+
"data-invalid": dataAttr(isInvalid),
|
|
227
|
+
"data-disabled": dataAttr(isDisabled),
|
|
228
|
+
className: cnMerge("flex items-center justify-between gap-2", className),
|
|
229
|
+
...restOfProps,
|
|
230
|
+
children: [
|
|
231
|
+
leftItemSlot,
|
|
232
|
+
regularChildren,
|
|
233
|
+
rightItemSlot
|
|
234
|
+
]
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function FormInputLeftItem(props) {
|
|
238
|
+
const { as: Element = "span", children, className,...restOfProps } = props;
|
|
239
|
+
return /* @__PURE__ */ jsx(Element, {
|
|
240
|
+
"data-scope": "form",
|
|
241
|
+
"data-part": "left-item",
|
|
242
|
+
"data-slot": "form-left-item",
|
|
243
|
+
className: cnMerge("inline-flex items-center justify-center", className),
|
|
244
|
+
...restOfProps,
|
|
245
|
+
children
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
FormInputLeftItem.slotSymbol = Symbol("input-left-item");
|
|
249
|
+
function FormInputRightItem(props) {
|
|
250
|
+
const { as: Element = "span", children, className,...restOfProps } = props;
|
|
251
|
+
return /* @__PURE__ */ jsx(Element, {
|
|
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
|
+
children
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
FormInputRightItem.slotSymbol = Symbol("input-right-item");
|
|
261
|
+
const inputTypesWithoutFullWith = new Set(["checkbox", "radio"]);
|
|
262
|
+
function FormInputPrimitive(props) {
|
|
263
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
264
|
+
const formRootContextValues = useLaxFormRootContext();
|
|
265
|
+
const { className, classNames, control, fieldState, id = fieldContextValues?.formItemId, name = fieldContextValues?.name, rules, type = "text", withEyeIcon = formRootContextValues?.withEyeIcon ?? true,...restOfProps } = props;
|
|
266
|
+
const fieldStateFromLaxFormField = useLaxFormFieldState({
|
|
267
|
+
control,
|
|
268
|
+
name
|
|
269
|
+
});
|
|
270
|
+
const { isDisabled, isInvalid } = fieldState ?? fieldStateFromLaxFormField;
|
|
271
|
+
const [isPasswordVisible, toggleVisibility] = useToggle(false);
|
|
272
|
+
const shouldHaveEyeIcon = withEyeIcon && type === "password";
|
|
273
|
+
const WrapperElement = shouldHaveEyeIcon ? FormInputGroup : Fragment;
|
|
274
|
+
const wrapperElementProps = shouldHaveEyeIcon && { className: cnMerge("w-full", classNames?.inputGroup, isInvalid && classNames?.error) };
|
|
275
|
+
const { register } = useFormMethodsContext({ strict: false }) ?? {};
|
|
276
|
+
const eyeIcon = getEyeIcon({
|
|
277
|
+
classNames,
|
|
278
|
+
iconType: isPasswordVisible ? "closed" : "open",
|
|
279
|
+
renderIconProps: { isPasswordVisible },
|
|
280
|
+
withEyeIcon
|
|
281
|
+
});
|
|
282
|
+
return /* @__PURE__ */ jsxs(WrapperElement, {
|
|
283
|
+
...wrapperElementProps,
|
|
284
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
285
|
+
"data-scope": "form",
|
|
286
|
+
"data-part": "input",
|
|
287
|
+
"data-slot": "form-input",
|
|
288
|
+
"aria-describedby": !isInvalid ? fieldContextValues?.formDescriptionId : `${fieldContextValues?.formDescriptionId} ${fieldContextValues?.formMessageId}`,
|
|
289
|
+
"aria-invalid": dataAttr(isInvalid),
|
|
290
|
+
"data-invalid": dataAttr(isInvalid),
|
|
291
|
+
"data-disabled": dataAttr(isDisabled),
|
|
292
|
+
id,
|
|
293
|
+
name,
|
|
294
|
+
type: type === "password" && isPasswordVisible ? "text" : type,
|
|
295
|
+
className: cnMerge(!inputTypesWithoutFullWith.has(type) && "flex w-full", `focus-visible:outline-hidden placeholder:text-shadcn-muted-foreground bg-transparent
|
|
296
|
+
text-sm file:border-0 file:bg-transparent disabled:cursor-not-allowed disabled:opacity-50`, className, classNames?.input, type !== "password" && isInvalid && classNames?.error),
|
|
297
|
+
...Boolean(name) && register?.(name, rules),
|
|
298
|
+
...restOfProps
|
|
299
|
+
}), shouldHaveEyeIcon && /* @__PURE__ */ jsx(FormInputRightItem, {
|
|
300
|
+
as: "button",
|
|
301
|
+
type: "button",
|
|
302
|
+
onClick: toggleVisibility,
|
|
303
|
+
className: "size-5 shrink-0 lg:size-6",
|
|
304
|
+
children: eyeIcon
|
|
305
|
+
})]
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function FormTextAreaPrimitive(props) {
|
|
309
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
310
|
+
const { className, classNames, control, fieldState, id = fieldContextValues?.formItemId, name = fieldContextValues?.name, rules,...restOfProps } = props;
|
|
311
|
+
const fieldStateFromLaxFormField = useLaxFormFieldState({
|
|
312
|
+
control,
|
|
313
|
+
name
|
|
314
|
+
});
|
|
315
|
+
const { isDisabled, isInvalid } = fieldState ?? fieldStateFromLaxFormField;
|
|
316
|
+
const { register } = useFormMethodsContext({ strict: false }) ?? {};
|
|
317
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
318
|
+
"data-scope": "form",
|
|
319
|
+
"data-part": "textarea",
|
|
320
|
+
"data-slot": "form-textarea",
|
|
321
|
+
"aria-describedby": !isInvalid ? fieldContextValues?.formDescriptionId : `${fieldContextValues?.formDescriptionId} ${fieldContextValues?.formMessageId}`,
|
|
322
|
+
"aria-invalid": dataAttr(isInvalid),
|
|
323
|
+
"data-disabled": dataAttr(isDisabled),
|
|
324
|
+
"data-invalid": dataAttr(isInvalid),
|
|
325
|
+
id,
|
|
326
|
+
name,
|
|
327
|
+
className: cnMerge(`placeholder:text-shadcn-muted-foreground focus-visible:outline-hidden w-full bg-transparent
|
|
328
|
+
text-sm disabled:cursor-not-allowed disabled:opacity-50`, className, classNames?.base, isInvalid && classNames?.error),
|
|
329
|
+
...Boolean(name) && register?.(name, rules),
|
|
330
|
+
...restOfProps
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function FormSelectPrimitive(props) {
|
|
334
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
335
|
+
const { className, classNames, control, fieldState, id = fieldContextValues?.formItemId, name = fieldContextValues?.name, rules,...restOfProps } = props;
|
|
336
|
+
const fieldStateFromLaxFormField = useLaxFormFieldState({
|
|
337
|
+
control,
|
|
338
|
+
name
|
|
339
|
+
});
|
|
340
|
+
const { isDisabled, isInvalid } = fieldState ?? fieldStateFromLaxFormField;
|
|
341
|
+
const { register } = useFormMethodsContext({ strict: false }) ?? {};
|
|
342
|
+
return /* @__PURE__ */ jsx("select", {
|
|
343
|
+
defaultValue: "",
|
|
344
|
+
"data-scope": "form",
|
|
345
|
+
"data-part": "select",
|
|
346
|
+
"data-slot": "form-select",
|
|
347
|
+
"aria-describedby": !isInvalid ? fieldContextValues?.formDescriptionId : `${fieldContextValues?.formDescriptionId} ${fieldContextValues?.formMessageId}`,
|
|
348
|
+
"aria-invalid": dataAttr(isInvalid),
|
|
349
|
+
"data-disabled": dataAttr(isDisabled),
|
|
350
|
+
"data-invalid": dataAttr(isInvalid),
|
|
351
|
+
id,
|
|
352
|
+
name,
|
|
353
|
+
className: cnMerge(`placeholder:text-shadcn-muted-foreground focus-visible:outline-hidden w-full bg-transparent
|
|
354
|
+
text-sm disabled:cursor-not-allowed disabled:opacity-50`, className, classNames?.base, isInvalid && classNames?.error),
|
|
355
|
+
...Boolean(name) && register?.(name, rules),
|
|
356
|
+
...restOfProps
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
const InputTypeMap = defineEnum({
|
|
360
|
+
select: FormSelectPrimitive,
|
|
361
|
+
textarea: FormTextAreaPrimitive
|
|
362
|
+
});
|
|
363
|
+
function FormInput(props) {
|
|
364
|
+
const { onBlur, onChange, ref, rules, type,...restOfProps } = props;
|
|
365
|
+
const { name } = useStrictFormFieldContext();
|
|
366
|
+
const { register } = useFormMethodsContext();
|
|
367
|
+
const SelectedInput = type === "textarea" || type === "select" ? InputTypeMap[type] : FormInputPrimitive;
|
|
368
|
+
const registerProps = name ? register(name, rules) : null;
|
|
369
|
+
return /* @__PURE__ */ jsx(SelectedInput, {
|
|
370
|
+
type,
|
|
371
|
+
name,
|
|
372
|
+
...registerProps,
|
|
373
|
+
...restOfProps,
|
|
374
|
+
ref: composeRefs(registerProps?.ref, ref),
|
|
375
|
+
onChange: composeTwoEventHandlers(registerProps?.onChange, onChange),
|
|
376
|
+
onBlur: composeTwoEventHandlers(registerProps?.onBlur, onBlur)
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function FormTextArea(props) {
|
|
380
|
+
return /* @__PURE__ */ jsx(FormInput, {
|
|
381
|
+
...props,
|
|
382
|
+
type: "textarea"
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function FormSelect(props) {
|
|
386
|
+
return /* @__PURE__ */ jsx(FormInput, {
|
|
387
|
+
...props,
|
|
388
|
+
type: "select"
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function FormDescription(props) {
|
|
392
|
+
const { className,...restOfProps } = props;
|
|
393
|
+
const { formDescriptionId } = useLaxFormFieldContext() ?? {};
|
|
394
|
+
return /* @__PURE__ */ jsx("p", {
|
|
395
|
+
id: formDescriptionId,
|
|
396
|
+
className: cnMerge("text-[12px]", className),
|
|
397
|
+
...restOfProps
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const FormErrorMessagePrimitive = (props) => {
|
|
401
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
402
|
+
const rootContextValues = useFormMethodsContext({ strict: false });
|
|
403
|
+
const { children, className, classNames, control = rootContextValues?.control, disableErrorAnimation = false, disableScrollToErrorField = false, fieldName = fieldContextValues?.name, render, type = "regular" } = props;
|
|
404
|
+
const { errors } = useLaxFormFieldState({
|
|
405
|
+
control,
|
|
406
|
+
name: fieldName
|
|
407
|
+
});
|
|
408
|
+
const { formMessageId } = useLaxFormFieldContext() ?? {};
|
|
409
|
+
const errorParagraphRef = useRef(null);
|
|
410
|
+
const wrapperRef = useRef(null);
|
|
411
|
+
const errorAnimationClass = classNames?.errorMessageAnimation ?? "animate-shake";
|
|
412
|
+
const getErrorElements = useCallbackRef(() => wrapperRef.current?.children ?? [errorParagraphRef.current]);
|
|
413
|
+
useEffect(() => {
|
|
414
|
+
if (disableErrorAnimation) return;
|
|
415
|
+
if (!errors || Object.keys(errors).length === 0) return;
|
|
416
|
+
const errorMessageElements = getErrorElements();
|
|
417
|
+
if (errorMessageElements.length === 0) return;
|
|
418
|
+
for (const element of errorMessageElements) {
|
|
419
|
+
if (!element) continue;
|
|
420
|
+
element.classList.add(errorAnimationClass);
|
|
421
|
+
const onAnimationEnd = () => element.classList.remove(errorAnimationClass);
|
|
422
|
+
on("animationend", element, onAnimationEnd, { once: true });
|
|
423
|
+
}
|
|
424
|
+
}, [
|
|
425
|
+
disableErrorAnimation,
|
|
426
|
+
errorAnimationClass,
|
|
427
|
+
errors,
|
|
428
|
+
getErrorElements
|
|
429
|
+
]);
|
|
430
|
+
useEffect(() => {
|
|
431
|
+
if (disableScrollToErrorField) return;
|
|
432
|
+
if (!errors || Object.keys(errors).length === 0) return;
|
|
433
|
+
const errorMessageElements = getErrorElements();
|
|
434
|
+
const firstErrorElement = errorMessageElements[0];
|
|
435
|
+
if (!firstErrorElement) return;
|
|
436
|
+
const inputField = document.querySelector(`[name='${fieldName}']`);
|
|
437
|
+
const isFocusableInput = inputField?.matches(":is(input, select, textarea, [contenteditable='true'])");
|
|
438
|
+
if (isFocusableInput) return;
|
|
439
|
+
requestAnimationFrame(() => {
|
|
440
|
+
const rect = firstErrorElement.getBoundingClientRect();
|
|
441
|
+
const topWithOffset = rect.top - 100;
|
|
442
|
+
window.scrollTo({
|
|
443
|
+
behavior: "smooth",
|
|
444
|
+
top: window.scrollY + topWithOffset
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
}, [
|
|
448
|
+
disableScrollToErrorField,
|
|
449
|
+
fieldName,
|
|
450
|
+
errors,
|
|
451
|
+
getErrorElements
|
|
452
|
+
]);
|
|
453
|
+
const fieldErrorMessage = getFieldErrorMessage({
|
|
454
|
+
errors,
|
|
455
|
+
fieldName,
|
|
456
|
+
type
|
|
457
|
+
});
|
|
458
|
+
if (!fieldErrorMessage) return null;
|
|
459
|
+
const errorMessageArray = toArray(fieldErrorMessage);
|
|
460
|
+
if (errorMessageArray.length === 0) return null;
|
|
461
|
+
const getRenderProps = (options) => {
|
|
462
|
+
const { index } = options;
|
|
463
|
+
return {
|
|
464
|
+
className: cnMerge(className, classNames?.errorMessage),
|
|
465
|
+
"data-index": index,
|
|
466
|
+
"data-part": "error-message",
|
|
467
|
+
"data-scope": "form",
|
|
468
|
+
"data-slot": "form-error-message",
|
|
469
|
+
id: formMessageId,
|
|
470
|
+
ref: (node) => {
|
|
471
|
+
if (!node || errorParagraphRef.current) return;
|
|
472
|
+
errorParagraphRef.current = node;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
const getRenderState = (options) => {
|
|
477
|
+
const { errorMessage, index } = options;
|
|
478
|
+
return {
|
|
479
|
+
errorMessage,
|
|
480
|
+
errorMessageArray,
|
|
481
|
+
index
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
const [ErrorMessageList] = getElementList("base");
|
|
485
|
+
const WrapperComponent = "div";
|
|
486
|
+
const wrapperComponentProps = errorMessageArray.length > 1 && {
|
|
487
|
+
className: cnMerge("flex flex-col", classNames?.container),
|
|
488
|
+
"data-part": "error-message-container",
|
|
489
|
+
"data-scope": "form",
|
|
490
|
+
"data-slot": "form-error-message-container",
|
|
491
|
+
ref: wrapperRef
|
|
492
|
+
};
|
|
493
|
+
const selectedChildren = typeof children === "function" ? children : render;
|
|
494
|
+
return /* @__PURE__ */ jsx(WrapperComponent, {
|
|
495
|
+
...wrapperComponentProps,
|
|
496
|
+
children: /* @__PURE__ */ jsx(ErrorMessageList, {
|
|
497
|
+
each: errorMessageArray,
|
|
498
|
+
render: (errorMessage, index) => {
|
|
499
|
+
return selectedChildren({
|
|
500
|
+
props: getRenderProps({ index }),
|
|
501
|
+
state: getRenderState({
|
|
502
|
+
errorMessage,
|
|
503
|
+
index
|
|
504
|
+
})
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
})
|
|
508
|
+
});
|
|
509
|
+
};
|
|
510
|
+
function FormErrorMessage(props) {
|
|
511
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
512
|
+
const { className, errorField = fieldContextValues?.name, type = "regular" } = props;
|
|
513
|
+
const { control } = useFormMethodsContext();
|
|
514
|
+
return /* @__PURE__ */ jsx(FormErrorMessagePrimitive, {
|
|
515
|
+
control,
|
|
516
|
+
fieldName: errorField,
|
|
517
|
+
type,
|
|
518
|
+
render: ({ props: renderProps, state }) => /* @__PURE__ */ jsx("p", {
|
|
519
|
+
...renderProps,
|
|
520
|
+
className: cnMerge("text-[13px] text-red-600", "data-[index=0]:mt-1", renderProps.className, className),
|
|
521
|
+
children: state.errorMessage
|
|
522
|
+
}, state.errorMessage)
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
function FormSubmit(props) {
|
|
526
|
+
const { as: Element = "button", asChild, children, type = "submit",...restOfProps } = props;
|
|
527
|
+
const Component$1 = asChild ? SlotRoot : Element;
|
|
528
|
+
return /* @__PURE__ */ jsx(Component$1, {
|
|
529
|
+
"data-part": "submit",
|
|
530
|
+
"data-scope": "form",
|
|
531
|
+
"data-slot": "form-submit",
|
|
532
|
+
type,
|
|
533
|
+
...restOfProps,
|
|
534
|
+
children
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
function FormSubscribeToFieldValue(props) {
|
|
538
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
539
|
+
const { children, name = fieldContextValues?.name, render } = props;
|
|
540
|
+
const { control } = useFormMethodsContext();
|
|
541
|
+
const formValue = useWatch({
|
|
542
|
+
control,
|
|
543
|
+
name
|
|
544
|
+
});
|
|
545
|
+
const fieldProps = { value: formValue };
|
|
546
|
+
const selectedChildren = typeof children === "function" ? children : render;
|
|
547
|
+
const resolvedChildren = selectedChildren(fieldProps);
|
|
548
|
+
return resolvedChildren;
|
|
549
|
+
}
|
|
550
|
+
function FormSubscribeToFormState(props) {
|
|
551
|
+
const fieldContextValues = useLaxFormFieldContext();
|
|
552
|
+
const { children, control, name = fieldContextValues?.name, render } = props;
|
|
553
|
+
const formState = useFormState({
|
|
554
|
+
control,
|
|
555
|
+
name
|
|
556
|
+
});
|
|
557
|
+
const selectedChildren = typeof children === "function" ? children : render;
|
|
558
|
+
const resolvedChildren = selectedChildren(formState);
|
|
559
|
+
return resolvedChildren;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/components/ui/form/form-parts.ts
|
|
564
|
+
var form_parts_exports = {};
|
|
565
|
+
__export(form_parts_exports, {
|
|
566
|
+
ControlledField: () => FormFieldControlledField,
|
|
567
|
+
Description: () => FormDescription,
|
|
568
|
+
ErrorMessage: () => FormErrorMessage,
|
|
569
|
+
ErrorMessagePrimitive: () => FormErrorMessagePrimitive,
|
|
570
|
+
Field: () => FormField,
|
|
571
|
+
FieldContext: () => FormFieldContext,
|
|
572
|
+
FieldController: () => FormFieldController,
|
|
573
|
+
Input: () => FormInput,
|
|
574
|
+
InputGroup: () => FormInputGroup,
|
|
575
|
+
InputLeftItem: () => FormInputLeftItem,
|
|
576
|
+
InputPrimitive: () => FormInputPrimitive,
|
|
577
|
+
InputRightItem: () => FormInputRightItem,
|
|
578
|
+
Label: () => FormLabel,
|
|
579
|
+
Root: () => FormRoot,
|
|
580
|
+
Select: () => FormSelect,
|
|
581
|
+
Submit: () => FormSubmit,
|
|
582
|
+
SubscribeToFieldValue: () => FormSubscribeToFieldValue,
|
|
583
|
+
SubscribeToFormState: () => FormSubscribeToFormState,
|
|
584
|
+
TextArea: () => FormTextArea,
|
|
585
|
+
TextAreaPrimitive: () => FormTextAreaPrimitive
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
//#endregion
|
|
589
|
+
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, useFormRootContext, useStrictFormFieldContext };
|
|
590
|
+
//# sourceMappingURL=form-DytCfL6R.js.map
|