@zayne-labs/ui-react 0.0.3
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/For-BmvZgK9J.d.ts +17 -0
- package/dist/esm/chunk-7TYZVYD6.js +42 -0
- package/dist/esm/chunk-7TYZVYD6.js.map +1 -0
- package/dist/esm/chunk-ABOA7YOO.js +9 -0
- package/dist/esm/chunk-ABOA7YOO.js.map +1 -0
- package/dist/esm/common/For/index.d.ts +9 -0
- package/dist/esm/common/For/index.js +3 -0
- package/dist/esm/common/For/index.js.map +1 -0
- package/dist/esm/common/Show/index.d.ts +22 -0
- package/dist/esm/common/Show/index.js +38 -0
- package/dist/esm/common/Show/index.js.map +1 -0
- package/dist/esm/common/Slot/index.d.ts +8 -0
- package/dist/esm/common/Slot/index.js +47 -0
- package/dist/esm/common/Slot/index.js.map +1 -0
- package/dist/esm/common/Switch/index.d.ts +20 -0
- package/dist/esm/common/Switch/index.js +26 -0
- package/dist/esm/common/Switch/index.js.map +1 -0
- package/dist/esm/common/Teleport/index.d.ts +12 -0
- package/dist/esm/common/Teleport/index.js +31 -0
- package/dist/esm/common/Teleport/index.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/ui/carousel/index.d.ts +96 -0
- package/dist/esm/ui/carousel/index.js +263 -0
- package/dist/esm/ui/carousel/index.js.map +1 -0
- package/dist/esm/ui/drag-scroll/index.d.ts +25 -0
- package/dist/esm/ui/drag-scroll/index.js +104 -0
- package/dist/esm/ui/drag-scroll/index.js.map +1 -0
- package/dist/esm/ui/drop-zone/index.d.ts +655 -0
- package/dist/esm/ui/drop-zone/index.js +125 -0
- package/dist/esm/ui/drop-zone/index.js.map +1 -0
- package/dist/esm/ui/form/index.d.ts +159 -0
- package/dist/esm/ui/form/index.js +336 -0
- package/dist/esm/ui/form/index.js.map +1 -0
- package/package.json +113 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { cnMerge } from '../../chunk-ABOA7YOO.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import { handleFileValidation } from '@zayne-labs/toolkit-core';
|
|
5
|
+
import { useToggle, useCallbackRef } from '@zayne-labs/toolkit-react';
|
|
6
|
+
import { isObject, isFunction } from '@zayne-labs/toolkit-type-helpers';
|
|
7
|
+
|
|
8
|
+
var useDropZone = (props) => {
|
|
9
|
+
const inputRef = useRef(null);
|
|
10
|
+
const {
|
|
11
|
+
allowedFileTypes,
|
|
12
|
+
children,
|
|
13
|
+
classNames,
|
|
14
|
+
disableInbuiltValidation,
|
|
15
|
+
existingFiles,
|
|
16
|
+
extraInputProps,
|
|
17
|
+
extraRootProps,
|
|
18
|
+
onUpload,
|
|
19
|
+
onUploadError,
|
|
20
|
+
onUploadSuccess,
|
|
21
|
+
ref,
|
|
22
|
+
validationSettings,
|
|
23
|
+
validator
|
|
24
|
+
// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Can be undefined
|
|
25
|
+
} = props ?? {};
|
|
26
|
+
const [isDragging, toggleIsDragging] = useToggle(false);
|
|
27
|
+
const [acceptedFiles, setAcceptedFiles] = useState([]);
|
|
28
|
+
const handleFileUpload = useCallbackRef(
|
|
29
|
+
(event) => {
|
|
30
|
+
if (event.type === "drop") {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
toggleIsDragging(false);
|
|
33
|
+
}
|
|
34
|
+
const fileList = event.type === "drop" ? event.dataTransfer.files : event.target.files;
|
|
35
|
+
if (fileList === null) {
|
|
36
|
+
console.warn("No file selected");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const inbuiltValidatedFilesArray = !disableInbuiltValidation ? handleFileValidation({
|
|
40
|
+
existingFileArray: existingFiles,
|
|
41
|
+
newFileList: fileList,
|
|
42
|
+
onError: onUploadError,
|
|
43
|
+
onSuccess: onUploadSuccess,
|
|
44
|
+
validationSettings: isObject(validationSettings) ? { ...validationSettings, allowedFileTypes } : {}
|
|
45
|
+
}) : [];
|
|
46
|
+
const validatorFnFileArray = validator ? validator({ existingFileArray: existingFiles, newFileList: fileList }) : [];
|
|
47
|
+
const validFilesArray = [...inbuiltValidatedFilesArray, ...validatorFnFileArray];
|
|
48
|
+
if (validFilesArray.length === 0) return;
|
|
49
|
+
setAcceptedFiles(validFilesArray);
|
|
50
|
+
onUpload?.({ acceptedFiles: validFilesArray, event });
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
const handleDragOver = (event) => {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
toggleIsDragging(true);
|
|
56
|
+
};
|
|
57
|
+
const handleDragLeave = (event) => {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
toggleIsDragging(false);
|
|
60
|
+
};
|
|
61
|
+
const getRenderProps = () => ({ acceptedFiles, inputRef, isDragging });
|
|
62
|
+
const getChildren = () => isFunction(children) ? children(getRenderProps()) : children;
|
|
63
|
+
const getRootProps = () => ({
|
|
64
|
+
...extraRootProps,
|
|
65
|
+
className: cnMerge(
|
|
66
|
+
"relative isolate flex flex-col",
|
|
67
|
+
extraRootProps?.className,
|
|
68
|
+
classNames?.base,
|
|
69
|
+
isDragging && ["opacity-60", classNames?.activeDrag]
|
|
70
|
+
),
|
|
71
|
+
"data-active-drag": isDragging,
|
|
72
|
+
"data-part": "root",
|
|
73
|
+
"data-scope": "dropzone",
|
|
74
|
+
onDragEnter: handleDragOver,
|
|
75
|
+
onDragLeave: handleDragLeave,
|
|
76
|
+
onDragOver: handleDragOver,
|
|
77
|
+
onDrop: handleFileUpload
|
|
78
|
+
});
|
|
79
|
+
const refCallback = useCallbackRef((node) => {
|
|
80
|
+
inputRef.current = node;
|
|
81
|
+
if (!ref) return;
|
|
82
|
+
if (isFunction(ref)) {
|
|
83
|
+
return ref(node);
|
|
84
|
+
}
|
|
85
|
+
ref.current = node;
|
|
86
|
+
});
|
|
87
|
+
const getInputProps = () => ({
|
|
88
|
+
...extraInputProps,
|
|
89
|
+
accept: allowedFileTypes ? allowedFileTypes.join(", ") : extraInputProps?.accept,
|
|
90
|
+
className: cnMerge(
|
|
91
|
+
"absolute inset-0 z-[100] cursor-pointer opacity-0",
|
|
92
|
+
extraInputProps?.className,
|
|
93
|
+
classNames?.input
|
|
94
|
+
),
|
|
95
|
+
"data-part": "input",
|
|
96
|
+
"data-scope": "dropzone",
|
|
97
|
+
onChange: (event) => {
|
|
98
|
+
handleFileUpload(event);
|
|
99
|
+
extraInputProps?.onChange?.(event);
|
|
100
|
+
},
|
|
101
|
+
ref: refCallback,
|
|
102
|
+
type: "file"
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
getChildren,
|
|
106
|
+
getInputProps,
|
|
107
|
+
getRenderProps,
|
|
108
|
+
getRootProps,
|
|
109
|
+
handleDragLeave,
|
|
110
|
+
handleDragOver,
|
|
111
|
+
handleFileUpload,
|
|
112
|
+
isDragging,
|
|
113
|
+
ref
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/components/ui/drop-zone/drop-zone.tsx
|
|
118
|
+
function DropZone(props) {
|
|
119
|
+
const api = useDropZone(props);
|
|
120
|
+
return /* @__PURE__ */ React.createElement("div", { ...api.getRootProps() }, /* @__PURE__ */ React.createElement("input", { ...api.getInputProps() }), api.getChildren());
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { DropZone, useDropZone };
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
|
125
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/ui/drop-zone/useDropZone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx"],"names":[],"mappings":";;;;;;;AAiDa,IAAA,WAAA,GAAc,CAAC,KAA4B,KAAA;AACvD,EAAM,MAAA,QAAA,GAAW,OAAyB,IAAI,CAAA;AAE9C,EAAM,MAAA;AAAA,IACL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GAAA,CAAI,aACN,CAAA;AAEF","file":"index.js","sourcesContent":["\"use client\";\n\nimport { cnMerge } from \"@/lib/utils/cn\";\nimport { type FileValidationOptions, handleFileValidation } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef, useToggle } from \"@zayne-labs/toolkit-react\";\nimport type { InferProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction, isObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type RefCallback, useRef, useState } from \"react\";\n\ntype RenderProps = {\n\tacceptedFiles: File[];\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n\tisDragging: boolean;\n};\n\nexport type UseDropZoneProps = {\n\tallowedFileTypes?: string[];\n\n\tchildren?: React.ReactNode | ((props: RenderProps) => React.ReactNode);\n\n\tclassNames?: { activeDrag?: string; base?: string; input?: string };\n\n\tdisableInbuiltValidation?: boolean;\n\n\texistingFiles?: File[];\n\n\textraInputProps?: Omit<InferProps<\"input\">, \"ref\">;\n\n\textraRootProps?: InferProps<\"div\">;\n\n\tonUpload?: (details: {\n\t\tacceptedFiles: File[];\n\t\tevent: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLDivElement>;\n\t}) => void;\n\n\tonUploadError?: FileValidationOptions[\"onError\"];\n\n\tonUploadSuccess?: FileValidationOptions[\"onSuccess\"];\n\n\tref?: React.Ref<HTMLInputElement>;\n\n\tvalidationSettings?: {\n\t\tdisallowDuplicates?: boolean;\n\t\tfileLimit?: number;\n\t\tmaxFileSize?: number;\n\t};\n\tvalidator?: (context: { existingFileArray: File[] | undefined; newFileList: FileList }) => File[];\n};\n\nexport const useDropZone = (props: UseDropZoneProps) => {\n\tconst inputRef = useRef<HTMLInputElement>(null);\n\n\tconst {\n\t\tallowedFileTypes,\n\t\tchildren,\n\t\tclassNames,\n\t\tdisableInbuiltValidation,\n\t\texistingFiles,\n\t\textraInputProps,\n\t\textraRootProps,\n\t\tonUpload,\n\t\tonUploadError,\n\t\tonUploadSuccess,\n\t\tref,\n\t\tvalidationSettings,\n\t\tvalidator,\n\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Can be undefined\n\t} = props ?? {};\n\n\tconst [isDragging, toggleIsDragging] = useToggle(false);\n\n\tconst [acceptedFiles, setAcceptedFiles] = useState<File[]>([]);\n\n\tconst handleFileUpload = useCallbackRef(\n\t\t(event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLDivElement>) => {\n\t\t\tif (event.type === \"drop\") {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttoggleIsDragging(false);\n\t\t\t}\n\n\t\t\tconst fileList =\n\t\t\t\tevent.type === \"drop\"\n\t\t\t\t\t? (event as React.DragEvent).dataTransfer.files\n\t\t\t\t\t: (event as React.ChangeEvent<HTMLInputElement>).target.files;\n\n\t\t\tif (fileList === null) {\n\t\t\t\tconsole.warn(\"No file selected\");\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst inbuiltValidatedFilesArray = !disableInbuiltValidation\n\t\t\t\t? handleFileValidation({\n\t\t\t\t\t\texistingFileArray: existingFiles,\n\t\t\t\t\t\tnewFileList: fileList,\n\t\t\t\t\t\tonError: onUploadError,\n\t\t\t\t\t\tonSuccess: onUploadSuccess,\n\t\t\t\t\t\tvalidationSettings: isObject(validationSettings)\n\t\t\t\t\t\t\t? { ...validationSettings, allowedFileTypes }\n\t\t\t\t\t\t\t: {},\n\t\t\t\t\t})\n\t\t\t\t: [];\n\n\t\t\tconst validatorFnFileArray = validator\n\t\t\t\t? validator({ existingFileArray: existingFiles, newFileList: fileList })\n\t\t\t\t: [];\n\n\t\t\tconst validFilesArray = [...inbuiltValidatedFilesArray, ...validatorFnFileArray];\n\n\t\t\tif (validFilesArray.length === 0) return;\n\n\t\t\tsetAcceptedFiles(validFilesArray);\n\n\t\t\tonUpload?.({ acceptedFiles: validFilesArray, event });\n\t\t}\n\t);\n\n\tconst handleDragOver = (event: React.DragEvent<HTMLDivElement>) => {\n\t\tevent.preventDefault();\n\t\ttoggleIsDragging(true);\n\t};\n\n\tconst handleDragLeave = (event: React.DragEvent<HTMLDivElement>) => {\n\t\tevent.preventDefault();\n\t\ttoggleIsDragging(false);\n\t};\n\n\tconst getRenderProps = () => ({ acceptedFiles, inputRef, isDragging }) satisfies RenderProps;\n\n\tconst getChildren = () => (isFunction(children) ? children(getRenderProps()) : children);\n\n\tconst getRootProps = () => ({\n\t\t...extraRootProps,\n\t\tclassName: cnMerge(\n\t\t\t\"relative isolate flex flex-col\",\n\t\t\textraRootProps?.className,\n\t\t\tclassNames?.base,\n\t\t\tisDragging && [\"opacity-60\", classNames?.activeDrag]\n\t\t),\n\t\t\"data-active-drag\": isDragging,\n\t\t\"data-part\": \"root\",\n\t\t\"data-scope\": \"dropzone\",\n\t\tonDragEnter: handleDragOver,\n\t\tonDragLeave: handleDragLeave,\n\t\tonDragOver: handleDragOver,\n\t\tonDrop: handleFileUpload,\n\t});\n\n\tconst refCallback: RefCallback<HTMLInputElement> = useCallbackRef((node) => {\n\t\tinputRef.current = node;\n\n\t\tif (!ref) return;\n\n\t\tif (isFunction(ref)) {\n\t\t\treturn ref(node);\n\t\t}\n\n\t\tref.current = node;\n\t});\n\n\tconst getInputProps = () => ({\n\t\t...extraInputProps,\n\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : extraInputProps?.accept,\n\t\tclassName: cnMerge(\n\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\textraInputProps?.className,\n\t\t\tclassNames?.input\n\t\t),\n\t\t\"data-part\": \"input\",\n\t\t\"data-scope\": \"dropzone\",\n\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\thandleFileUpload(event);\n\t\t\textraInputProps?.onChange?.(event);\n\t\t},\n\t\tref: refCallback,\n\t\ttype: \"file\",\n\t});\n\n\treturn {\n\t\tgetChildren,\n\t\tgetInputProps,\n\t\tgetRenderProps,\n\t\tgetRootProps,\n\t\thandleDragLeave,\n\t\thandleDragOver,\n\t\thandleFileUpload,\n\t\tisDragging,\n\t\tref,\n\t};\n};\n","import * as React from \"react\";\n\nimport { type UseDropZoneProps, useDropZone } from \"./useDropZone\";\n\nfunction DropZone(props: UseDropZoneProps) {\n\tconst api = useDropZone(props);\n\n\treturn (\n\t\t<div {...api.getRootProps()}>\n\t\t\t<input {...api.getInputProps()} />\n\n\t\t\t{api.getChildren()}\n\t\t</div>\n\t);\n}\n\nexport { DropZone };\n"]}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { InferProps, PolymorphicProps, DiscriminatedRenderProps } from '@zayne-labs/toolkit-react/utils';
|
|
3
|
+
import { UseFormReturn, Control, FormState, RegisterOptions, ControllerProps, FieldPath, ControllerRenderProps, ControllerFieldState, UseFormStateReturn } from 'react-hook-form';
|
|
4
|
+
export { Controller as ControllerPrimitive } from 'react-hook-form';
|
|
5
|
+
|
|
6
|
+
type FieldValues = Record<string, unknown>;
|
|
7
|
+
type FormRootProps<TValues extends FieldValues> = react.ComponentPropsWithoutRef<"form"> & {
|
|
8
|
+
children: react.ReactNode;
|
|
9
|
+
methods: UseFormReturn<TValues>;
|
|
10
|
+
};
|
|
11
|
+
type ContextValue = {
|
|
12
|
+
name: string;
|
|
13
|
+
uniqueId: string;
|
|
14
|
+
};
|
|
15
|
+
declare const useStrictFormItemContext: () => ContextValue;
|
|
16
|
+
declare function FormRoot<TValues extends FieldValues>(props: FormRootProps<TValues>): react.JSX.Element;
|
|
17
|
+
type FormItemProps<TControl, TFieldValues extends FieldValues> = (TControl extends Control<infer TValues> ? {
|
|
18
|
+
control?: never;
|
|
19
|
+
name: keyof TValues;
|
|
20
|
+
} : {
|
|
21
|
+
control?: Control<TFieldValues>;
|
|
22
|
+
name: keyof TFieldValues;
|
|
23
|
+
}) & {
|
|
24
|
+
children: react.ReactNode;
|
|
25
|
+
className?: string;
|
|
26
|
+
withWrapper?: boolean;
|
|
27
|
+
};
|
|
28
|
+
declare function FormItem<TControl, TFieldValues extends FieldValues = FieldValues>(props: FormItemProps<TControl, TFieldValues>): react.JSX.Element;
|
|
29
|
+
type FormItemContextProps = DiscriminatedRenderProps<(contextValue: ContextValue) => react.ReactNode>;
|
|
30
|
+
declare function FormItemContext(props: FormItemContextProps): react.ReactNode;
|
|
31
|
+
declare function FormLabel(props: InferProps<"label">): react.JSX.Element;
|
|
32
|
+
declare function FormInputGroup(props: react.ComponentPropsWithRef<"div">): react.JSX.Element;
|
|
33
|
+
type FormSideItemProps = {
|
|
34
|
+
children?: react.ReactNode;
|
|
35
|
+
className?: string;
|
|
36
|
+
};
|
|
37
|
+
declare function FormInputLeftItem<TElement extends react.ElementType = "span">(props: PolymorphicProps<TElement, FormSideItemProps>): react.JSX.Element;
|
|
38
|
+
declare namespace FormInputLeftItem {
|
|
39
|
+
var slot: symbol;
|
|
40
|
+
}
|
|
41
|
+
declare function FormInputRightItem<TElement extends react.ElementType = "span">(props: PolymorphicProps<TElement, FormSideItemProps>): react.JSX.Element;
|
|
42
|
+
declare namespace FormInputRightItem {
|
|
43
|
+
var slot: symbol;
|
|
44
|
+
}
|
|
45
|
+
type FormInputPrimitiveProps<TFieldValues extends FieldValues = FieldValues> = Omit<react.ComponentPropsWithRef<"input">, "children"> & {
|
|
46
|
+
classNames?: {
|
|
47
|
+
error?: string;
|
|
48
|
+
eyeIcon?: string;
|
|
49
|
+
input?: string;
|
|
50
|
+
inputGroup?: string;
|
|
51
|
+
};
|
|
52
|
+
name?: keyof TFieldValues;
|
|
53
|
+
withEyeIcon?: boolean;
|
|
54
|
+
} & ({
|
|
55
|
+
control: Control<TFieldValues>;
|
|
56
|
+
formState?: never;
|
|
57
|
+
} | {
|
|
58
|
+
control?: never;
|
|
59
|
+
formState?: FormState<TFieldValues>;
|
|
60
|
+
});
|
|
61
|
+
declare function FormInputPrimitive<TFieldValues extends FieldValues>(props: FormInputPrimitiveProps<TFieldValues>): react.JSX.Element;
|
|
62
|
+
declare function FormInput(props: Omit<FormInputPrimitiveProps, "control" | "formState" | "name" | "ref"> & {
|
|
63
|
+
rules?: RegisterOptions;
|
|
64
|
+
}): react.JSX.Element;
|
|
65
|
+
type FormTextAreaPrimitiveProps<TFieldValues extends FieldValues = FieldValues> = react.ComponentPropsWithRef<"textarea"> & {
|
|
66
|
+
errorClassName?: string;
|
|
67
|
+
name?: keyof TFieldValues;
|
|
68
|
+
} & ({
|
|
69
|
+
control: Control<TFieldValues>;
|
|
70
|
+
formState?: never;
|
|
71
|
+
} | {
|
|
72
|
+
control?: never;
|
|
73
|
+
formState?: FormState<TFieldValues>;
|
|
74
|
+
});
|
|
75
|
+
declare function FormTextAreaPrimitive<TFieldValues extends FieldValues>(props: FormTextAreaPrimitiveProps<TFieldValues>): react.JSX.Element;
|
|
76
|
+
declare function FormTextArea(props: Omit<FormTextAreaPrimitiveProps, "control" | "formState" | "id" | "name" | "ref"> & {
|
|
77
|
+
rules?: RegisterOptions;
|
|
78
|
+
}): react.JSX.Element;
|
|
79
|
+
type FormControllerProps<TFieldValues> = Omit<ControllerProps<FieldValues, FieldPath<FieldValues>>, "control" | "name" | "render"> & {
|
|
80
|
+
render: (props: {
|
|
81
|
+
field: Omit<ControllerRenderProps, "value"> & {
|
|
82
|
+
value: TFieldValues;
|
|
83
|
+
};
|
|
84
|
+
fieldState: ControllerFieldState;
|
|
85
|
+
formState: UseFormStateReturn<FieldValues>;
|
|
86
|
+
}) => react.ReactElement;
|
|
87
|
+
};
|
|
88
|
+
declare function FormController<TFieldValues = never>(props: FormControllerProps<TFieldValues>): react.JSX.Element;
|
|
89
|
+
type FormErrorRenderProps = {
|
|
90
|
+
className: string;
|
|
91
|
+
"data-index": number;
|
|
92
|
+
"data-part": string;
|
|
93
|
+
"data-scope": string;
|
|
94
|
+
onAnimationEnd?: react.ReactEventHandler<HTMLElement>;
|
|
95
|
+
};
|
|
96
|
+
type FormErrorRenderPropState = {
|
|
97
|
+
errorMessage: string;
|
|
98
|
+
errorMessageArray: string[];
|
|
99
|
+
index: number;
|
|
100
|
+
};
|
|
101
|
+
type FormErrorMessagePrimitiveProps<TFieldValues extends FieldValues> = {
|
|
102
|
+
className?: string;
|
|
103
|
+
classNames?: {
|
|
104
|
+
container?: string;
|
|
105
|
+
errorMessage?: string;
|
|
106
|
+
errorMessageAnimation?: string;
|
|
107
|
+
};
|
|
108
|
+
control: Control<TFieldValues>;
|
|
109
|
+
render: (context: {
|
|
110
|
+
props: FormErrorRenderProps;
|
|
111
|
+
state: FormErrorRenderPropState;
|
|
112
|
+
}) => react.ReactNode;
|
|
113
|
+
withAnimationOnInvalid?: boolean;
|
|
114
|
+
} & ({
|
|
115
|
+
errorField: keyof TFieldValues;
|
|
116
|
+
type?: "regular";
|
|
117
|
+
} | {
|
|
118
|
+
errorField: string;
|
|
119
|
+
type: "root";
|
|
120
|
+
});
|
|
121
|
+
declare function FormErrorMessagePrimitive<TFieldValues extends FieldValues>(props: Extract<FormErrorMessagePrimitiveProps<TFieldValues>, {
|
|
122
|
+
type?: "regular";
|
|
123
|
+
}>): react.ReactNode;
|
|
124
|
+
declare function FormErrorMessagePrimitive<TFieldValues extends FieldValues>(props: Extract<FormErrorMessagePrimitiveProps<TFieldValues>, {
|
|
125
|
+
type: "root";
|
|
126
|
+
}>): react.ReactNode;
|
|
127
|
+
type FormErrorMessageProps<TControl, TFieldValues extends FieldValues> = (TControl extends Control<infer TValues> ? {
|
|
128
|
+
className?: string;
|
|
129
|
+
control?: never;
|
|
130
|
+
errorField?: keyof TValues;
|
|
131
|
+
type?: "regular";
|
|
132
|
+
} : {
|
|
133
|
+
className?: string;
|
|
134
|
+
control?: Control<TFieldValues>;
|
|
135
|
+
errorField?: keyof TFieldValues;
|
|
136
|
+
type?: "regular";
|
|
137
|
+
}) | {
|
|
138
|
+
className?: string;
|
|
139
|
+
control?: never;
|
|
140
|
+
errorField: string;
|
|
141
|
+
type: "root";
|
|
142
|
+
};
|
|
143
|
+
declare function FormErrorMessage<TControl, TFieldValues extends FieldValues = FieldValues>(props: FormErrorMessageProps<TControl, TFieldValues>): react.JSX.Element;
|
|
144
|
+
declare const Root: typeof FormRoot;
|
|
145
|
+
declare const Item: typeof FormItem;
|
|
146
|
+
declare const ItemContext: typeof FormItemContext;
|
|
147
|
+
declare const Label: typeof FormLabel;
|
|
148
|
+
declare const ErrorMessagePrimitive: typeof FormErrorMessagePrimitive;
|
|
149
|
+
declare const ErrorMessage: typeof FormErrorMessage;
|
|
150
|
+
declare const Input: typeof FormInput;
|
|
151
|
+
declare const InputPrimitive: typeof FormInputPrimitive;
|
|
152
|
+
declare const InputGroup: typeof FormInputGroup;
|
|
153
|
+
declare const InputLeftItem: typeof FormInputLeftItem;
|
|
154
|
+
declare const InputRightItem: typeof FormInputRightItem;
|
|
155
|
+
declare const TextAreaPrimitive: typeof FormTextAreaPrimitive;
|
|
156
|
+
declare const TextArea: typeof FormTextArea;
|
|
157
|
+
declare const Controller: typeof FormController;
|
|
158
|
+
|
|
159
|
+
export { Controller, ErrorMessage, ErrorMessagePrimitive, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormItem, FormLabel, FormRoot, Input, InputGroup, InputLeftItem, InputPrimitive, InputRightItem, Item, ItemContext, Label, Root, TextArea, TextAreaPrimitive, useStrictFormItemContext as useFormItemContext };
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { getElementList } from '../../chunk-7TYZVYD6.js';
|
|
2
|
+
import { cnMerge } from '../../chunk-ABOA7YOO.js';
|
|
3
|
+
import * as React2 from 'react';
|
|
4
|
+
import { useId, useMemo, Fragment, useRef, useEffect } from 'react';
|
|
5
|
+
import { toArray } from '@zayne-labs/toolkit-core';
|
|
6
|
+
import { createCustomContext, useToggle } from '@zayne-labs/toolkit-react';
|
|
7
|
+
import { getSlotElement, getOtherChildren } from '@zayne-labs/toolkit-react/utils';
|
|
8
|
+
import { FormProvider, useFormState, useFormContext, Controller } from 'react-hook-form';
|
|
9
|
+
export { Controller as ControllerPrimitive } from 'react-hook-form';
|
|
10
|
+
|
|
11
|
+
// src/components/icons/EyeIcon.tsx
|
|
12
|
+
var EyeIconInvisible = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement(
|
|
13
|
+
"path",
|
|
14
|
+
{
|
|
15
|
+
fill: "currentColor",
|
|
16
|
+
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"
|
|
17
|
+
}
|
|
18
|
+
));
|
|
19
|
+
var EyeIconVisible = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement(
|
|
20
|
+
"path",
|
|
21
|
+
{
|
|
22
|
+
fill: "currentColor",
|
|
23
|
+
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"
|
|
24
|
+
}
|
|
25
|
+
));
|
|
26
|
+
var [StrictFormItemProvider, useStrictFormItemContext] = createCustomContext({
|
|
27
|
+
hookName: "useStrictFormItemContext",
|
|
28
|
+
providerName: "StrictFormItemProvider"
|
|
29
|
+
});
|
|
30
|
+
var [LaxFormItemProvider, useLaxFormItemContext] = createCustomContext({
|
|
31
|
+
hookName: "useLaxFormItemContext",
|
|
32
|
+
providerName: "LaxFormItemProvider",
|
|
33
|
+
strict: false
|
|
34
|
+
});
|
|
35
|
+
function FormRoot(props) {
|
|
36
|
+
const { children, className, methods, ...restOfProps } = props;
|
|
37
|
+
return /* @__PURE__ */ React2.createElement(FormProvider, { ...methods }, /* @__PURE__ */ React2.createElement(
|
|
38
|
+
"form",
|
|
39
|
+
{
|
|
40
|
+
className: cnMerge("flex flex-col", className),
|
|
41
|
+
...restOfProps,
|
|
42
|
+
"data-scope": "form",
|
|
43
|
+
"data-part": "root"
|
|
44
|
+
},
|
|
45
|
+
children
|
|
46
|
+
));
|
|
47
|
+
}
|
|
48
|
+
function FormItem(props) {
|
|
49
|
+
const { children, className, name, withWrapper = true } = props;
|
|
50
|
+
const uniqueId = useId();
|
|
51
|
+
const value = useMemo(
|
|
52
|
+
() => ({ name: String(name), uniqueId: `${String(name)}-(${uniqueId})` }),
|
|
53
|
+
[name, uniqueId]
|
|
54
|
+
);
|
|
55
|
+
const WrapperElement = withWrapper ? "div" : Fragment;
|
|
56
|
+
const wrapperElementProps = withWrapper && {
|
|
57
|
+
className: cnMerge("flex flex-col", className),
|
|
58
|
+
"data-part": "item",
|
|
59
|
+
"data-scope": "form"
|
|
60
|
+
};
|
|
61
|
+
return /* @__PURE__ */ React2.createElement(StrictFormItemProvider, { value }, /* @__PURE__ */ React2.createElement(LaxFormItemProvider, { value }, /* @__PURE__ */ React2.createElement(WrapperElement, { ...wrapperElementProps }, children)));
|
|
62
|
+
}
|
|
63
|
+
function FormItemContext(props) {
|
|
64
|
+
const { children, render } = props;
|
|
65
|
+
const contextValues = useStrictFormItemContext();
|
|
66
|
+
if (typeof children === "function") {
|
|
67
|
+
return children(contextValues);
|
|
68
|
+
}
|
|
69
|
+
return render(contextValues);
|
|
70
|
+
}
|
|
71
|
+
function FormLabel(props) {
|
|
72
|
+
const { uniqueId } = useStrictFormItemContext();
|
|
73
|
+
const { children, className, ...restOfProps } = props;
|
|
74
|
+
return /* @__PURE__ */ React2.createElement("label", { "data-scope": "form", "data-part": "label", htmlFor: uniqueId, className, ...restOfProps }, children);
|
|
75
|
+
}
|
|
76
|
+
function FormInputGroup(props) {
|
|
77
|
+
const { children, className, ...restOfProps } = props;
|
|
78
|
+
const LeftItemSlot = getSlotElement(children, FormInputLeftItem);
|
|
79
|
+
const RightItemSlot = getSlotElement(children, FormInputRightItem);
|
|
80
|
+
const otherChildren = getOtherChildren(children, [FormInputLeftItem, FormInputRightItem]);
|
|
81
|
+
return /* @__PURE__ */ React2.createElement(
|
|
82
|
+
"div",
|
|
83
|
+
{
|
|
84
|
+
"data-scope": "form",
|
|
85
|
+
"data-part": "input-group",
|
|
86
|
+
className: cnMerge("flex items-center justify-between gap-2", className),
|
|
87
|
+
...restOfProps
|
|
88
|
+
},
|
|
89
|
+
LeftItemSlot,
|
|
90
|
+
otherChildren,
|
|
91
|
+
RightItemSlot
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
function FormInputLeftItem(props) {
|
|
95
|
+
const { as: Element = "span", children, className, ...restOfProps } = props;
|
|
96
|
+
return /* @__PURE__ */ React2.createElement(
|
|
97
|
+
Element,
|
|
98
|
+
{
|
|
99
|
+
"data-scope": "form",
|
|
100
|
+
"data-part": "left-item",
|
|
101
|
+
className: cnMerge("inline-flex items-center justify-center", className),
|
|
102
|
+
...restOfProps
|
|
103
|
+
},
|
|
104
|
+
children
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
FormInputLeftItem.slot = Symbol.for("leftItem");
|
|
108
|
+
function FormInputRightItem(props) {
|
|
109
|
+
const { as: Element = "span", children, className, ...restOfProps } = props;
|
|
110
|
+
return /* @__PURE__ */ React2.createElement(
|
|
111
|
+
Element,
|
|
112
|
+
{
|
|
113
|
+
"data-scope": "form",
|
|
114
|
+
"data-part": "right-item",
|
|
115
|
+
className: cnMerge("inline-flex items-center justify-center", className),
|
|
116
|
+
...restOfProps
|
|
117
|
+
},
|
|
118
|
+
children
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
FormInputRightItem.slot = Symbol.for("rightItem");
|
|
122
|
+
var inputTypesWithoutFullWith = /* @__PURE__ */ new Set(["checkbox", "radio"]);
|
|
123
|
+
function FormInputPrimitive(props) {
|
|
124
|
+
const contextValues = useLaxFormItemContext();
|
|
125
|
+
const {
|
|
126
|
+
className,
|
|
127
|
+
classNames,
|
|
128
|
+
control,
|
|
129
|
+
formState,
|
|
130
|
+
id = contextValues?.uniqueId,
|
|
131
|
+
name = contextValues?.name,
|
|
132
|
+
type = "text",
|
|
133
|
+
withEyeIcon = true,
|
|
134
|
+
...restOfProps
|
|
135
|
+
} = props;
|
|
136
|
+
const getFormState = control ? useFormState : () => formState;
|
|
137
|
+
const { errors } = getFormState({ control }) ?? {};
|
|
138
|
+
const [isPasswordVisible, toggleVisibility] = useToggle(false);
|
|
139
|
+
const shouldHaveEyeIcon = withEyeIcon && type === "password";
|
|
140
|
+
const WrapperElement = shouldHaveEyeIcon ? FormInputGroup : Fragment;
|
|
141
|
+
const wrapperElementProps = shouldHaveEyeIcon && {
|
|
142
|
+
className: cnMerge("w-full", classNames?.inputGroup, name && errors?.[name] && classNames?.error)
|
|
143
|
+
};
|
|
144
|
+
return /* @__PURE__ */ React2.createElement(WrapperElement, { ...wrapperElementProps }, /* @__PURE__ */ React2.createElement(
|
|
145
|
+
"input",
|
|
146
|
+
{
|
|
147
|
+
"data-scope": "form",
|
|
148
|
+
"data-part": "input",
|
|
149
|
+
id,
|
|
150
|
+
name,
|
|
151
|
+
type: type === "password" && isPasswordVisible ? "text" : type,
|
|
152
|
+
className: cnMerge(
|
|
153
|
+
!inputTypesWithoutFullWith.has(type) && "flex w-full",
|
|
154
|
+
`bg-transparent text-sm file:border-0 file:bg-transparent
|
|
155
|
+
placeholder:text-shadcn-muted-foreground focus-visible:outline-none
|
|
156
|
+
disabled:cursor-not-allowed disabled:opacity-50`,
|
|
157
|
+
className,
|
|
158
|
+
classNames?.input,
|
|
159
|
+
type !== "password" && name && errors?.[name] && classNames?.error
|
|
160
|
+
),
|
|
161
|
+
...restOfProps
|
|
162
|
+
}
|
|
163
|
+
), shouldHaveEyeIcon && /* @__PURE__ */ React2.createElement(
|
|
164
|
+
FormInputRightItem,
|
|
165
|
+
{
|
|
166
|
+
as: "button",
|
|
167
|
+
type: "button",
|
|
168
|
+
onClick: toggleVisibility,
|
|
169
|
+
className: "size-5 shrink-0 lg:size-6"
|
|
170
|
+
},
|
|
171
|
+
isPasswordVisible ? /* @__PURE__ */ React2.createElement(EyeIconInvisible, { className: cnMerge("size-full", classNames?.eyeIcon) }) : /* @__PURE__ */ React2.createElement(EyeIconVisible, { className: cnMerge("size-full", classNames?.eyeIcon) })
|
|
172
|
+
));
|
|
173
|
+
}
|
|
174
|
+
function FormInput(props) {
|
|
175
|
+
const { rules, ...restOfProps } = props;
|
|
176
|
+
const { name } = useStrictFormItemContext();
|
|
177
|
+
const { formState, register } = useFormContext();
|
|
178
|
+
return /* @__PURE__ */ React2.createElement(
|
|
179
|
+
FormInputPrimitive,
|
|
180
|
+
{
|
|
181
|
+
name,
|
|
182
|
+
formState,
|
|
183
|
+
...Boolean(name) && register(name, rules),
|
|
184
|
+
...restOfProps
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function FormTextAreaPrimitive(props) {
|
|
189
|
+
const contextValues = useLaxFormItemContext();
|
|
190
|
+
const {
|
|
191
|
+
className,
|
|
192
|
+
control,
|
|
193
|
+
errorClassName,
|
|
194
|
+
formState,
|
|
195
|
+
id = contextValues?.uniqueId,
|
|
196
|
+
name = contextValues?.name,
|
|
197
|
+
...restOfProps
|
|
198
|
+
} = props;
|
|
199
|
+
const getFormState = control ? useFormState : () => formState;
|
|
200
|
+
const { errors } = getFormState({ control }) ?? {};
|
|
201
|
+
return /* @__PURE__ */ React2.createElement(
|
|
202
|
+
"textarea",
|
|
203
|
+
{
|
|
204
|
+
"data-scope": "form",
|
|
205
|
+
"data-part": "textarea",
|
|
206
|
+
id,
|
|
207
|
+
name,
|
|
208
|
+
className: cnMerge(
|
|
209
|
+
`w-full bg-transparent text-sm placeholder:text-shadcn-muted-foreground
|
|
210
|
+
focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,
|
|
211
|
+
className,
|
|
212
|
+
name && errors?.[name] && errorClassName
|
|
213
|
+
),
|
|
214
|
+
...restOfProps
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
function FormTextArea(props) {
|
|
219
|
+
const { rules, ...restOfProps } = props;
|
|
220
|
+
const { name } = useStrictFormItemContext();
|
|
221
|
+
const { formState, register } = useFormContext();
|
|
222
|
+
return /* @__PURE__ */ React2.createElement(
|
|
223
|
+
FormTextAreaPrimitive,
|
|
224
|
+
{
|
|
225
|
+
name,
|
|
226
|
+
formState,
|
|
227
|
+
...Boolean(name) && register(name, rules),
|
|
228
|
+
...restOfProps
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
function FormController(props) {
|
|
233
|
+
const { control } = useFormContext();
|
|
234
|
+
const { name } = useStrictFormItemContext();
|
|
235
|
+
return /* @__PURE__ */ React2.createElement(Controller, { name, control, ...props });
|
|
236
|
+
}
|
|
237
|
+
function FormErrorMessagePrimitive(props) {
|
|
238
|
+
const {
|
|
239
|
+
className,
|
|
240
|
+
classNames,
|
|
241
|
+
control,
|
|
242
|
+
errorField,
|
|
243
|
+
render,
|
|
244
|
+
type = "regular",
|
|
245
|
+
withAnimationOnInvalid = true
|
|
246
|
+
} = props;
|
|
247
|
+
const formState = useFormState({ control });
|
|
248
|
+
const wrapperRef = useRef(null);
|
|
249
|
+
const errorAnimationClass = classNames?.errorMessageAnimation ?? "animate-shake";
|
|
250
|
+
useEffect(() => {
|
|
251
|
+
if (!withAnimationOnInvalid) return;
|
|
252
|
+
const errorMessageElements = wrapperRef.current?.children;
|
|
253
|
+
if (!errorMessageElements) return;
|
|
254
|
+
for (const element of errorMessageElements) {
|
|
255
|
+
element.classList.add(errorAnimationClass);
|
|
256
|
+
}
|
|
257
|
+
}, [errorAnimationClass, withAnimationOnInvalid]);
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
const errorMessageElements = wrapperRef.current?.children;
|
|
260
|
+
if (!errorMessageElements) return;
|
|
261
|
+
if (Object.keys(formState.errors).indexOf(errorField) === 0) {
|
|
262
|
+
errorMessageElements[0]?.scrollIntoView({
|
|
263
|
+
behavior: "smooth",
|
|
264
|
+
block: "center"
|
|
265
|
+
});
|
|
266
|
+
window.scrollBy({ behavior: "smooth", top: -100 });
|
|
267
|
+
}
|
|
268
|
+
}, [errorField, formState.errors]);
|
|
269
|
+
const message = type === "root" ? formState.errors.root?.[errorField]?.message : formState.errors[errorField]?.message;
|
|
270
|
+
if (!message) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const errorMessageArray = toArray(message);
|
|
274
|
+
const [ErrorMessageList] = getElementList();
|
|
275
|
+
const onAnimationEnd = withAnimationOnInvalid ? (event) => event.currentTarget.classList.remove(errorAnimationClass) : void 0;
|
|
276
|
+
return /* @__PURE__ */ React2.createElement(
|
|
277
|
+
ErrorMessageList,
|
|
278
|
+
{
|
|
279
|
+
ref: wrapperRef,
|
|
280
|
+
each: errorMessageArray,
|
|
281
|
+
className: cnMerge("flex flex-col", classNames?.container),
|
|
282
|
+
render: (errorMessage, index) => {
|
|
283
|
+
return render({
|
|
284
|
+
props: {
|
|
285
|
+
className: cnMerge(errorAnimationClass, className, classNames?.errorMessage),
|
|
286
|
+
"data-index": index,
|
|
287
|
+
"data-part": "error-message",
|
|
288
|
+
"data-scope": "form",
|
|
289
|
+
onAnimationEnd
|
|
290
|
+
},
|
|
291
|
+
state: { errorMessage, errorMessageArray, index }
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
function FormErrorMessage(props) {
|
|
298
|
+
const contextValues = useLaxFormItemContext();
|
|
299
|
+
const { className, errorField = contextValues?.name, type = "regular" } = props;
|
|
300
|
+
const { control } = useFormContext();
|
|
301
|
+
return /* @__PURE__ */ React2.createElement(
|
|
302
|
+
FormErrorMessagePrimitive,
|
|
303
|
+
{
|
|
304
|
+
control,
|
|
305
|
+
errorField,
|
|
306
|
+
type,
|
|
307
|
+
render: ({ props: renderProps, state: { errorMessage } }) => /* @__PURE__ */ React2.createElement(
|
|
308
|
+
"p",
|
|
309
|
+
{
|
|
310
|
+
key: errorMessage,
|
|
311
|
+
...renderProps,
|
|
312
|
+
className: cnMerge("text-[13px]", "data-[index=0]:mt-1", renderProps.className, className)
|
|
313
|
+
},
|
|
314
|
+
errorMessage
|
|
315
|
+
)
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
var Root = FormRoot;
|
|
320
|
+
var Item = FormItem;
|
|
321
|
+
var ItemContext = FormItemContext;
|
|
322
|
+
var Label = FormLabel;
|
|
323
|
+
var ErrorMessagePrimitive = FormErrorMessagePrimitive;
|
|
324
|
+
var ErrorMessage = FormErrorMessage;
|
|
325
|
+
var Input = FormInput;
|
|
326
|
+
var InputPrimitive = FormInputPrimitive;
|
|
327
|
+
var InputGroup = FormInputGroup;
|
|
328
|
+
var InputLeftItem = FormInputLeftItem;
|
|
329
|
+
var InputRightItem = FormInputRightItem;
|
|
330
|
+
var TextAreaPrimitive = FormTextAreaPrimitive;
|
|
331
|
+
var TextArea = FormTextArea;
|
|
332
|
+
var Controller2 = FormController;
|
|
333
|
+
|
|
334
|
+
export { Controller2 as Controller, ErrorMessage, ErrorMessagePrimitive, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormItem, FormLabel, FormRoot, Input, InputGroup, InputLeftItem, InputPrimitive, InputRightItem, Item, ItemContext, Label, Root, TextArea, TextAreaPrimitive, useStrictFormItemContext as useFormItemContext };
|
|
335
|
+
//# sourceMappingURL=index.js.map
|
|
336
|
+
//# sourceMappingURL=index.js.map
|