@zayne-labs/ui-react 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/esm/chunk-ENDWJXPF.js +1 -1
  2. package/dist/esm/chunk-ENDWJXPF.js.map +1 -1
  3. package/dist/esm/{chunk-GBLTOENX.js → chunk-MPOYLILK.js} +6 -8
  4. package/dist/esm/chunk-MPOYLILK.js.map +1 -0
  5. package/dist/esm/chunk-PZ5AY32C.js +9 -0
  6. package/dist/esm/chunk-PZ5AY32C.js.map +1 -0
  7. package/dist/esm/common/for/index.d.ts +4 -4
  8. package/dist/esm/common/for/index.js +2 -1
  9. package/dist/esm/common/show/index.d.ts +10 -6
  10. package/dist/esm/common/show/index.js +10 -6
  11. package/dist/esm/common/show/index.js.map +1 -1
  12. package/dist/esm/common/slot/index.js +1 -0
  13. package/dist/esm/common/switch/index.d.ts +2 -5
  14. package/dist/esm/common/switch/index.js +4 -7
  15. package/dist/esm/common/switch/index.js.map +1 -1
  16. package/dist/esm/common/teleport/index.js +1 -1
  17. package/dist/esm/{for-BmvZgK9J.d.ts → for-C3T5FbXd.d.ts} +1 -3
  18. package/dist/esm/ui/card/index.d.ts +5 -7
  19. package/dist/esm/ui/card/index.js +13 -7
  20. package/dist/esm/ui/card/index.js.map +1 -1
  21. package/dist/esm/ui/carousel/index.d.ts +7 -12
  22. package/dist/esm/ui/carousel/index.js +31 -19
  23. package/dist/esm/ui/carousel/index.js.map +1 -1
  24. package/dist/esm/ui/drag-scroll/index.d.ts +285 -4
  25. package/dist/esm/ui/drag-scroll/index.js +41 -21
  26. package/dist/esm/ui/drag-scroll/index.js.map +1 -1
  27. package/dist/esm/ui/drop-zone/index.d.ts +24 -14
  28. package/dist/esm/ui/drop-zone/index.js +45 -44
  29. package/dist/esm/ui/drop-zone/index.js.map +1 -1
  30. package/dist/esm/ui/form/index.d.ts +26 -32
  31. package/dist/esm/ui/form/index.js +67 -39
  32. package/dist/esm/ui/form/index.js.map +1 -1
  33. package/package.json +10 -10
  34. package/dist/esm/chunk-GBLTOENX.js.map +0 -1
@@ -1,5 +1,4 @@
1
1
  import * as react from 'react';
2
- import { RefCallback } from 'react';
3
2
  import { FileValidationOptions } from '@zayne-labs/toolkit-core';
4
3
  import { InferProps } from '@zayne-labs/toolkit-react/utils';
5
4
 
@@ -8,6 +7,13 @@ type RenderProps = {
8
7
  inputRef: React.RefObject<HTMLInputElement | null>;
9
8
  isDragging: boolean;
10
9
  };
10
+ type RootProps = InferProps<"div"> & {
11
+ classNames?: {
12
+ activeDrag?: string;
13
+ base?: string;
14
+ };
15
+ };
16
+ type InputProps = InferProps<"input">;
11
17
  type UseDropZoneProps = {
12
18
  allowedFileTypes?: string[];
13
19
  children?: React.ReactNode | ((props: RenderProps) => React.ReactNode);
@@ -18,15 +24,14 @@ type UseDropZoneProps = {
18
24
  };
19
25
  disableInbuiltValidation?: boolean;
20
26
  existingFiles?: File[];
21
- extraInputProps?: Omit<InferProps<"input">, "ref">;
22
- extraRootProps?: InferProps<"div">;
27
+ extraInputProps?: InputProps;
28
+ extraRootProps?: RootProps;
23
29
  onUpload?: (details: {
24
30
  acceptedFiles: File[];
25
31
  event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLDivElement>;
26
32
  }) => void;
27
33
  onUploadError?: FileValidationOptions["onError"];
28
34
  onUploadSuccess?: FileValidationOptions["onSuccess"];
29
- ref?: React.Ref<HTMLInputElement>;
30
35
  validationSettings?: {
31
36
  disallowDuplicates?: boolean;
32
37
  fileLimit?: number;
@@ -39,25 +44,22 @@ type UseDropZoneProps = {
39
44
  };
40
45
  declare const useDropZone: (props: UseDropZoneProps) => {
41
46
  getChildren: () => react.ReactNode;
42
- getInputProps: () => {
47
+ getInputProps: (inputProps?: InputProps) => {
43
48
  accept: string | undefined;
44
49
  className: string;
50
+ "data-active-drag": boolean;
45
51
  "data-part": string;
46
52
  "data-scope": string;
47
53
  onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
48
- ref: RefCallback<HTMLInputElement>;
54
+ ref: react.RefCallback<HTMLInputElement>;
49
55
  type: string;
50
- form?: string | undefined;
51
- slot?: string | undefined;
52
- style?: react.CSSProperties | undefined;
53
- title?: string | undefined;
54
- pattern?: string | undefined;
55
56
  key?: react.Key | null | undefined;
56
57
  alt?: string | undefined;
57
58
  autoComplete?: react.HTMLInputAutoCompleteAttribute | undefined;
58
59
  capture?: boolean | "user" | "environment" | undefined;
59
60
  checked?: boolean | undefined;
60
61
  disabled?: boolean | undefined;
62
+ form?: string | undefined;
61
63
  formAction?: string | ((formData: FormData) => void | Promise<void>) | react.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_FORM_ACTIONS[keyof react.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_FORM_ACTIONS] | undefined;
62
64
  formEncType?: string | undefined;
63
65
  formMethod?: string | undefined;
@@ -71,6 +73,7 @@ declare const useDropZone: (props: UseDropZoneProps) => {
71
73
  minLength?: number | undefined;
72
74
  multiple?: boolean | undefined;
73
75
  name?: string | undefined;
76
+ pattern?: string | undefined;
74
77
  placeholder?: string | undefined;
75
78
  readOnly?: boolean | undefined;
76
79
  required?: boolean | undefined;
@@ -95,8 +98,11 @@ declare const useDropZone: (props: UseDropZoneProps) => {
95
98
  id?: string | undefined;
96
99
  lang?: string | undefined;
97
100
  nonce?: string | undefined;
101
+ slot?: string | undefined;
98
102
  spellCheck?: (boolean | "true" | "false") | undefined;
103
+ style?: react.CSSProperties | undefined;
99
104
  tabIndex?: number | undefined;
105
+ title?: string | undefined;
100
106
  translate?: "yes" | "no" | undefined;
101
107
  radioGroup?: string | undefined;
102
108
  role?: react.AriaRole | undefined;
@@ -358,7 +364,7 @@ declare const useDropZone: (props: UseDropZoneProps) => {
358
364
  inputRef: react.RefObject<HTMLInputElement | null>;
359
365
  isDragging: boolean;
360
366
  };
361
- getRootProps: () => {
367
+ getRootProps: (rootProps?: RootProps) => {
362
368
  className: string;
363
369
  "data-active-drag": boolean;
364
370
  "data-part": string;
@@ -642,14 +648,18 @@ declare const useDropZone: (props: UseDropZoneProps) => {
642
648
  onTransitionRunCapture?: react.TransitionEventHandler<HTMLDivElement> | undefined;
643
649
  onTransitionStart?: react.TransitionEventHandler<HTMLDivElement> | undefined;
644
650
  onTransitionStartCapture?: react.TransitionEventHandler<HTMLDivElement> | undefined;
651
+ classNames?: {
652
+ activeDrag?: string;
653
+ base?: string;
654
+ };
645
655
  };
646
656
  handleDragLeave: (event: React.DragEvent<HTMLDivElement>) => void;
647
657
  handleDragOver: (event: React.DragEvent<HTMLDivElement>) => void;
648
658
  handleFileUpload: (event: React.ChangeEvent<HTMLInputElement> | React.DragEvent<HTMLDivElement>) => void;
659
+ inputRef: react.RefObject<HTMLInputElement | null>;
649
660
  isDragging: boolean;
650
- ref: react.Ref<HTMLInputElement> | undefined;
651
661
  };
652
662
 
653
663
  declare function DropZone(props: UseDropZoneProps): react.JSX.Element;
654
664
 
655
- export { DropZone, type UseDropZoneProps, useDropZone };
665
+ export { DropZone, type InputProps, type RootProps, type UseDropZoneProps, useDropZone };
@@ -1,8 +1,10 @@
1
1
  import { cnMerge } from '../../chunk-OHG7GB7O.js';
2
+ import '../../chunk-PZ5AY32C.js';
2
3
  import * as React from 'react';
3
4
  import { useRef, useState } from 'react';
4
5
  import { handleFileValidation } from '@zayne-labs/toolkit-core';
5
6
  import { useToggle, useCallbackRef } from '@zayne-labs/toolkit-react';
7
+ import { mergeProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
6
8
  import { isObject, isFunction } from '@zayne-labs/toolkit-type-helpers';
7
9
 
8
10
  var useDropZone = (props) => {
@@ -18,7 +20,6 @@ var useDropZone = (props) => {
18
20
  onUpload,
19
21
  onUploadError,
20
22
  onUploadSuccess,
21
- ref,
22
23
  validationSettings,
23
24
  validator
24
25
  // eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Can be undefined
@@ -27,6 +28,7 @@ var useDropZone = (props) => {
27
28
  const [acceptedFiles, setAcceptedFiles] = useState([]);
28
29
  const handleFileUpload = useCallbackRef(
29
30
  (event) => {
31
+ if (event.defaultPrevented) return;
30
32
  if (event.type === "drop") {
31
33
  event.preventDefault();
32
34
  toggleIsDragging(false);
@@ -60,47 +62,46 @@ var useDropZone = (props) => {
60
62
  };
61
63
  const getRenderProps = () => ({ acceptedFiles, inputRef, isDragging });
62
64
  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
- });
65
+ const getRootProps = (rootProps) => {
66
+ const mergedRootProps = mergeProps(extraRootProps, rootProps);
67
+ return {
68
+ ...mergedRootProps,
69
+ className: cnMerge(
70
+ "relative isolate flex flex-col",
71
+ mergedRootProps.className,
72
+ classNames?.base,
73
+ isDragging && ["opacity-60", classNames?.activeDrag, rootProps?.classNames?.activeDrag]
74
+ ),
75
+ "data-active-drag": isDragging,
76
+ "data-part": "root",
77
+ "data-scope": "dropzone",
78
+ onDragEnter: handleDragOver,
79
+ onDragLeave: handleDragLeave,
80
+ onDragOver: handleDragOver,
81
+ onDrop: handleFileUpload
82
+ };
83
+ };
84
+ const getInputProps = (inputProps) => {
85
+ const mergedInputProps = mergeProps(extraInputProps, inputProps);
86
+ return {
87
+ ...mergedInputProps,
88
+ accept: allowedFileTypes ? allowedFileTypes.join(", ") : mergedInputProps.accept,
89
+ className: cnMerge(
90
+ "absolute inset-0 z-[100] cursor-pointer opacity-0",
91
+ classNames?.input,
92
+ mergedInputProps.className
93
+ ),
94
+ "data-active-drag": isDragging,
95
+ "data-part": "input",
96
+ "data-scope": "dropzone",
97
+ onChange: (event) => {
98
+ handleFileUpload(event);
99
+ mergedInputProps.onChange?.(event);
100
+ },
101
+ ref: composeRefs([inputRef, mergedInputProps.ref]),
102
+ type: "file"
103
+ };
104
+ };
104
105
  return {
105
106
  getChildren,
106
107
  getInputProps,
@@ -109,8 +110,8 @@ var useDropZone = (props) => {
109
110
  handleDragLeave,
110
111
  handleDragOver,
111
112
  handleFileUpload,
112
- isDragging,
113
- ref
113
+ inputRef,
114
+ isDragging
114
115
  };
115
116
  };
116
117
 
@@ -1 +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,gBAAA;AAAA,IACA,QAAA;AAAA,IACA,UAAA;AAAA,IACA,wBAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA,QAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,GAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA;AA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AA,CAAI,OAAU,GAAA,IAAA;AAAA,GACd,CAAA;AAED,EAAA,MAAM,gBAAgB,OAAO;AAAA,IAC5B,GAAG,eAAA;AAAA,IACH,QAAQ,gBAAmB,GAAA,gBAAA,CAAiB,IAAK,CAAA,IAAI,IAAI,eAAiB,EAAA,MAAA;AAAA,IAC1E,SAAW,EAAA,OAAA;AAAA,MACV,mDAAA;AAAA,MACA,eAAiB,EAAA,SAAA;AAAA,MACjB,UAAY,EAAA;AAAA,KACb;AAAA,IACA,WAAa,EAAA,OAAA;AAAA,IACb,YAAc,EAAA,UAAA;AAAA,IACd,QAAA,EAAU,CAAC,KAA+C,KAAA;AACzD,MAAA,gBAAA,CAAiB,KAAK,CAAA;AACtB,MAAA,eAAA,EAAiB,WAAW,KAAK,CAAA;AAAA,KAClC;AAAA,IACA,GAAK,EAAA,WAAA;AAAA,IACL,IAAM,EAAA;AAAA,GACP,CAAA;AAEA,EAAO,OAAA;AAAA,IACN,WAAA;AAAA,IACA,aAAA;AAAA,IACA,cAAA;AAAA,IACA,YAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA,gBAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACD;AACD;;;ACzLA,SAAS,SAAS,KAAyB,EAAA;AAC1C,EAAM,MAAA,GAAA,GAAM,YAAY,KAAK,CAAA;AAE7B,EAAA,uBACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,GAAG,GAAA,CAAI,cACZ,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,OAAO,EAAA,EAAA,GAAG,IAAI,aAAc,EAAA,EAAG,CAE/B,EAAA,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"]}
1
+ {"version":3,"sources":["../../../../src/components/ui/drop-zone/use-drop-zone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx"],"names":[],"mappings":";;;;;;;;;AAmDa,IAAA,WAAA,GAAc,CAAC,KAA4B,KAAA;AACvD,EAAM,MAAA,QAAA,GAAW,OAAyB,IAAI,CAAA;AAE9C,EAAM,MAAA;AAAA,IACL,gBAAA;AAAA,IACA,QAAA;AAAA,IACA,UAAA;AAAA,IACA,wBAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,cAAA;AAAA,IACA,QAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA;AAAA,GAED,GAAI,SAAS,EAAC;AAEd,EAAA,MAAM,CAAC,UAAA,EAAY,gBAAgB,CAAA,GAAI,UAAU,KAAK,CAAA;AAEtD,EAAA,MAAM,CAAC,aAAe,EAAA,gBAAgB,CAAI,GAAA,QAAA,CAAiB,EAAE,CAAA;AAE7D,EAAA,MAAM,gBAAmB,GAAA,cAAA;AAAA,IACxB,CAAC,KAAiF,KAAA;AACjF,MAAA,IAAI,MAAM,gBAAkB,EAAA;AAE5B,MAAI,IAAA,KAAA,CAAM,SAAS,MAAQ,EAAA;AAC1B,QAAA,KAAA,CAAM,cAAe,EAAA;AACrB,QAAA,gBAAA,CAAiB,KAAK,CAAA;AAAA;AAGvB,MAAM,MAAA,QAAA,GACL,MAAM,IAAS,KAAA,MAAA,GACX,MAA0B,YAAa,CAAA,KAAA,GACvC,MAA8C,MAAO,CAAA,KAAA;AAE1D,MAAA,IAAI,aAAa,IAAM,EAAA;AACtB,QAAA,OAAA,CAAQ,KAAK,kBAAkB,CAAA;AAE/B,QAAA;AAAA;AAGD,MAAM,MAAA,0BAAA,GAA6B,CAAC,wBAAA,GACjC,oBAAqB,CAAA;AAAA,QACrB,iBAAmB,EAAA,aAAA;AAAA,Q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AA,IACA,cAAA;AAAA,IACA,gBAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACD;AACD;;;AC7LA,SAAS,SAAS,KAAyB,EAAA;AAC1C,EAAM,MAAA,GAAA,GAAM,YAAY,KAAK,CAAA;AAE7B,EAAA,uBACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,GAAG,GAAA,CAAI,cACZ,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,OAAO,EAAA,EAAA,GAAG,IAAI,aAAc,EAAA,EAAG,CAE/B,EAAA,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, composeRefs, mergeProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction, isObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useRef, useState } from \"react\";\n\ntype RenderProps = {\n\tacceptedFiles: File[];\n\tinputRef: React.RefObject<HTMLInputElement | null>;\n\tisDragging: boolean;\n};\n\nexport type RootProps = InferProps<\"div\"> & { classNames?: { activeDrag?: string; base?: string } };\n\nexport type InputProps = InferProps<\"input\">;\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?: InputProps;\n\n\textraRootProps?: RootProps;\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\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\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.defaultPrevented) return;\n\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\t/* TODO: take inspiration from ark's implementation to merge extraRootProps with the props you pass to getRootProps\n\t * @see https://github.com/chakra-ui/ark/blob/main/packages/react/src/components/steps/steps-separator.tsx\n\t */\n\n\tconst getRootProps = (rootProps?: RootProps) => {\n\t\tconst mergedRootProps = mergeProps(extraRootProps, rootProps);\n\n\t\treturn {\n\t\t\t...mergedRootProps,\n\t\t\tclassName: cnMerge(\n\t\t\t\t\"relative isolate flex flex-col\",\n\t\t\t\tmergedRootProps.className,\n\t\t\t\tclassNames?.base,\n\t\t\t\tisDragging && [\"opacity-60\", classNames?.activeDrag, rootProps?.classNames?.activeDrag]\n\t\t\t),\n\t\t\t\"data-active-drag\": isDragging,\n\t\t\t\"data-part\": \"root\",\n\t\t\t\"data-scope\": \"dropzone\",\n\t\t\tonDragEnter: handleDragOver,\n\t\t\tonDragLeave: handleDragLeave,\n\t\t\tonDragOver: handleDragOver,\n\t\t\tonDrop: handleFileUpload,\n\t\t};\n\t};\n\n\tconst getInputProps = (inputProps?: InputProps) => {\n\t\tconst mergedInputProps = mergeProps(extraInputProps, inputProps);\n\n\t\treturn {\n\t\t\t...mergedInputProps,\n\t\t\taccept: allowedFileTypes ? allowedFileTypes.join(\", \") : mergedInputProps.accept,\n\t\t\tclassName: cnMerge(\n\t\t\t\t\"absolute inset-0 z-[100] cursor-pointer opacity-0\",\n\t\t\t\tclassNames?.input,\n\t\t\t\tmergedInputProps.className\n\t\t\t),\n\t\t\t\"data-active-drag\": isDragging,\n\t\t\t\"data-part\": \"input\",\n\t\t\t\"data-scope\": \"dropzone\",\n\t\t\tonChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\t\thandleFileUpload(event);\n\t\t\t\tmergedInputProps.onChange?.(event);\n\t\t\t},\n\t\t\tref: composeRefs([inputRef, mergedInputProps.ref]),\n\t\t\ttype: \"file\",\n\t\t};\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\tinputRef,\n\t\tisDragging,\n\t};\n};\n","import * as React from \"react\";\n\nimport { type UseDropZoneProps, useDropZone } from \"./use-drop-zone\";\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"]}
@@ -1,18 +1,18 @@
1
1
  import * as react from 'react';
2
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';
3
+ import { RegisterOptions, UseFormReturn, Control, FormState, ControllerProps, FieldPath, ControllerRenderProps, ControllerFieldState, UseFormStateReturn, Controller } from 'react-hook-form';
5
4
 
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
5
  type ContextValue = {
12
6
  name: string;
13
7
  uniqueId: string;
14
8
  };
15
9
  declare const useStrictFormItemContext: () => ContextValue;
10
+
11
+ type FieldValues = Record<string, unknown>;
12
+ type FormRootProps<TValues extends FieldValues> = react.ComponentPropsWithoutRef<"form"> & {
13
+ children: react.ReactNode;
14
+ methods: UseFormReturn<TValues>;
15
+ };
16
16
  declare function FormRoot<TValues extends FieldValues>(props: FormRootProps<TValues>): react.JSX.Element;
17
17
  type FormItemProps<TControl, TFieldValues extends FieldValues> = (TControl extends Control<infer TValues> ? {
18
18
  control?: never;
@@ -86,14 +86,15 @@ type FormControllerProps<TFieldValues> = Omit<ControllerProps<FieldValues, Field
86
86
  }) => react.ReactElement;
87
87
  };
88
88
  declare function FormController<TFieldValues = never>(props: FormControllerProps<TFieldValues>): react.JSX.Element;
89
- type FormErrorRenderProps = {
89
+ declare function FormDescription(props: InferProps<"p">): react.JSX.Element;
90
+ type ErrorMessageRenderProps = {
90
91
  className: string;
91
92
  "data-index": number;
92
93
  "data-part": string;
93
94
  "data-scope": string;
94
95
  onAnimationEnd?: react.ReactEventHandler<HTMLElement>;
95
96
  };
96
- type FormErrorRenderPropState = {
97
+ type ErrorMessageRenderState = {
97
98
  errorMessage: string;
98
99
  errorMessageArray: string[];
99
100
  index: number;
@@ -107,8 +108,8 @@ type FormErrorMessagePrimitiveProps<TFieldValues extends FieldValues> = {
107
108
  };
108
109
  control: Control<TFieldValues>;
109
110
  render: (context: {
110
- props: FormErrorRenderProps;
111
- state: FormErrorRenderPropState;
111
+ props: ErrorMessageRenderProps;
112
+ state: ErrorMessageRenderState;
112
113
  }) => react.ReactNode;
113
114
  withAnimationOnInvalid?: boolean;
114
115
  } & ({
@@ -118,12 +119,15 @@ type FormErrorMessagePrimitiveProps<TFieldValues extends FieldValues> = {
118
119
  errorField: string;
119
120
  type: "root";
120
121
  });
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;
122
+ type FormErrorMessagePrimitiveType = {
123
+ <TFieldValues extends FieldValues>(props: Extract<FormErrorMessagePrimitiveProps<TFieldValues>, {
124
+ type?: "regular";
125
+ }>): react.ReactNode;
126
+ <TFieldValues extends FieldValues>(props: Extract<FormErrorMessagePrimitiveProps<TFieldValues>, {
127
+ type: "root";
128
+ }>): react.ReactNode;
129
+ };
130
+ declare const FormErrorMessagePrimitive: FormErrorMessagePrimitiveType;
127
131
  type FormErrorMessageProps<TControl, TFieldValues extends FieldValues> = (TControl extends Control<infer TValues> ? {
128
132
  className?: string;
129
133
  control?: never;
@@ -141,19 +145,9 @@ type FormErrorMessageProps<TControl, TFieldValues extends FieldValues> = (TContr
141
145
  type: "root";
142
146
  };
143
147
  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
148
 
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 };
149
+ declare namespace formParts {
150
+ export { FormController as Controller, Controller as ControllerPrimitive, FormDescription as Description, FormErrorMessage as ErrorMessage, FormErrorMessagePrimitive as ErrorMessagePrimitive, FormInput as Input, FormInputGroup as InputGroup, FormInputLeftItem as InputLeftItem, FormInputPrimitive as InputPrimitive, FormInputRightItem as InputRightItem, FormItem as Item, FormItemContext as ItemContext, FormLabel as Label, FormRoot as Root, FormTextArea as TextArea, FormTextAreaPrimitive as TextAreaPrimitive };
151
+ }
152
+
153
+ export { formParts as Form, FormController, FormDescription, FormErrorMessage, FormErrorMessagePrimitive, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormItem, FormItemContext, FormLabel, FormRoot, FormTextArea, FormTextAreaPrimitive, useStrictFormItemContext as useFormItemContext };
@@ -1,12 +1,12 @@
1
- import { getElementList } from '../../chunk-GBLTOENX.js';
1
+ import { getElementList } from '../../chunk-MPOYLILK.js';
2
2
  import { cnMerge } from '../../chunk-OHG7GB7O.js';
3
+ import { __export } from '../../chunk-PZ5AY32C.js';
3
4
  import * as React2 from 'react';
4
- import { useId, useMemo, Fragment, useRef, useEffect } from 'react';
5
+ import { useId, useMemo, useRef, useEffect, Fragment } from 'react';
5
6
  import { toArray } from '@zayne-labs/toolkit-core';
6
- import { createCustomContext, useToggle } from '@zayne-labs/toolkit-react';
7
+ import { createCustomContext, useToggle, ContextError } from '@zayne-labs/toolkit-react';
7
8
  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';
9
+ import { Controller, FormProvider, useFormState, useFormContext } from 'react-hook-form';
10
10
 
11
11
  var EyeIconInvisible = (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(
12
12
  "path",
@@ -22,15 +22,26 @@ var EyeIconVisible = (props) => /* @__PURE__ */ React2.createElement("svg", { xm
22
22
  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"
23
23
  }
24
24
  ));
25
+ var useFormFieldContext = () => {
26
+ const formContext = useFormContext();
27
+ if (!formContext) {
28
+ throw new ContextError(
29
+ `useFormFieldContext returned "null". Did you forget to wrap the necessary components within FormRoot?`
30
+ );
31
+ }
32
+ return formContext;
33
+ };
25
34
  var [StrictFormItemProvider, useStrictFormItemContext] = createCustomContext({
26
- hookName: "useStrictFormItemContext",
27
- providerName: "StrictFormItemProvider"
35
+ hookName: "useFormItemContext",
36
+ providerName: "FormItem"
28
37
  });
29
38
  var [LaxFormItemProvider, useLaxFormItemContext] = createCustomContext({
30
39
  hookName: "useLaxFormItemContext",
31
- providerName: "LaxFormItemProvider",
40
+ providerName: "FormItem",
32
41
  strict: false
33
42
  });
43
+
44
+ // src/components/ui/form/form.tsx
34
45
  function FormRoot(props) {
35
46
  const { children, className, methods, ...restOfProps } = props;
36
47
  return /* @__PURE__ */ React2.createElement(FormProvider, { ...methods }, /* @__PURE__ */ React2.createElement(
@@ -173,7 +184,7 @@ function FormInputPrimitive(props) {
173
184
  function FormInput(props) {
174
185
  const { rules, ...restOfProps } = props;
175
186
  const { name } = useStrictFormItemContext();
176
- const { formState, register } = useFormContext();
187
+ const { formState, register } = useFormFieldContext();
177
188
  return /* @__PURE__ */ React2.createElement(
178
189
  FormInputPrimitive,
179
190
  {
@@ -217,7 +228,7 @@ function FormTextAreaPrimitive(props) {
217
228
  function FormTextArea(props) {
218
229
  const { rules, ...restOfProps } = props;
219
230
  const { name } = useStrictFormItemContext();
220
- const { formState, register } = useFormContext();
231
+ const { formState, register } = useFormFieldContext();
221
232
  return /* @__PURE__ */ React2.createElement(
222
233
  FormTextAreaPrimitive,
223
234
  {
@@ -229,11 +240,15 @@ function FormTextArea(props) {
229
240
  );
230
241
  }
231
242
  function FormController(props) {
232
- const { control } = useFormContext();
243
+ const { control } = useFormFieldContext();
233
244
  const { name } = useStrictFormItemContext();
234
245
  return /* @__PURE__ */ React2.createElement(Controller, { name, control, ...props });
235
246
  }
236
- function FormErrorMessagePrimitive(props) {
247
+ function FormDescription(props) {
248
+ const { className, ...restOfProps } = props;
249
+ return /* @__PURE__ */ React2.createElement("p", { className: cnMerge("text-[12px]", className), ...restOfProps });
250
+ }
251
+ var FormErrorMessagePrimitive = (props) => {
237
252
  const {
238
253
  className,
239
254
  classNames,
@@ -271,7 +286,19 @@ function FormErrorMessagePrimitive(props) {
271
286
  }
272
287
  const errorMessageArray = toArray(message);
273
288
  const [ErrorMessageList] = getElementList();
274
- const onAnimationEnd = withAnimationOnInvalid ? (event) => event.currentTarget.classList.remove(errorAnimationClass) : void 0;
289
+ const onAnimationEnd = withAnimationOnInvalid ? (event) => event.currentTarget.classList.remove(errorAnimationClass) : undefined;
290
+ const getRenderProps = ({ index }) => ({
291
+ className: cnMerge(errorAnimationClass, className, classNames?.errorMessage),
292
+ "data-index": index,
293
+ "data-part": "error-message",
294
+ "data-scope": "form",
295
+ onAnimationEnd
296
+ });
297
+ const getRenderState = ({ errorMessage, index }) => ({
298
+ errorMessage,
299
+ errorMessageArray,
300
+ index
301
+ });
275
302
  return /* @__PURE__ */ React2.createElement(
276
303
  ErrorMessageList,
277
304
  {
@@ -280,23 +307,17 @@ function FormErrorMessagePrimitive(props) {
280
307
  className: cnMerge("flex flex-col", classNames?.container),
281
308
  render: (errorMessage, index) => {
282
309
  return render({
283
- props: {
284
- className: cnMerge(errorAnimationClass, className, classNames?.errorMessage),
285
- "data-index": index,
286
- "data-part": "error-message",
287
- "data-scope": "form",
288
- onAnimationEnd
289
- },
290
- state: { errorMessage, errorMessageArray, index }
310
+ props: getRenderProps({ index }),
311
+ state: getRenderState({ errorMessage, index })
291
312
  });
292
313
  }
293
314
  }
294
315
  );
295
- }
316
+ };
296
317
  function FormErrorMessage(props) {
297
318
  const contextValues = useLaxFormItemContext();
298
319
  const { className, errorField = contextValues?.name, type = "regular" } = props;
299
- const { control } = useFormContext();
320
+ const { control } = useFormFieldContext();
300
321
  return /* @__PURE__ */ React2.createElement(
301
322
  FormErrorMessagePrimitive,
302
323
  {
@@ -306,8 +327,8 @@ function FormErrorMessage(props) {
306
327
  render: ({ props: renderProps, state: { errorMessage } }) => /* @__PURE__ */ React2.createElement(
307
328
  "p",
308
329
  {
309
- key: errorMessage,
310
330
  ...renderProps,
331
+ key: errorMessage,
311
332
  className: cnMerge("text-[13px]", "data-[index=0]:mt-1", renderProps.className, className)
312
333
  },
313
334
  errorMessage
@@ -315,21 +336,28 @@ function FormErrorMessage(props) {
315
336
  }
316
337
  );
317
338
  }
318
- var Root = FormRoot;
319
- var Item = FormItem;
320
- var ItemContext = FormItemContext;
321
- var Label = FormLabel;
322
- var ErrorMessagePrimitive = FormErrorMessagePrimitive;
323
- var ErrorMessage = FormErrorMessage;
324
- var Input = FormInput;
325
- var InputPrimitive = FormInputPrimitive;
326
- var InputGroup = FormInputGroup;
327
- var InputLeftItem = FormInputLeftItem;
328
- var InputRightItem = FormInputRightItem;
329
- var TextAreaPrimitive = FormTextAreaPrimitive;
330
- var TextArea = FormTextArea;
331
- var Controller2 = FormController;
332
339
 
333
- 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 };
340
+ // src/components/ui/form/form-parts.ts
341
+ var form_parts_exports = {};
342
+ __export(form_parts_exports, {
343
+ Controller: () => FormController,
344
+ ControllerPrimitive: () => Controller,
345
+ Description: () => FormDescription,
346
+ ErrorMessage: () => FormErrorMessage,
347
+ ErrorMessagePrimitive: () => FormErrorMessagePrimitive,
348
+ Input: () => FormInput,
349
+ InputGroup: () => FormInputGroup,
350
+ InputLeftItem: () => FormInputLeftItem,
351
+ InputPrimitive: () => FormInputPrimitive,
352
+ InputRightItem: () => FormInputRightItem,
353
+ Item: () => FormItem,
354
+ ItemContext: () => FormItemContext,
355
+ Label: () => FormLabel,
356
+ Root: () => FormRoot,
357
+ TextArea: () => FormTextArea,
358
+ TextAreaPrimitive: () => FormTextAreaPrimitive
359
+ });
360
+
361
+ export { form_parts_exports as Form, FormController, FormDescription, FormErrorMessage, FormErrorMessagePrimitive, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormItem, FormItemContext, FormLabel, FormRoot, FormTextArea, FormTextAreaPrimitive, useStrictFormItemContext as useFormItemContext };
334
362
  //# sourceMappingURL=index.js.map
335
363
  //# sourceMappingURL=index.js.map