@zayne-labs/ui-react 0.1.5 → 0.2.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 (54) hide show
  1. package/dist/esm/chunk-CB2EZJYW.js +31 -0
  2. package/dist/esm/chunk-CB2EZJYW.js.map +1 -0
  3. package/dist/esm/chunk-E3UC4AGS.js +119 -0
  4. package/dist/esm/chunk-E3UC4AGS.js.map +1 -0
  5. package/dist/esm/chunk-HKPJTORQ.js +3 -0
  6. package/dist/esm/chunk-HKPJTORQ.js.map +1 -0
  7. package/dist/esm/chunk-JKLRBPJZ.js +40 -0
  8. package/dist/esm/chunk-JKLRBPJZ.js.map +1 -0
  9. package/dist/esm/chunk-NCS3WKFW.js +50 -0
  10. package/dist/esm/chunk-NCS3WKFW.js.map +1 -0
  11. package/dist/esm/chunk-PKN52DWQ.js +363 -0
  12. package/dist/esm/chunk-PKN52DWQ.js.map +1 -0
  13. package/dist/esm/chunk-PNYEIX7F.js +3 -0
  14. package/dist/esm/chunk-PNYEIX7F.js.map +1 -0
  15. package/dist/esm/chunk-PW4AIAWC.js +125 -0
  16. package/dist/esm/chunk-PW4AIAWC.js.map +1 -0
  17. package/dist/esm/chunk-PXYYL2LL.js +45 -0
  18. package/dist/esm/chunk-PXYYL2LL.js.map +1 -0
  19. package/dist/esm/{chunk-MPOYLILK.js → chunk-RJQIINNX.js} +11 -7
  20. package/dist/esm/chunk-RJQIINNX.js.map +1 -0
  21. package/dist/esm/chunk-VMJ2L3VC.js +274 -0
  22. package/dist/esm/chunk-VMJ2L3VC.js.map +1 -0
  23. package/dist/esm/common/for/index.d.ts +20 -5
  24. package/dist/esm/common/for/index.js +1 -1
  25. package/dist/esm/common/index.d.ts +8 -0
  26. package/dist/esm/common/index.js +9 -0
  27. package/dist/esm/common/index.js.map +1 -0
  28. package/dist/esm/common/show/index.d.ts +10 -6
  29. package/dist/esm/common/show/index.js +2 -41
  30. package/dist/esm/common/show/index.js.map +1 -1
  31. package/dist/esm/common/switch/index.d.ts +10 -6
  32. package/dist/esm/common/switch/index.js +2 -31
  33. package/dist/esm/common/switch/index.js.map +1 -1
  34. package/dist/esm/common/teleport/index.js +1 -28
  35. package/dist/esm/common/teleport/index.js.map +1 -1
  36. package/dist/esm/index.d.ts +16 -2
  37. package/dist/esm/index.js +14 -1
  38. package/dist/esm/ui/card/index.js +4 -43
  39. package/dist/esm/ui/card/index.js.map +1 -1
  40. package/dist/esm/ui/carousel/index.d.ts +5 -3
  41. package/dist/esm/ui/carousel/index.js +4 -272
  42. package/dist/esm/ui/carousel/index.js.map +1 -1
  43. package/dist/esm/ui/drag-scroll/index.js +2 -117
  44. package/dist/esm/ui/drag-scroll/index.js.map +1 -1
  45. package/dist/esm/ui/drop-zone/index.js +2 -123
  46. package/dist/esm/ui/drop-zone/index.js.map +1 -1
  47. package/dist/esm/ui/form/index.js +4 -361
  48. package/dist/esm/ui/form/index.js.map +1 -1
  49. package/dist/esm/ui/index.d.ts +11 -0
  50. package/dist/esm/ui/index.js +12 -0
  51. package/dist/esm/ui/index.js.map +1 -0
  52. package/package.json +6 -14
  53. package/dist/esm/chunk-MPOYLILK.js.map +0 -1
  54. package/dist/esm/for-C3T5FbXd.d.ts +0 -15
@@ -0,0 +1,31 @@
1
+ import { useState } from 'react';
2
+ import { useEffectOnce, useMountEffect } from '@zayne-labs/toolkit-react';
3
+ import { isString } from '@zayne-labs/toolkit-type-helpers';
4
+ import { createPortal } from 'react-dom';
5
+
6
+ // src/components/common/teleport/teleport.tsx
7
+ function Teleport(props) {
8
+ const { children, insertPosition, to } = props;
9
+ const [reactPortal, setReactPortal] = useState(null);
10
+ useEffectOnce(() => {
11
+ if (!to || !insertPosition) return;
12
+ const destination = isString(to) ? document.querySelector(to) : to;
13
+ const tempWrapper = document.createElement("div");
14
+ tempWrapper.style.display = "contents";
15
+ destination?.insertAdjacentElement(insertPosition, tempWrapper);
16
+ setReactPortal(createPortal(children, tempWrapper));
17
+ return () => {
18
+ tempWrapper.remove();
19
+ };
20
+ });
21
+ useMountEffect(() => {
22
+ if (!to || insertPosition) return;
23
+ const destination = isString(to) ? document.querySelector(to) : to;
24
+ destination && setReactPortal(createPortal(children, destination));
25
+ });
26
+ return reactPortal;
27
+ }
28
+
29
+ export { Teleport };
30
+ //# sourceMappingURL=chunk-CB2EZJYW.js.map
31
+ //# sourceMappingURL=chunk-CB2EZJYW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/common/teleport/teleport.tsx"],"names":[],"mappings":";;;;;;AAeA,SAAS,SAAS,KAAoB,EAAA;AACrC,EAAA,MAAM,EAAE,QAAA,EAAU,cAAgB,EAAA,EAAA,EAAO,GAAA,KAAA;AAEzC,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAmC,IAAI,CAAA;AAE7E,EAAA,aAAA,CAAc,MAAM;AACnB,IAAI,IAAA,CAAC,EAAM,IAAA,CAAC,cAAgB,EAAA;AAE5B,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAM,MAAA,WAAA,GAAc,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA;AAChD,IAAA,WAAA,CAAY,MAAM,OAAU,GAAA,UAAA;AAE5B,IAAa,WAAA,EAAA,qBAAA,CAAsB,gBAAgB,WAAW,CAAA;AAE9D,IAAe,cAAA,CAAA,YAAA,CAAa,QAAU,EAAA,WAAW,CAAC,CAAA;AAElD,IAAA,OAAO,MAAM;AACZ,MAAA,WAAA,CAAY,MAAO,EAAA;AAAA,KACpB;AAAA,GACA,CAAA;AAED,EAAA,cAAA,CAAe,MAAM;AACpB,IAAI,IAAA,CAAC,MAAM,cAAgB,EAAA;AAE3B,IAAA,MAAM,cAAc,QAAS,CAAA,EAAE,IAAI,QAAS,CAAA,aAAA,CAA2B,EAAE,CAAI,GAAA,EAAA;AAE7E,IAAA,WAAA,IAAe,cAAe,CAAA,YAAA,CAAa,QAAU,EAAA,WAAW,CAAC,CAAA;AAAA,GACjE,CAAA;AAED,EAAO,OAAA,WAAA;AACR","file":"chunk-CB2EZJYW.js","sourcesContent":["import * as React from \"react\";\n\nimport { useEffectOnce, useMountEffect } from \"@zayne-labs/toolkit-react\";\nimport { type AnyString, isString } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\ntype ValidHtmlTags = keyof HTMLElementTagNameMap;\n\ntype PortalProps = {\n\tchildren: React.ReactNode;\n\tinsertPosition?: InsertPosition;\n\tto?: AnyString | HTMLElement | ValidHtmlTags | null;\n};\n\nfunction Teleport(props: PortalProps) {\n\tconst { children, insertPosition, to } = props;\n\n\tconst [reactPortal, setReactPortal] = useState<React.ReactPortal | null>(null);\n\n\tuseEffectOnce(() => {\n\t\tif (!to || !insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tconst tempWrapper = document.createElement(\"div\");\n\t\ttempWrapper.style.display = \"contents\";\n\n\t\tdestination?.insertAdjacentElement(insertPosition, tempWrapper);\n\n\t\tsetReactPortal(createPortal(children, tempWrapper));\n\n\t\treturn () => {\n\t\t\ttempWrapper.remove();\n\t\t};\n\t});\n\n\tuseMountEffect(() => {\n\t\tif (!to || insertPosition) return;\n\n\t\tconst destination = isString(to) ? document.querySelector<HTMLElement>(to) : to;\n\n\t\tdestination && setReactPortal(createPortal(children, destination));\n\t});\n\n\treturn reactPortal;\n}\n\nexport { Teleport };\n"]}
@@ -0,0 +1,119 @@
1
+ import { cnMerge } from './chunk-OHG7GB7O.js';
2
+ import { off, on, checkIsDeviceMobileOrTablet } from '@zayne-labs/toolkit-core';
3
+ import { useCallbackRef } from '@zayne-labs/toolkit-react';
4
+ import { mergeTwoProps, composeRefs } from '@zayne-labs/toolkit-react/utils';
5
+ import { useRef } from 'react';
6
+
7
+ var updateCursor = (element) => {
8
+ element.style.cursor = "grabbing";
9
+ element.style.userSelect = "none";
10
+ };
11
+ var onScrollSnap = (action, element) => {
12
+ if (action === "remove") {
13
+ element.style.scrollSnapType = "none";
14
+ return;
15
+ }
16
+ element.style.scrollSnapType = "";
17
+ };
18
+ var resetCursor = (element) => {
19
+ element.style.cursor = "";
20
+ element.style.userSelect = "";
21
+ };
22
+ var handleScrollSnap = (dragContainer) => {
23
+ const isMobileOrTablet = checkIsDeviceMobileOrTablet();
24
+ if (!isMobileOrTablet) {
25
+ onScrollSnap("remove", dragContainer);
26
+ } else {
27
+ onScrollSnap("reset", dragContainer);
28
+ }
29
+ };
30
+
31
+ // src/components/ui/drag-scroll/use-drag-scroll.ts
32
+ var useDragScroll = (props = {}) => {
33
+ const {
34
+ classNames,
35
+ extraItemProps,
36
+ extraRootProps,
37
+ orientation = "horizontal",
38
+ usage = "allScreens"
39
+ } = props;
40
+ const dragContainerRef = useRef(null);
41
+ const positionRef = useRef({ left: 0, top: 0, x: 0, y: 0 });
42
+ const handleMouseMove = useCallbackRef((event) => {
43
+ if (!dragContainerRef.current) return;
44
+ if (orientation === "horizontal" || orientation === "both") {
45
+ const dx = event.clientX - positionRef.current.x;
46
+ dragContainerRef.current.scrollLeft = positionRef.current.left - dx;
47
+ }
48
+ if (orientation === "vertical" || orientation === "both") {
49
+ const dy = event.clientY - positionRef.current.y;
50
+ dragContainerRef.current.scrollTop = positionRef.current.top - dy;
51
+ }
52
+ });
53
+ const handleMouseUpOrLeave = useCallbackRef(() => {
54
+ if (!dragContainerRef.current) return;
55
+ off("mousemove", dragContainerRef.current, handleMouseMove);
56
+ off("mouseup", dragContainerRef.current, handleMouseUpOrLeave);
57
+ off("mouseleave", dragContainerRef.current, handleMouseUpOrLeave);
58
+ resetCursor(dragContainerRef.current);
59
+ });
60
+ const handleMouseDown = useCallbackRef((event) => {
61
+ if (usage === "mobileAndTabletOnly" && window.innerWidth >= 768) return;
62
+ if (usage === "desktopOnly" && window.innerWidth < 768) return;
63
+ if (!dragContainerRef.current) return;
64
+ if (orientation === "horizontal" || orientation === "both") {
65
+ positionRef.current.x = event.clientX;
66
+ positionRef.current.left = dragContainerRef.current.scrollLeft;
67
+ }
68
+ if (orientation === "vertical" || orientation === "both") {
69
+ positionRef.current.y = event.clientY;
70
+ positionRef.current.top = dragContainerRef.current.scrollTop;
71
+ }
72
+ updateCursor(dragContainerRef.current);
73
+ on("mousemove", dragContainerRef.current, handleMouseMove);
74
+ on("mouseup", dragContainerRef.current, handleMouseUpOrLeave);
75
+ on("mouseleave", dragContainerRef.current, handleMouseUpOrLeave);
76
+ });
77
+ const refCallBack = useCallbackRef((node) => {
78
+ dragContainerRef.current = node;
79
+ node && handleScrollSnap(node);
80
+ const cleanup = on("mousedown", dragContainerRef.current, handleMouseDown);
81
+ return cleanup;
82
+ });
83
+ const getRootProps = (rootProps) => {
84
+ const mergedRootProps = mergeTwoProps(extraRootProps, rootProps);
85
+ return {
86
+ ...mergedRootProps,
87
+ className: cnMerge(
88
+ `flex w-full cursor-grab snap-x snap-mandatory overflow-y-clip overflow-x-scroll
89
+ [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,
90
+ orientation === "horizontal" && "flex-row",
91
+ orientation === "vertical" && "flex-col",
92
+ usage === "mobileAndTabletOnly" && "md:cursor-default md:flex-col",
93
+ usage === "desktopOnly" && "max-md:cursor-default max-md:flex-col",
94
+ classNames?.base,
95
+ mergedRootProps.className
96
+ ),
97
+ "data-part": "root",
98
+ "data-scope": "drag-scroll",
99
+ ref: composeRefs([
100
+ refCallBack,
101
+ mergedRootProps?.ref
102
+ ])
103
+ };
104
+ };
105
+ const getItemProps = (itemProps) => {
106
+ const mergedItemProps = mergeTwoProps(extraItemProps, itemProps);
107
+ return {
108
+ ...mergedItemProps,
109
+ className: cnMerge("snap-center snap-always", classNames?.item, mergedItemProps.className),
110
+ "data-part": "item",
111
+ "data-scope": "drag-scroll"
112
+ };
113
+ };
114
+ return { getItemProps, getRootProps };
115
+ };
116
+
117
+ export { useDragScroll };
118
+ //# sourceMappingURL=chunk-E3UC4AGS.js.map
119
+ //# sourceMappingURL=chunk-E3UC4AGS.js.map
@@ -0,0 +1 @@
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,GAAA,KAAA;AAEJ,EAAM,MAAA,gBAAA,GAAmB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,OAAA,OAAA;AAAA,GACP,CAAA;AAED,EAAM,MAAA,YAAA,GAAe,CAAC,SAA4D,KAAA;AACjF,IAAM,MAAA,eAAA,GAAkB,aAAc,CAAA,cAAA,EAAgB,SAAS,CAAA;AAE/D,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,CACpB,SACI,KAAA;AACJ,IAAM,MAAA,eAAA,GAAkB,aAAc,CAAA,cAAA,EAAgB,SAAS,CAAA;AAE/D,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":"chunk-E3UC4AGS.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, mergeTwoProps } 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?: Omit<InferProps<TElement>, \"children\">;\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\treturn cleanup;\n\t});\n\n\tconst getRootProps = (rootProps?: DragScrollProps<TElement>[\"extraRootProps\"]) => {\n\t\tconst mergedRootProps = mergeTwoProps(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 = <TItemElement extends HTMLElement>(\n\t\titemProps?: DragScrollProps<TItemElement>[\"extraItemProps\"]\n\t) => {\n\t\tconst mergedItemProps = mergeTwoProps(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"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=chunk-HKPJTORQ.js.map
3
+ //# sourceMappingURL=chunk-HKPJTORQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-HKPJTORQ.js"}
@@ -0,0 +1,40 @@
1
+ import { __export } from './chunk-PZ5AY32C.js';
2
+ import 'react';
3
+ import { getSlotElement, getOtherChildren } from '@zayne-labs/toolkit-react/utils';
4
+ import { isFunction } from '@zayne-labs/toolkit-type-helpers';
5
+
6
+ var defaultConditionSymbol = Symbol("condition-default");
7
+ function SwitchRoot(props) {
8
+ const { children, condition = defaultConditionSymbol } = props;
9
+ const defaultCase = getSlotElement(children, SwitchDefault, {
10
+ errorMessage: "Only one <Switch.Default> component is allowed",
11
+ throwOnMultipleSlotMatch: true
12
+ });
13
+ const childrenCasesArray = getOtherChildren(children, SwitchDefault);
14
+ const matchedCase = childrenCasesArray.find(
15
+ (child) => condition === defaultConditionSymbol ? child.props.when : child.props.when === condition
16
+ );
17
+ return matchedCase ?? defaultCase;
18
+ }
19
+ function SwitchMatch({ children, when }) {
20
+ if (when == null || when === false) {
21
+ return null;
22
+ }
23
+ return isFunction(children) ? children(when) : children;
24
+ }
25
+ function SwitchDefault({ children }) {
26
+ return children;
27
+ }
28
+ SwitchDefault.slot = Symbol.for("switch-default");
29
+
30
+ // src/components/common/switch/switch-parts.ts
31
+ var switch_parts_exports = {};
32
+ __export(switch_parts_exports, {
33
+ Default: () => SwitchDefault,
34
+ Match: () => SwitchMatch,
35
+ Root: () => SwitchRoot
36
+ });
37
+
38
+ export { SwitchDefault, SwitchMatch, SwitchRoot, switch_parts_exports };
39
+ //# sourceMappingURL=chunk-JKLRBPJZ.js.map
40
+ //# sourceMappingURL=chunk-JKLRBPJZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/common/switch/switch.tsx","../../src/components/common/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Content":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getOtherChildren, getSlotElement } from \"@zayne-labs/toolkit-react/utils\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ValidSwitchComponentType = React.ReactElement<SwitchMatchProps>;\n\ntype SwitchProps<TCondition> = {\n\tchildren: ValidSwitchComponentType | ValidSwitchComponentType[];\n\tcondition?: TCondition;\n};\n\ntype SwitchMatchProps<TWhen = unknown> = {\n\tchildren: React.ReactNode | ((whenValue: TWhen) => React.ReactNode);\n\twhen: false | TWhen | null | undefined;\n};\n\nconst defaultConditionSymbol = Symbol(\"condition-default\");\n\nexport function SwitchRoot<TCondition = true>(props: SwitchProps<TCondition>) {\n\tconst { children, condition = defaultConditionSymbol } = props;\n\n\tconst defaultCase = getSlotElement(children, SwitchDefault, {\n\t\terrorMessage: \"Only one <Switch.Default> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst childrenCasesArray = getOtherChildren(children, SwitchDefault);\n\n\tconst matchedCase = childrenCasesArray.find((child) =>\n\t\tcondition === defaultConditionSymbol ? child.props.when : child.props.when === condition\n\t);\n\n\treturn matchedCase ?? defaultCase;\n}\n\nexport function SwitchMatch<TWhen>({ children, when }: SwitchMatchProps<TWhen>) {\n\tif (when == null || when === false) {\n\t\treturn null;\n\t}\n\n\treturn isFunction(children) ? children(when) : children;\n}\n\nexport function SwitchDefault({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nSwitchDefault.slot = Symbol.for(\"switch-default\");\n","export { SwitchDefault as Default, SwitchMatch as Match, SwitchRoot as Root } from \"./switch\";\n"]}
@@ -0,0 +1,50 @@
1
+ import { __export } from './chunk-PZ5AY32C.js';
2
+ import 'react';
3
+ import { getSlotElement, getOtherChildren } from '@zayne-labs/toolkit-react/utils';
4
+ import { isFunction, AssertionError } from '@zayne-labs/toolkit-type-helpers';
5
+
6
+ function ShowRoot({ children, fallback, when }) {
7
+ if ((when == null || when === false) && !isFunction(children)) {
8
+ const fallBackSlot = getSlotElement(children, ShowFallback, {
9
+ errorMessage: "Only one <Show.Fallback> or <Show.OtherWise> component is allowed",
10
+ throwOnMultipleSlotMatch: true
11
+ });
12
+ if (fallBackSlot && fallback) {
13
+ throw new AssertionError(`
14
+ The fallback prop and <Show.Fallback>/<Show.OtherWise> cannot be used at the same time.
15
+ `);
16
+ }
17
+ return fallBackSlot ?? fallback;
18
+ }
19
+ if (when == null || when === false) {
20
+ return fallback;
21
+ }
22
+ const resolvedChildren = isFunction(children) ? children(when) : children;
23
+ const contentSlot = getSlotElement(resolvedChildren, ShowContent, {
24
+ errorMessage: "Only one <Show.Content> component is allowed",
25
+ throwOnMultipleSlotMatch: true
26
+ });
27
+ const otherChildren = getOtherChildren(resolvedChildren, [ShowFallback, ShowContent]);
28
+ return contentSlot ?? otherChildren;
29
+ }
30
+ function ShowContent({ children }) {
31
+ return children;
32
+ }
33
+ ShowContent.slot = Symbol.for("content");
34
+ function ShowFallback({ children }) {
35
+ return children;
36
+ }
37
+ ShowFallback.slot = Symbol.for("show-fallback");
38
+
39
+ // src/components/common/show/show-parts.ts
40
+ var show_parts_exports = {};
41
+ __export(show_parts_exports, {
42
+ Content: () => ShowContent,
43
+ Fallback: () => ShowFallback,
44
+ OtherWise: () => ShowFallback,
45
+ Root: () => ShowRoot
46
+ });
47
+
48
+ export { ShowContent, ShowFallback, ShowRoot, show_parts_exports };
49
+ //# sourceMappingURL=chunk-NCS3WKFW.js.map
50
+ //# sourceMappingURL=chunk-NCS3WKFW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/common/show/show.tsx","../../src/components/common/show/show-parts.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,QAAgB,CAAA,EAAE,QAAU,EAAA,QAAA,EAAU,MAA0B,EAAA;AAC/E,EAAA,IAAA,CAAK,QAAQ,IAAQ,IAAA,IAAA,KAAS,UAAU,CAAC,UAAA,CAAW,QAAQ,CAAG,EAAA;AAC9D,IAAM,MAA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AAA,MAAA;AAAA,CAAA,CAAA","file":"chunk-NCS3WKFW.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport { getOtherChildren, getSlotElement } from \"@zayne-labs/toolkit-react/utils\";\nimport { AssertionError, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\n\ntype ShowProps<TWhen> = {\n\tchildren: React.ReactNode | ((whenValue: TWhen) => React.ReactNode);\n\tfallback?: React.ReactNode;\n\twhen: false | TWhen | null | undefined;\n};\n\nexport function ShowRoot<TWhen>({ children, fallback, when }: ShowProps<TWhen>) {\n\tif ((when == null || when === false) && !isFunction(children)) {\n\t\tconst fallBackSlot = getSlotElement(children, ShowFallback, {\n\t\t\terrorMessage: \"Only one <Show.Fallback> or <Show.OtherWise> component is allowed\",\n\t\t\tthrowOnMultipleSlotMatch: true,\n\t\t});\n\n\t\tif (fallBackSlot && fallback) {\n\t\t\tthrow new AssertionError(`\n\t\t\tThe fallback prop and <Show.Fallback>/<Show.OtherWise> cannot be used at the same time.\n\t\t`);\n\t\t}\n\n\t\treturn fallBackSlot ?? fallback;\n\t}\n\n\tif (when == null || when === false) {\n\t\treturn fallback;\n\t}\n\n\tconst resolvedChildren = isFunction(children) ? children(when) : children;\n\n\tconst contentSlot = getSlotElement(resolvedChildren, ShowContent, {\n\t\terrorMessage: \"Only one <Show.Content> component is allowed\",\n\t\tthrowOnMultipleSlotMatch: true,\n\t});\n\n\tconst otherChildren = getOtherChildren(resolvedChildren, [ShowFallback, ShowContent]);\n\n\treturn contentSlot ?? otherChildren;\n}\n\nexport function ShowContent({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowContent.slot = Symbol.for(\"content\");\n\nexport function ShowFallback({ children }: { children: React.ReactNode }) {\n\treturn children;\n}\nShowFallback.slot = Symbol.for(\"show-fallback\");\n","export {\n\tShowContent as Content,\n\tShowFallback as Fallback,\n\tShowFallback as OtherWise,\n\tShowRoot as Root,\n} from \"./show\";\n"]}
@@ -0,0 +1,363 @@
1
+ import { cnMerge } from './chunk-OHG7GB7O.js';
2
+ import { getElementList } from './chunk-RJQIINNX.js';
3
+ import { __export } from './chunk-PZ5AY32C.js';
4
+ import * as React2 from 'react';
5
+ import { useId, useMemo, useRef, useEffect, Fragment } from 'react';
6
+ import { toArray } from '@zayne-labs/toolkit-core';
7
+ import { createCustomContext, useToggle, ContextError } from '@zayne-labs/toolkit-react';
8
+ import { getSlotElement, getOtherChildren } from '@zayne-labs/toolkit-react/utils';
9
+ import { Controller, FormProvider, useFormState, useFormContext } from 'react-hook-form';
10
+
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
+ "path",
13
+ {
14
+ fill: "currentColor",
15
+ d: "M15.175 8.325q.725.725 1.063 1.65t.237 1.9q0 .375-.275.638t-.65.262t-.638-.262t-.262-.638q.125-.65-.075-1.25T13.95 9.6t-1.025-.65t-1.275-.1q-.375 0-.638-.275t-.262-.65t.263-.637t.637-.263q.95-.1 1.875.238t1.65 1.062M12 6q-.475 0-.925.037t-.9.138q-.425.075-.763-.125t-.462-.6t.088-.775t.612-.45q.575-.125 1.163-.175T12 4q3.425 0 6.263 1.8t4.337 4.85q.1.2.15.413t.05.437t-.038.438t-.137.412q-.45 1-1.112 1.875t-1.463 1.6q-.3.275-.7.225t-.65-.4t-.212-.763t.337-.687q.6-.575 1.1-1.25t.875-1.45q-1.25-2.525-3.613-4.012T12 6m0 13q-3.35 0-6.125-1.812T1.5 12.425q-.125-.2-.187-.437T1.25 11.5t.05-.475t.175-.45q.5-1 1.163-1.912T4.15 7L2.075 4.9q-.275-.3-.262-.712T2.1 3.5t.7-.275t.7.275l17 17q.275.275.288.688t-.288.712q-.275.275-.7.275t-.7-.275l-3.5-3.45q-.875.275-1.775.413T12 19M5.55 8.4q-.725.65-1.325 1.425T3.2 11.5q1.25 2.525 3.613 4.013T12 17q.5 0 .975-.062t.975-.138l-.9-.95q-.275.075-.525.113T12 16q-1.875 0-3.188-1.312T7.5 11.5q0-.275.038-.525t.112-.525zm4.2 4.2"
16
+ }
17
+ ));
18
+ var EyeIconVisible = (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(
19
+ "path",
20
+ {
21
+ fill: "currentColor",
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
+ }
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
+ };
34
+ var [StrictFormItemProvider, useStrictFormItemContext] = createCustomContext({
35
+ hookName: "useFormItemContext",
36
+ providerName: "FormItem"
37
+ });
38
+ var [LaxFormItemProvider, useLaxFormItemContext] = createCustomContext({
39
+ hookName: "useLaxFormItemContext",
40
+ providerName: "FormItem",
41
+ strict: false
42
+ });
43
+
44
+ // src/components/ui/form/form.tsx
45
+ function FormRoot(props) {
46
+ const { children, className, methods, ...restOfProps } = props;
47
+ return /* @__PURE__ */ React2.createElement(FormProvider, { ...methods }, /* @__PURE__ */ React2.createElement(
48
+ "form",
49
+ {
50
+ className: cnMerge("flex flex-col", className),
51
+ ...restOfProps,
52
+ "data-scope": "form",
53
+ "data-part": "root"
54
+ },
55
+ children
56
+ ));
57
+ }
58
+ function FormItem(props) {
59
+ const { children, className, name, withWrapper = true } = props;
60
+ const uniqueId = useId();
61
+ const value = useMemo(
62
+ () => ({ name: String(name), uniqueId: `${String(name)}-(${uniqueId})` }),
63
+ [name, uniqueId]
64
+ );
65
+ const WrapperElement = withWrapper ? "div" : Fragment;
66
+ const wrapperElementProps = withWrapper && {
67
+ className: cnMerge("flex flex-col", className),
68
+ "data-part": "item",
69
+ "data-scope": "form"
70
+ };
71
+ return /* @__PURE__ */ React2.createElement(StrictFormItemProvider, { value }, /* @__PURE__ */ React2.createElement(LaxFormItemProvider, { value }, /* @__PURE__ */ React2.createElement(WrapperElement, { ...wrapperElementProps }, children)));
72
+ }
73
+ function FormItemContext(props) {
74
+ const { children, render } = props;
75
+ const contextValues = useStrictFormItemContext();
76
+ if (typeof children === "function") {
77
+ return children(contextValues);
78
+ }
79
+ return render(contextValues);
80
+ }
81
+ function FormLabel(props) {
82
+ const { uniqueId } = useStrictFormItemContext();
83
+ const { children, className, ...restOfProps } = props;
84
+ return /* @__PURE__ */ React2.createElement("label", { "data-scope": "form", "data-part": "label", htmlFor: uniqueId, className, ...restOfProps }, children);
85
+ }
86
+ function FormInputGroup(props) {
87
+ const { children, className, ...restOfProps } = props;
88
+ const LeftItemSlot = getSlotElement(children, FormInputLeftItem);
89
+ const RightItemSlot = getSlotElement(children, FormInputRightItem);
90
+ const otherChildren = getOtherChildren(children, [FormInputLeftItem, FormInputRightItem]);
91
+ return /* @__PURE__ */ React2.createElement(
92
+ "div",
93
+ {
94
+ "data-scope": "form",
95
+ "data-part": "input-group",
96
+ className: cnMerge("flex items-center justify-between gap-2", className),
97
+ ...restOfProps
98
+ },
99
+ LeftItemSlot,
100
+ otherChildren,
101
+ RightItemSlot
102
+ );
103
+ }
104
+ function FormInputLeftItem(props) {
105
+ const { as: Element = "span", children, className, ...restOfProps } = props;
106
+ return /* @__PURE__ */ React2.createElement(
107
+ Element,
108
+ {
109
+ "data-scope": "form",
110
+ "data-part": "left-item",
111
+ className: cnMerge("inline-flex items-center justify-center", className),
112
+ ...restOfProps
113
+ },
114
+ children
115
+ );
116
+ }
117
+ FormInputLeftItem.slot = Symbol.for("leftItem");
118
+ function FormInputRightItem(props) {
119
+ const { as: Element = "span", children, className, ...restOfProps } = props;
120
+ return /* @__PURE__ */ React2.createElement(
121
+ Element,
122
+ {
123
+ "data-scope": "form",
124
+ "data-part": "right-item",
125
+ className: cnMerge("inline-flex items-center justify-center", className),
126
+ ...restOfProps
127
+ },
128
+ children
129
+ );
130
+ }
131
+ FormInputRightItem.slot = Symbol.for("rightItem");
132
+ var inputTypesWithoutFullWith = /* @__PURE__ */ new Set(["checkbox", "radio"]);
133
+ function FormInputPrimitive(props) {
134
+ const contextValues = useLaxFormItemContext();
135
+ const {
136
+ className,
137
+ classNames,
138
+ control,
139
+ formState,
140
+ id = contextValues?.uniqueId,
141
+ name = contextValues?.name,
142
+ type = "text",
143
+ withEyeIcon = true,
144
+ ...restOfProps
145
+ } = props;
146
+ const getFormState = control ? useFormState : () => formState;
147
+ const { errors } = getFormState({ control }) ?? {};
148
+ const [isPasswordVisible, toggleVisibility] = useToggle(false);
149
+ const shouldHaveEyeIcon = withEyeIcon && type === "password";
150
+ const WrapperElement = shouldHaveEyeIcon ? FormInputGroup : Fragment;
151
+ const wrapperElementProps = shouldHaveEyeIcon && {
152
+ className: cnMerge("w-full", classNames?.inputGroup, name && errors?.[name] && classNames?.error)
153
+ };
154
+ return /* @__PURE__ */ React2.createElement(WrapperElement, { ...wrapperElementProps }, /* @__PURE__ */ React2.createElement(
155
+ "input",
156
+ {
157
+ "data-scope": "form",
158
+ "data-part": "input",
159
+ id,
160
+ name,
161
+ type: type === "password" && isPasswordVisible ? "text" : type,
162
+ className: cnMerge(
163
+ !inputTypesWithoutFullWith.has(type) && "flex w-full",
164
+ `bg-transparent text-sm file:border-0 file:bg-transparent
165
+ placeholder:text-shadcn-muted-foreground focus-visible:outline-none
166
+ disabled:cursor-not-allowed disabled:opacity-50`,
167
+ className,
168
+ classNames?.input,
169
+ type !== "password" && name && errors?.[name] && classNames?.error
170
+ ),
171
+ ...restOfProps
172
+ }
173
+ ), shouldHaveEyeIcon && /* @__PURE__ */ React2.createElement(
174
+ FormInputRightItem,
175
+ {
176
+ as: "button",
177
+ type: "button",
178
+ onClick: toggleVisibility,
179
+ className: "size-5 shrink-0 lg:size-6"
180
+ },
181
+ isPasswordVisible ? /* @__PURE__ */ React2.createElement(EyeIconInvisible, { className: cnMerge("size-full", classNames?.eyeIcon) }) : /* @__PURE__ */ React2.createElement(EyeIconVisible, { className: cnMerge("size-full", classNames?.eyeIcon) })
182
+ ));
183
+ }
184
+ function FormInput(props) {
185
+ const { rules, ...restOfProps } = props;
186
+ const { name } = useStrictFormItemContext();
187
+ const { formState, register } = useFormFieldContext();
188
+ return /* @__PURE__ */ React2.createElement(
189
+ FormInputPrimitive,
190
+ {
191
+ name,
192
+ formState,
193
+ ...Boolean(name) && register(name, rules),
194
+ ...restOfProps
195
+ }
196
+ );
197
+ }
198
+ function FormTextAreaPrimitive(props) {
199
+ const contextValues = useLaxFormItemContext();
200
+ const {
201
+ className,
202
+ control,
203
+ errorClassName,
204
+ formState,
205
+ id = contextValues?.uniqueId,
206
+ name = contextValues?.name,
207
+ ...restOfProps
208
+ } = props;
209
+ const getFormState = control ? useFormState : () => formState;
210
+ const { errors } = getFormState({ control }) ?? {};
211
+ return /* @__PURE__ */ React2.createElement(
212
+ "textarea",
213
+ {
214
+ "data-scope": "form",
215
+ "data-part": "textarea",
216
+ id,
217
+ name,
218
+ className: cnMerge(
219
+ `w-full bg-transparent text-sm placeholder:text-shadcn-muted-foreground
220
+ focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50`,
221
+ className,
222
+ name && errors?.[name] && errorClassName
223
+ ),
224
+ ...restOfProps
225
+ }
226
+ );
227
+ }
228
+ function FormTextArea(props) {
229
+ const { rules, ...restOfProps } = props;
230
+ const { name } = useStrictFormItemContext();
231
+ const { formState, register } = useFormFieldContext();
232
+ return /* @__PURE__ */ React2.createElement(
233
+ FormTextAreaPrimitive,
234
+ {
235
+ name,
236
+ formState,
237
+ ...Boolean(name) && register(name, rules),
238
+ ...restOfProps
239
+ }
240
+ );
241
+ }
242
+ function FormController(props) {
243
+ const { control } = useFormFieldContext();
244
+ const { name } = useStrictFormItemContext();
245
+ return /* @__PURE__ */ React2.createElement(Controller, { name, control, ...props });
246
+ }
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) => {
252
+ const {
253
+ className,
254
+ classNames,
255
+ control,
256
+ errorField,
257
+ render,
258
+ type = "regular",
259
+ withAnimationOnInvalid = true
260
+ } = props;
261
+ const formState = useFormState({ control });
262
+ const wrapperRef = useRef(null);
263
+ const errorAnimationClass = classNames?.errorMessageAnimation ?? "animate-shake";
264
+ useEffect(() => {
265
+ if (!withAnimationOnInvalid) return;
266
+ const errorMessageElements = wrapperRef.current?.children;
267
+ if (!errorMessageElements) return;
268
+ for (const element of errorMessageElements) {
269
+ element.classList.add(errorAnimationClass);
270
+ }
271
+ }, [errorAnimationClass, withAnimationOnInvalid]);
272
+ useEffect(() => {
273
+ const errorMessageElements = wrapperRef.current?.children;
274
+ if (!errorMessageElements) return;
275
+ if (Object.keys(formState.errors).indexOf(errorField) === 0) {
276
+ errorMessageElements[0]?.scrollIntoView({
277
+ behavior: "smooth",
278
+ block: "center"
279
+ });
280
+ window.scrollBy({ behavior: "smooth", top: -100 });
281
+ }
282
+ }, [errorField, formState.errors]);
283
+ const message = type === "root" ? formState.errors.root?.[errorField]?.message : formState.errors[errorField]?.message;
284
+ if (!message) {
285
+ return null;
286
+ }
287
+ const errorMessageArray = toArray(message);
288
+ const [ErrorMessageList] = getElementList();
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
+ });
302
+ return /* @__PURE__ */ React2.createElement(
303
+ ErrorMessageList,
304
+ {
305
+ ref: wrapperRef,
306
+ each: errorMessageArray,
307
+ className: cnMerge("flex flex-col", classNames?.container),
308
+ render: (errorMessage, index) => {
309
+ return render({
310
+ props: getRenderProps({ index }),
311
+ state: getRenderState({ errorMessage, index })
312
+ });
313
+ }
314
+ }
315
+ );
316
+ };
317
+ function FormErrorMessage(props) {
318
+ const contextValues = useLaxFormItemContext();
319
+ const { className, errorField = contextValues?.name, type = "regular" } = props;
320
+ const { control } = useFormFieldContext();
321
+ return /* @__PURE__ */ React2.createElement(
322
+ FormErrorMessagePrimitive,
323
+ {
324
+ control,
325
+ errorField,
326
+ type,
327
+ render: ({ props: renderProps, state: { errorMessage } }) => /* @__PURE__ */ React2.createElement(
328
+ "p",
329
+ {
330
+ ...renderProps,
331
+ key: errorMessage,
332
+ className: cnMerge("text-[13px]", "data-[index=0]:mt-1", renderProps.className, className)
333
+ },
334
+ errorMessage
335
+ )
336
+ }
337
+ );
338
+ }
339
+
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 { FormController, FormDescription, FormErrorMessage, FormErrorMessagePrimitive, FormInput, FormInputGroup, FormInputLeftItem, FormInputPrimitive, FormInputRightItem, FormItem, FormItemContext, FormLabel, FormRoot, FormTextArea, FormTextAreaPrimitive, form_parts_exports, useStrictFormItemContext };
362
+ //# sourceMappingURL=chunk-PKN52DWQ.js.map
363
+ //# sourceMappingURL=chunk-PKN52DWQ.js.map