@zayne-labs/ui-react 0.0.8 → 0.1.0

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 (35) hide show
  1. package/dist/esm/chunk-ENDWJXPF.js +47 -0
  2. package/dist/esm/chunk-ENDWJXPF.js.map +1 -0
  3. package/dist/esm/chunk-GBLTOENX.js +42 -0
  4. package/dist/esm/chunk-GBLTOENX.js.map +1 -0
  5. package/dist/esm/chunk-OHG7GB7O.js +8 -0
  6. package/dist/esm/chunk-OHG7GB7O.js.map +1 -0
  7. package/dist/esm/chunk-PZ5AY32C.js +9 -0
  8. package/dist/esm/chunk-PZ5AY32C.js.map +1 -0
  9. package/dist/esm/common/for/index.js +2 -40
  10. package/dist/esm/common/for/index.js.map +1 -1
  11. package/dist/esm/common/show/index.d.ts +10 -6
  12. package/dist/esm/common/show/index.js +10 -6
  13. package/dist/esm/common/show/index.js.map +1 -1
  14. package/dist/esm/common/slot/index.js +2 -45
  15. package/dist/esm/common/slot/index.js.map +1 -1
  16. package/dist/esm/common/switch/index.d.ts +2 -5
  17. package/dist/esm/common/switch/index.js +4 -7
  18. package/dist/esm/common/switch/index.js.map +1 -1
  19. package/dist/esm/common/teleport/index.js +1 -1
  20. package/dist/esm/ui/card/index.d.ts +5 -7
  21. package/dist/esm/ui/card/index.js +22 -59
  22. package/dist/esm/ui/card/index.js.map +1 -1
  23. package/dist/esm/ui/carousel/index.d.ts +6 -11
  24. package/dist/esm/ui/carousel/index.js +33 -59
  25. package/dist/esm/ui/carousel/index.js.map +1 -1
  26. package/dist/esm/ui/drag-scroll/index.d.ts +285 -4
  27. package/dist/esm/ui/drag-scroll/index.js +42 -24
  28. package/dist/esm/ui/drag-scroll/index.js.map +1 -1
  29. package/dist/esm/ui/drop-zone/index.d.ts +24 -14
  30. package/dist/esm/ui/drop-zone/index.js +46 -47
  31. package/dist/esm/ui/drop-zone/index.js.map +1 -1
  32. package/dist/esm/ui/form/index.d.ts +41 -32
  33. package/dist/esm/ui/form/index.js +84 -96
  34. package/dist/esm/ui/form/index.js.map +1 -1
  35. package/package.json +10 -10
@@ -1,10 +1,10 @@
1
- import { twMerge } from 'tailwind-merge';
1
+ import { cnMerge } from '../../chunk-OHG7GB7O.js';
2
+ import '../../chunk-PZ5AY32C.js';
2
3
  import { off, on, checkIsDeviceMobileOrTablet } from '@zayne-labs/toolkit-core';
3
4
  import { useCallbackRef } from '@zayne-labs/toolkit-react';
5
+ import { mergeProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
4
6
  import { useRef } from 'react';
5
7
 
6
- // src/lib/utils/cn.ts
7
- var cnMerge = (...classNames) => twMerge(classNames);
8
8
  var updateCursor = (element) => {
9
9
  element.style.cursor = "grabbing";
10
10
  element.style.userSelect = "none";
@@ -29,9 +29,15 @@ var handleScrollSnap = (dragContainer) => {
29
29
  }
30
30
  };
31
31
 
32
- // src/components/ui/drag-scroll/useDragScroll.ts
32
+ // src/components/ui/drag-scroll/use-drag-scroll.ts
33
33
  var useDragScroll = (props = {}) => {
34
- const { classNames, orientation = "horizontal", usage = "allScreens" } = props;
34
+ const {
35
+ classNames,
36
+ extraItemProps,
37
+ extraRootProps,
38
+ orientation = "horizontal",
39
+ usage = "allScreens"
40
+ } = props;
35
41
  const dragContainerRef = useRef(null);
36
42
  const positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });
37
43
  const handleMouseMove = useCallbackRef((event) => {
@@ -79,25 +85,37 @@ var useDragScroll = (props = {}) => {
79
85
  }
80
86
  return cleanup;
81
87
  });
82
- const getRootProps = () => ({
83
- className: cnMerge(
84
- `flex w-full cursor-grab snap-x snap-mandatory overflow-y-clip overflow-x-scroll
85
- [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,
86
- orientation === "horizontal" && "flex-row",
87
- orientation === "vertical" && "flex-col",
88
- usage === "mobileAndTabletOnly" && "md:cursor-default md:flex-col",
89
- usage === "desktopOnly" && "max-md:cursor-default max-md:flex-col",
90
- classNames?.base
91
- ),
92
- "data-part": "root",
93
- "data-scope": "drag-scroll",
94
- ref: refCallBack
95
- });
96
- const getItemProps = () => ({
97
- className: cnMerge("snap-center snap-always", classNames?.item),
98
- "data-part": "item",
99
- "data-scope": "drag-scroll"
100
- });
88
+ const getRootProps = (rootProps) => {
89
+ const mergedRootProps = mergeProps(extraRootProps, rootProps);
90
+ return {
91
+ ...mergedRootProps,
92
+ className: cnMerge(
93
+ `flex w-full cursor-grab snap-x snap-mandatory overflow-y-clip overflow-x-scroll
94
+ [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,
95
+ orientation === "horizontal" && "flex-row",
96
+ orientation === "vertical" && "flex-col",
97
+ usage === "mobileAndTabletOnly" && "md:cursor-default md:flex-col",
98
+ usage === "desktopOnly" && "max-md:cursor-default max-md:flex-col",
99
+ classNames?.base,
100
+ mergedRootProps.className
101
+ ),
102
+ "data-part": "root",
103
+ "data-scope": "drag-scroll",
104
+ ref: composeRefs([
105
+ refCallBack,
106
+ mergedRootProps?.ref
107
+ ])
108
+ };
109
+ };
110
+ const getItemProps = (itemProps) => {
111
+ const mergedItemProps = mergeProps(extraItemProps, itemProps);
112
+ return {
113
+ ...mergedItemProps,
114
+ className: cnMerge("snap-center snap-always", classNames?.item, mergedItemProps.className),
115
+ "data-part": "item",
116
+ "data-scope": "drag-scroll"
117
+ };
118
+ };
101
119
  return { getItemProps, getRootProps };
102
120
  };
103
121
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/cn.ts","../../../../src/components/ui/drag-scroll/utils.ts","../../../../src/components/ui/drag-scroll/useDragScroll.ts"],"names":[],"mappings":";;;;;;AAEO,IAAM,OAAU,GAAA,CAAA,GAAI,UAAiC,KAAA,OAAA,CAAQ,UAAU,CAAA;ACCvE,IAAM,YAAA,GAAe,CAA+B,OAAsB,KAAA;AAChF,EAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,UAAA;AACvB,EAAA,OA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B,UAAY,EAAA;AAAA,KACb;AAAA,IACA,WAAa,EAAA,MAAA;AAAA,IACb,YAAc,EAAA,aAAA;AAAA,IACd,GAAK,EAAA;AAAA,GACN,CAAA;AAEA,EAAA,MAAM,eAAe,OAAO;AAAA,IAC3B,SAAW,EAAA,OAAA,CAAQ,yBAA2B,EAAA,UAAA,EAAY,IAAI,CAAA;AAAA,IAC9D,WAAa,EAAA,MAAA;AAAA,IACb,YAAc,EAAA;AAAA,GACf,CAAA;AAEA,EAAO,OAAA,EAAE,cAAc,YAAa,EAAA;AACrC","file":"index.js","sourcesContent":["import { type ClassNameValue, twMerge } from \"tailwind-merge\";\n\nexport const cnMerge = (...classNames: ClassNameValue[]) => twMerge(classNames);\n","import { checkIsDeviceMobileOrTablet } from \"@zayne-labs/toolkit-core\";\n\n/* eslint-disable no-param-reassign -- Mutation is needed here since it's an element */\nexport const updateCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"grabbing\";\n\telement.style.userSelect = \"none\";\n};\n\nexport const onScrollSnap = <TElement extends HTMLElement>(\n\taction: \"remove\" | \"reset\",\n\telement: TElement\n) => {\n\tif (action === \"remove\") {\n\t\telement.style.scrollSnapType = \"none\";\n\t\treturn;\n\t}\n\n\telement.style.scrollSnapType = \"\";\n};\n\nexport const resetCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"\";\n\telement.style.userSelect = \"\";\n};\n/* eslint-enable no-param-reassign -- Mutation is needed here since it's an element */\n\nexport const handleScrollSnap = (dragContainer: HTMLElement) => {\n\tconst isMobileOrTablet = checkIsDeviceMobileOrTablet();\n\n\tif (!isMobileOrTablet) {\n\t\tonScrollSnap(\"remove\", dragContainer);\n\t} else {\n\t\tonScrollSnap(\"reset\", dragContainer);\n\t}\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { off, on } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { type RefCallback, useRef } from \"react\";\nimport { handleScrollSnap, resetCursor, updateCursor } from \"./utils\";\n\ntype DragScrollProps = {\n\tclassNames?: { base?: string; item?: string };\n\torientation?: \"both\" | \"horizontal\" | \"vertical\";\n\tusage?: \"allScreens\" | \"desktopOnly\" | \"mobileAndTabletOnly\";\n};\n\nconst useDragScroll = <TElement extends HTMLElement>(props: DragScrollProps = {}) => {\n\tconst { classNames, orientation = \"horizontal\", usage = \"allScreens\" } = props;\n\n\tconst dragContainerRef = useRef<TElement>(null);\n\n\tconst positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });\n\n\tconst handleMouseMove = useCallbackRef((event: MouseEvent) => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the horizontal scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dx = event.clientX - positionRef.current.x;\n\n\t\t\t// == Assign the scrollLeft of the container to the difference between its previous horizontal scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollLeft = positionRef.current.left - dx;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the vertical scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dy = event.clientY - positionRef.current.y;\n\n\t\t\t// == Assign the scrollTop of the container to the difference between its previous vertical scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollTop = positionRef.current.top - dy;\n\t\t}\n\t});\n\n\tconst handleMouseUpOrLeave = useCallbackRef(() => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\toff(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\toff(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\toff(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\n\t\tresetCursor(dragContainerRef.current);\n\t});\n\n\tconst handleMouseDown = useCallbackRef((event: MouseEvent) => {\n\t\tif (usage === \"mobileAndTabletOnly\" && window.innerWidth >= 768) return;\n\t\tif (usage === \"desktopOnly\" && window.innerWidth < 768) return;\n\n\t\tif (!dragContainerRef.current) return;\n\n\t\t// == Update all initial position properties stored in the positionRef\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\tpositionRef.current.x = event.clientX;\n\t\t\tpositionRef.current.left = dragContainerRef.current.scrollLeft;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\tpositionRef.current.y = event.clientY;\n\t\t\tpositionRef.current.top = dragContainerRef.current.scrollTop;\n\t\t}\n\n\t\tupdateCursor(dragContainerRef.current);\n\n\t\ton(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\ton(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\ton(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\t});\n\n\tconst refCallBack: RefCallback<TElement> = useCallbackRef((node) => {\n\t\tdragContainerRef.current = node;\n\n\t\tnode && handleScrollSnap(node);\n\n\t\tconst cleanup = on(\"mousedown\", dragContainerRef.current, handleMouseDown);\n\n\t\t// == Run cleanup manually on unmount if the user is using a version of react that doesn't support cleanup\n\t\tif (!node) {\n\t\t\tcleanup();\n\t\t\treturn;\n\t\t}\n\n\t\treturn cleanup;\n\t});\n\n\tconst getRootProps = () => ({\n\t\tclassName: cnMerge(\n\t\t\t`flex w-full cursor-grab snap-x snap-mandatory overflow-y-clip overflow-x-scroll\n\t\t\t[-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,\n\t\t\torientation === \"horizontal\" && \"flex-row\",\n\t\t\torientation === \"vertical\" && \"flex-col\",\n\t\t\tusage === \"mobileAndTabletOnly\" && \"md:cursor-default md:flex-col\",\n\t\t\tusage === \"desktopOnly\" && \"max-md:cursor-default max-md:flex-col\",\n\t\t\tclassNames?.base\n\t\t),\n\t\t\"data-part\": \"root\",\n\t\t\"data-scope\": \"drag-scroll\",\n\t\tref: refCallBack,\n\t});\n\n\tconst getItemProps = () => ({\n\t\tclassName: cnMerge(\"snap-center snap-always\", classNames?.item),\n\t\t\"data-part\": \"item\",\n\t\t\"data-scope\": \"drag-scroll\",\n\t});\n\n\treturn { getItemProps, getRootProps };\n};\n\nexport { useDragScroll };\n"]}
1
+ {"version":3,"sources":["../../../../src/components/ui/drag-scroll/utils.ts","../../../../src/components/ui/drag-scroll/use-drag-scroll.ts"],"names":[],"mappings":";;;;;;;AAGO,IAAM,YAAA,GAAe,CAA+B,OAAsB,KAAA;AAChF,EAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,UAAA;AACvB,EAAA,OAAA,CAAQ,MAAM,UAAa,GAAA,MAAA;AAC5B,CAAA;AAEO,IAAM,YAAA,GAAe,CAC3B,MAAA,EACA,OACI,KAAA;AACJ,EAAA,IAAI,WAAW,QAAU,EAAA;AACxB,IAAA,OAAA,CAAQ,MAAM,cAAiB,GAAA,MAAA;AAC/B,IAAA;AAAA;AAGD,EAAA,OAAA,CAAQ,MAAM,cAAiB,GAAA,EAAA;AAChC,CAAA;AAEO,IAAM,WAAA,GAAc,CAA+B,OAAsB,KAAA;AAC/E,EAAA,OAAA,CAAQ,MAAM,MAAS,GAAA,EAAA;AACvB,EAAA,OAAA,CAAQ,MAAM,UAAa,GAAA,EAAA;AAC5B,CAAA;AAGO,IAAM,gBAAA,GAAmB,CAAC,aAA+B,KAAA;AAC/D,EAAA,MAAM,mBAAmB,2BAA4B,EAAA;AAErD,EAAA,IAAI,CAAC,gBAAkB,EAAA;AACtB,IAAA,YAAA,CAAa,UAAU,aAAa,CAAA;AAAA,GAC9B,MAAA;AACN,IAAA,YAAA,CAAa,SAAS,aAAa,CAAA;AAAA;AAErC,CAAA;;;ACnBA,IAAM,aAAgB,GAAA,CAA+B,KAAmC,GAAA,EAAO,KAAA;AAC9F,EAAM,MAAA;AAAA,IACL,UAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,WAAc,GAAA,YAAA;AAAA,IACd,KAAQ,GAAA;AAAA,GACL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,gBAAA,CAAiB,SAAS,eAAe,CAAA;AAGzE,IAAA,IAAI,CAAC,IAAM,EAAA;AACV,MAAQ,OAAA,EAAA;AACR,MAAA;AAAA;AAGD,IAAO,OAAA,OAAA;AAAA,GACP,CAAA;AAED,EAAM,MAAA,YAAA,GAAe,CAAC,SAA4D,KAAA;AACjF,IAAM,MAAA,eAAA,GAAkB,UAAW,CAAA,cAAA,EAAgB,SAAS,CAAA;AAE5D,IAAO,OAAA;AAAA,MACN,GAAG,eAAA;AAAA,MACH,SAAW,EAAA,OAAA;AAAA,QACV,CAAA;AAAA,kFAAA,CAAA;AAAA,QAEA,gBAAgB,YAAgB,IAAA,UAAA;AAAA,QAChC,gBAAgB,UAAc,IAAA,UAAA;AAAA,QAC9B,UAAU,qBAAyB,IAAA,+BAAA;AAAA,QACnC,UAAU,aAAiB,IAAA,uCAAA;AAAA,QAC3B,UAAY,EAAA,IAAA;AAAA,QACZ,eAAgB,CAAA;AAAA,OACjB;AAAA,MACA,WAAa,EAAA,MAAA;AAAA,MACb,YAAc,EAAA,aAAA;AAAA,MACd,KAAK,WAAY,CAAA;AAAA,QAChB,WAAA;AAAA,QACC,eAA+D,EAAA;AAAA,OAChE;AAAA,KACF;AAAA,GACD;AAEA,EAAM,MAAA,YAAA,GAAe,CAAC,SAA4D,KAAA;AACjF,IAAM,MAAA,eAAA,GAAkB,UAAW,CAAA,cAAA,EAAgB,SAAS,CAAA;AAE5D,IAAO,OAAA;AAAA,MACN,GAAG,eAAA;AAAA,MACH,WAAW,OAAQ,CAAA,yBAAA,EAA2B,UAAY,EAAA,IAAA,EAAM,gBAAgB,SAAS,CAAA;AAAA,MACzF,WAAa,EAAA,MAAA;AAAA,MACb,YAAc,EAAA;AAAA,KACf;AAAA,GACD;AAEA,EAAO,OAAA,EAAE,cAAc,YAAa,EAAA;AACrC","file":"index.js","sourcesContent":["import { checkIsDeviceMobileOrTablet } from \"@zayne-labs/toolkit-core\";\n\n/* eslint-disable no-param-reassign -- Mutation is needed here since it's an element */\nexport const updateCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"grabbing\";\n\telement.style.userSelect = \"none\";\n};\n\nexport const onScrollSnap = <TElement extends HTMLElement>(\n\taction: \"remove\" | \"reset\",\n\telement: TElement\n) => {\n\tif (action === \"remove\") {\n\t\telement.style.scrollSnapType = \"none\";\n\t\treturn;\n\t}\n\n\telement.style.scrollSnapType = \"\";\n};\n\nexport const resetCursor = <TElement extends HTMLElement>(element: TElement) => {\n\telement.style.cursor = \"\";\n\telement.style.userSelect = \"\";\n};\n/* eslint-enable no-param-reassign -- Mutation is needed here since it's an element */\n\nexport const handleScrollSnap = (dragContainer: HTMLElement) => {\n\tconst isMobileOrTablet = checkIsDeviceMobileOrTablet();\n\n\tif (!isMobileOrTablet) {\n\t\tonScrollSnap(\"remove\", dragContainer);\n\t} else {\n\t\tonScrollSnap(\"reset\", dragContainer);\n\t}\n};\n","import { cnMerge } from \"@/lib/utils/cn\";\nimport { off, on } from \"@zayne-labs/toolkit-core\";\nimport { useCallbackRef } from \"@zayne-labs/toolkit-react\";\nimport { type InferProps, composeRefs, mergeProps } from \"@zayne-labs/toolkit-react/utils\";\nimport { type RefCallback, useRef } from \"react\";\nimport { handleScrollSnap, resetCursor, updateCursor } from \"./utils\";\n\ntype DragScrollProps<TElement extends HTMLElement> = {\n\tclassNames?: { base?: string; item?: string };\n\textraItemProps?: InferProps<HTMLElement>;\n\textraRootProps?: InferProps<TElement>;\n\torientation?: \"both\" | \"horizontal\" | \"vertical\";\n\tusage?: \"allScreens\" | \"desktopOnly\" | \"mobileAndTabletOnly\";\n};\n\nconst useDragScroll = <TElement extends HTMLElement>(props: DragScrollProps<TElement> = {}) => {\n\tconst {\n\t\tclassNames,\n\t\textraItemProps,\n\t\textraRootProps,\n\t\torientation = \"horizontal\",\n\t\tusage = \"allScreens\",\n\t} = props;\n\n\tconst dragContainerRef = useRef<TElement>(null);\n\n\tconst positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });\n\n\tconst handleMouseMove = useCallbackRef((event: MouseEvent) => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the horizontal scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dx = event.clientX - positionRef.current.x;\n\n\t\t\t// == Assign the scrollLeft of the container to the difference between its previous horizontal scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollLeft = positionRef.current.left - dx;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\t// == calculate the current change in the vertical scroll position based on the difference between the previous mouse position and the new mouse position\n\t\t\tconst dy = event.clientY - positionRef.current.y;\n\n\t\t\t// == Assign the scrollTop of the container to the difference between its previous vertical scroll position and the change in the mouse position\n\t\t\tdragContainerRef.current.scrollTop = positionRef.current.top - dy;\n\t\t}\n\t});\n\n\tconst handleMouseUpOrLeave = useCallbackRef(() => {\n\t\tif (!dragContainerRef.current) return;\n\n\t\toff(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\toff(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\toff(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\n\t\tresetCursor(dragContainerRef.current);\n\t});\n\n\tconst handleMouseDown = useCallbackRef((event: MouseEvent) => {\n\t\tif (usage === \"mobileAndTabletOnly\" && window.innerWidth >= 768) return;\n\t\tif (usage === \"desktopOnly\" && window.innerWidth < 768) return;\n\n\t\tif (!dragContainerRef.current) return;\n\n\t\t// == Update all initial position properties stored in the positionRef\n\t\tif (orientation === \"horizontal\" || orientation === \"both\") {\n\t\t\tpositionRef.current.x = event.clientX;\n\t\t\tpositionRef.current.left = dragContainerRef.current.scrollLeft;\n\t\t}\n\n\t\tif (orientation === \"vertical\" || orientation === \"both\") {\n\t\t\tpositionRef.current.y = event.clientY;\n\t\t\tpositionRef.current.top = dragContainerRef.current.scrollTop;\n\t\t}\n\n\t\tupdateCursor(dragContainerRef.current);\n\n\t\ton(\"mousemove\", dragContainerRef.current, handleMouseMove);\n\t\ton(\"mouseup\", dragContainerRef.current, handleMouseUpOrLeave);\n\t\ton(\"mouseleave\", dragContainerRef.current, handleMouseUpOrLeave);\n\t});\n\n\tconst refCallBack: RefCallback<TElement> = useCallbackRef((node) => {\n\t\tdragContainerRef.current = node;\n\n\t\tnode && handleScrollSnap(node);\n\n\t\tconst cleanup = on(\"mousedown\", dragContainerRef.current, handleMouseDown);\n\n\t\t// == Run cleanup manually on unmount if the user is using a version of react that doesn't support cleanup\n\t\tif (!node) {\n\t\t\tcleanup();\n\t\t\treturn;\n\t\t}\n\n\t\treturn cleanup;\n\t});\n\n\tconst getRootProps = (rootProps?: DragScrollProps<TElement>[\"extraRootProps\"]) => {\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`flex w-full cursor-grab snap-x snap-mandatory overflow-y-clip overflow-x-scroll\n\t\t\t\t[-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,\n\t\t\t\torientation === \"horizontal\" && \"flex-row\",\n\t\t\t\torientation === \"vertical\" && \"flex-col\",\n\t\t\t\tusage === \"mobileAndTabletOnly\" && \"md:cursor-default md:flex-col\",\n\t\t\t\tusage === \"desktopOnly\" && \"max-md:cursor-default max-md:flex-col\",\n\t\t\t\tclassNames?.base,\n\t\t\t\tmergedRootProps.className\n\t\t\t),\n\t\t\t\"data-part\": \"root\",\n\t\t\t\"data-scope\": \"drag-scroll\",\n\t\t\tref: composeRefs([\n\t\t\t\trefCallBack,\n\t\t\t\t(mergedRootProps as { ref?: React.Ref<TElement> } | undefined)?.ref,\n\t\t\t]),\n\t\t};\n\t};\n\n\tconst getItemProps = (itemProps?: DragScrollProps<TElement>[\"extraItemProps\"]) => {\n\t\tconst mergedItemProps = mergeProps(extraItemProps, itemProps);\n\n\t\treturn {\n\t\t\t...mergedItemProps,\n\t\t\tclassName: cnMerge(\"snap-center snap-always\", classNames?.item, mergedItemProps.className),\n\t\t\t\"data-part\": \"item\",\n\t\t\t\"data-scope\": \"drag-scroll\",\n\t\t};\n\t};\n\n\treturn { getItemProps, getRootProps };\n};\n\nexport { useDragScroll };\n"]}
@@ -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,12 +1,12 @@
1
+ import { cnMerge } from '../../chunk-OHG7GB7O.js';
2
+ import '../../chunk-PZ5AY32C.js';
1
3
  import * as React from 'react';
2
4
  import { useRef, useState } from 'react';
3
- import { twMerge } from 'tailwind-merge';
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
- // src/components/ui/drop-zone/drop-zone.tsx
9
- var cnMerge = (...classNames) => twMerge(classNames);
10
10
  var useDropZone = (props) => {
11
11
  const inputRef = useRef(null);
12
12
  const {
@@ -20,7 +20,6 @@ var useDropZone = (props) => {
20
20
  onUpload,
21
21
  onUploadError,
22
22
  onUploadSuccess,
23
- ref,
24
23
  validationSettings,
25
24
  validator
26
25
  // eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Can be undefined
@@ -29,6 +28,7 @@ var useDropZone = (props) => {
29
28
  const [acceptedFiles, setAcceptedFiles] = useState([]);
30
29
  const handleFileUpload = useCallbackRef(
31
30
  (event) => {
31
+ if (event.defaultPrevented) return;
32
32
  if (event.type === "drop") {
33
33
  event.preventDefault();
34
34
  toggleIsDragging(false);
@@ -62,47 +62,46 @@ var useDropZone = (props) => {
62
62
  };
63
63
  const getRenderProps = () => ({ acceptedFiles, inputRef, isDragging });
64
64
  const getChildren = () => isFunction(children) ? children(getRenderProps()) : children;
65
- const getRootProps = () => ({
66
- ...extraRootProps,
67
- className: cnMerge(
68
- "relative isolate flex flex-col",
69
- extraRootProps?.className,
70
- classNames?.base,
71
- isDragging && ["opacity-60", classNames?.activeDrag]
72
- ),
73
- "data-active-drag": isDragging,
74
- "data-part": "root",
75
- "data-scope": "dropzone",
76
- onDragEnter: handleDragOver,
77
- onDragLeave: handleDragLeave,
78
- onDragOver: handleDragOver,
79
- onDrop: handleFileUpload
80
- });
81
- const refCallback = useCallbackRef((node) => {
82
- inputRef.current = node;
83
- if (!ref) return;
84
- if (isFunction(ref)) {
85
- return ref(node);
86
- }
87
- ref.current = node;
88
- });
89
- const getInputProps = () => ({
90
- ...extraInputProps,
91
- accept: allowedFileTypes ? allowedFileTypes.join(", ") : extraInputProps?.accept,
92
- className: cnMerge(
93
- "absolute inset-0 z-[100] cursor-pointer opacity-0",
94
- extraInputProps?.className,
95
- classNames?.input
96
- ),
97
- "data-part": "input",
98
- "data-scope": "dropzone",
99
- onChange: (event) => {
100
- handleFileUpload(event);
101
- extraInputProps?.onChange?.(event);
102
- },
103
- ref: refCallback,
104
- type: "file"
105
- });
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
+ };
106
105
  return {
107
106
  getChildren,
108
107
  getInputProps,
@@ -111,8 +110,8 @@ var useDropZone = (props) => {
111
110
  handleDragLeave,
112
111
  handleDragOver,
113
112
  handleFileUpload,
114
- isDragging,
115
- ref
113
+ inputRef,
114
+ isDragging
116
115
  };
117
116
  };
118
117
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/cn.ts","../../../../src/components/ui/drop-zone/useDropZone.ts","../../../../src/components/ui/drop-zone/drop-zone.tsx"],"names":[],"mappings":";;;;;;;;AAEO,IAAM,OAAU,GAAA,CAAA,GAAI,UAAiC,KAAA,OAAA,CAAQ,UAAU,CAAA;AC+CjE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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":["import { type ClassNameValue, twMerge } from \"tailwind-merge\";\n\nexport const cnMerge = (...classNames: ClassNameValue[]) => twMerge(classNames);\n","\"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,MA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B,WAAa,EAAA,OAAA;AAAA,MACb,YAAc,EAAA,UAAA;AAAA,MACd,QAAA,EAAU,CAAC,KAA+C,KAAA;AACzD,QAAA,gBAAA,CAAiB,KAAK,CAAA;AACtB,QAAA,gBAAA,CAAiB,WAAW,KAAK,CAAA;AAAA,OAClC;AAAA,MACA,KAAK,WAAY,CAAA,CAAC,QAAU,EAAA,gBAAA,CAAiB,GAAG,CAAC,CAAA;AAAA,MACjD,IAAM,EAAA;AAAA,KACP;AAAA,GACD;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,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 } 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,24 @@ 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 const form_FormController: typeof FormController;
150
+ declare const form_FormDescription: typeof FormDescription;
151
+ declare const form_FormErrorMessage: typeof FormErrorMessage;
152
+ declare const form_FormErrorMessagePrimitive: typeof FormErrorMessagePrimitive;
153
+ declare const form_FormInput: typeof FormInput;
154
+ declare const form_FormInputGroup: typeof FormInputGroup;
155
+ declare const form_FormInputLeftItem: typeof FormInputLeftItem;
156
+ declare const form_FormInputPrimitive: typeof FormInputPrimitive;
157
+ declare const form_FormInputRightItem: typeof FormInputRightItem;
158
+ declare const form_FormItem: typeof FormItem;
159
+ declare const form_FormItemContext: typeof FormItemContext;
160
+ declare const form_FormLabel: typeof FormLabel;
161
+ declare const form_FormRoot: typeof FormRoot;
162
+ declare const form_FormTextArea: typeof FormTextArea;
163
+ declare const form_FormTextAreaPrimitive: typeof FormTextAreaPrimitive;
164
+ declare namespace form {
165
+ export { form_FormController as FormController, form_FormDescription as FormDescription, form_FormErrorMessage as FormErrorMessage, form_FormErrorMessagePrimitive as FormErrorMessagePrimitive, form_FormInput as FormInput, form_FormInputGroup as FormInputGroup, form_FormInputLeftItem as FormInputLeftItem, form_FormInputPrimitive as FormInputPrimitive, form_FormInputRightItem as FormInputRightItem, form_FormItem as FormItem, form_FormItemContext as FormItemContext, form_FormLabel as FormLabel, form_FormRoot as FormRoot, form_FormTextArea as FormTextArea, form_FormTextAreaPrimitive as FormTextAreaPrimitive };
166
+ }
167
+
168
+ export { form as Form, FormController, FormDescription, FormErrorMessage, FormErrorMessagePrimitive, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormItem, FormItemContext, FormLabel, FormRoot, FormTextArea, FormTextAreaPrimitive, useStrictFormItemContext as useFormItemContext };