@craftzbay/ui 0.11.3 → 0.11.4

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 (163) hide show
  1. package/dist-lib/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist-lib/components/ui/Accordion.js +42 -67
  3. package/dist-lib/components/ui/Accordion.js.map +1 -1
  4. package/dist-lib/components/ui/Alert.js +71 -77
  5. package/dist-lib/components/ui/Alert.js.map +1 -1
  6. package/dist-lib/components/ui/Avatar.js +67 -92
  7. package/dist-lib/components/ui/Avatar.js.map +1 -1
  8. package/dist-lib/components/ui/Badge.js +119 -74
  9. package/dist-lib/components/ui/Badge.js.map +1 -1
  10. package/dist-lib/components/ui/Breadcrumbs.js +62 -50
  11. package/dist-lib/components/ui/Breadcrumbs.js.map +1 -1
  12. package/dist-lib/components/ui/Button.js +129 -131
  13. package/dist-lib/components/ui/Button.js.map +1 -1
  14. package/dist-lib/components/ui/Calendar.d.ts +1 -1
  15. package/dist-lib/components/ui/Calendar.js +99 -136
  16. package/dist-lib/components/ui/Calendar.js.map +1 -1
  17. package/dist-lib/components/ui/Card.js +88 -94
  18. package/dist-lib/components/ui/Card.js.map +1 -1
  19. package/dist-lib/components/ui/Carousel.js +125 -170
  20. package/dist-lib/components/ui/Carousel.js.map +1 -1
  21. package/dist-lib/components/ui/Chart.d.ts +3 -3
  22. package/dist-lib/components/ui/Chart.js +435 -464
  23. package/dist-lib/components/ui/Chart.js.map +1 -1
  24. package/dist-lib/components/ui/Checkbox.js +60 -69
  25. package/dist-lib/components/ui/Checkbox.js.map +1 -1
  26. package/dist-lib/components/ui/Combobox.js +179 -192
  27. package/dist-lib/components/ui/Combobox.js.map +1 -1
  28. package/dist-lib/components/ui/CommandPalette.d.ts +2 -2
  29. package/dist-lib/components/ui/CommandPalette.js +106 -167
  30. package/dist-lib/components/ui/CommandPalette.js.map +1 -1
  31. package/dist-lib/components/ui/ContextMenu.d.ts +1 -1
  32. package/dist-lib/components/ui/ContextMenu.js +89 -154
  33. package/dist-lib/components/ui/ContextMenu.js.map +1 -1
  34. package/dist-lib/components/ui/DataGrid.d.ts +1 -1
  35. package/dist-lib/components/ui/DataGrid.js +99 -96
  36. package/dist-lib/components/ui/DataGrid.js.map +1 -1
  37. package/dist-lib/components/ui/DatePicker.js +151 -188
  38. package/dist-lib/components/ui/DatePicker.js.map +1 -1
  39. package/dist-lib/components/ui/DesignSystemProvider.d.ts +1 -1
  40. package/dist-lib/components/ui/DesignSystemProvider.js +120 -130
  41. package/dist-lib/components/ui/DesignSystemProvider.js.map +1 -1
  42. package/dist-lib/components/ui/Dialog.d.ts +3 -3
  43. package/dist-lib/components/ui/Dialog.js +108 -156
  44. package/dist-lib/components/ui/Dialog.js.map +1 -1
  45. package/dist-lib/components/ui/Drawer.d.ts +3 -3
  46. package/dist-lib/components/ui/Drawer.js +90 -124
  47. package/dist-lib/components/ui/Drawer.js.map +1 -1
  48. package/dist-lib/components/ui/DropdownMenu.d.ts +1 -1
  49. package/dist-lib/components/ui/DropdownMenu.js +92 -158
  50. package/dist-lib/components/ui/DropdownMenu.js.map +1 -1
  51. package/dist-lib/components/ui/EmptyState.js +31 -44
  52. package/dist-lib/components/ui/EmptyState.js.map +1 -1
  53. package/dist-lib/components/ui/ErrorState.js +57 -67
  54. package/dist-lib/components/ui/ErrorState.js.map +1 -1
  55. package/dist-lib/components/ui/FileUpload.js +113 -107
  56. package/dist-lib/components/ui/FileUpload.js.map +1 -1
  57. package/dist-lib/components/ui/Form.d.ts +6 -4
  58. package/dist-lib/components/ui/Form.js +117 -122
  59. package/dist-lib/components/ui/Form.js.map +1 -1
  60. package/dist-lib/components/ui/Icon.d.ts +1 -1
  61. package/dist-lib/components/ui/Icon.js +30 -29
  62. package/dist-lib/components/ui/Icon.js.map +1 -1
  63. package/dist-lib/components/ui/IconButton.js +61 -63
  64. package/dist-lib/components/ui/IconButton.js.map +1 -1
  65. package/dist-lib/components/ui/Input.js +133 -156
  66. package/dist-lib/components/ui/Input.js.map +1 -1
  67. package/dist-lib/components/ui/Kbd.js +14 -21
  68. package/dist-lib/components/ui/Kbd.js.map +1 -1
  69. package/dist-lib/components/ui/MultiSelect.js +176 -208
  70. package/dist-lib/components/ui/MultiSelect.js.map +1 -1
  71. package/dist-lib/components/ui/Pagination.js +152 -149
  72. package/dist-lib/components/ui/Pagination.js.map +1 -1
  73. package/dist-lib/components/ui/Popover.js +18 -33
  74. package/dist-lib/components/ui/Popover.js.map +1 -1
  75. package/dist-lib/components/ui/Progress.js +77 -99
  76. package/dist-lib/components/ui/Progress.js.map +1 -1
  77. package/dist-lib/components/ui/RadioGroup.js +51 -80
  78. package/dist-lib/components/ui/RadioGroup.js.map +1 -1
  79. package/dist-lib/components/ui/RelativeTime.js +22 -29
  80. package/dist-lib/components/ui/RelativeTime.js.map +1 -1
  81. package/dist-lib/components/ui/ScrollArea.js +39 -58
  82. package/dist-lib/components/ui/ScrollArea.js.map +1 -1
  83. package/dist-lib/components/ui/Select.js +108 -131
  84. package/dist-lib/components/ui/Select.js.map +1 -1
  85. package/dist-lib/components/ui/Separator.js +18 -24
  86. package/dist-lib/components/ui/Separator.js.map +1 -1
  87. package/dist-lib/components/ui/Sheet.d.ts +2 -2
  88. package/dist-lib/components/ui/Sheet.js +77 -129
  89. package/dist-lib/components/ui/Sheet.js.map +1 -1
  90. package/dist-lib/components/ui/Sidebar.d.ts +1 -1
  91. package/dist-lib/components/ui/Sidebar.js +168 -207
  92. package/dist-lib/components/ui/Sidebar.js.map +1 -1
  93. package/dist-lib/components/ui/Skeleton.js +17 -27
  94. package/dist-lib/components/ui/Skeleton.js.map +1 -1
  95. package/dist-lib/components/ui/Slider.js +45 -62
  96. package/dist-lib/components/ui/Slider.js.map +1 -1
  97. package/dist-lib/components/ui/Snackbar.js +75 -55
  98. package/dist-lib/components/ui/Snackbar.js.map +1 -1
  99. package/dist-lib/components/ui/Spinner.js +45 -52
  100. package/dist-lib/components/ui/Spinner.js.map +1 -1
  101. package/dist-lib/components/ui/Stepper.js +56 -108
  102. package/dist-lib/components/ui/Stepper.js.map +1 -1
  103. package/dist-lib/components/ui/Switch.js +46 -79
  104. package/dist-lib/components/ui/Switch.js.map +1 -1
  105. package/dist-lib/components/ui/Table.js +108 -169
  106. package/dist-lib/components/ui/Table.js.map +1 -1
  107. package/dist-lib/components/ui/Tabs.js +57 -88
  108. package/dist-lib/components/ui/Tabs.js.map +1 -1
  109. package/dist-lib/components/ui/TagInput.js +76 -109
  110. package/dist-lib/components/ui/TagInput.js.map +1 -1
  111. package/dist-lib/components/ui/Textarea.js +74 -86
  112. package/dist-lib/components/ui/Textarea.js.map +1 -1
  113. package/dist-lib/components/ui/Timeline.d.ts +3 -3
  114. package/dist-lib/components/ui/Timeline.js +61 -49
  115. package/dist-lib/components/ui/Timeline.js.map +1 -1
  116. package/dist-lib/components/ui/Toast.d.ts +1 -1
  117. package/dist-lib/components/ui/Toast.js +136 -150
  118. package/dist-lib/components/ui/Toast.js.map +1 -1
  119. package/dist-lib/components/ui/Tooltip.d.ts +2 -2
  120. package/dist-lib/components/ui/Tooltip.js +35 -56
  121. package/dist-lib/components/ui/Tooltip.js.map +1 -1
  122. package/dist-lib/components/ui/TopNav.js +46 -66
  123. package/dist-lib/components/ui/TopNav.js.map +1 -1
  124. package/dist-lib/components/ui/Tree.js +134 -168
  125. package/dist-lib/components/ui/Tree.js.map +1 -1
  126. package/dist-lib/hooks/use-debounce.js +27 -33
  127. package/dist-lib/hooks/use-debounce.js.map +1 -1
  128. package/dist-lib/hooks/use-delayed-loading.js +19 -18
  129. package/dist-lib/hooks/use-delayed-loading.js.map +1 -1
  130. package/dist-lib/hooks/use-field-ids.js +14 -16
  131. package/dist-lib/hooks/use-field-ids.js.map +1 -1
  132. package/dist-lib/hooks/use-media-query.js +15 -19
  133. package/dist-lib/hooks/use-media-query.js.map +1 -1
  134. package/dist-lib/hooks/use-modifier-key.js +20 -15
  135. package/dist-lib/hooks/use-modifier-key.js.map +1 -1
  136. package/dist-lib/hooks/use-strings.js +10 -10
  137. package/dist-lib/hooks/use-strings.js.map +1 -1
  138. package/dist-lib/hooks/use-toast.js +73 -62
  139. package/dist-lib/hooks/use-toast.js.map +1 -1
  140. package/dist-lib/icon.js +2 -6
  141. package/dist-lib/icons/index.js +166 -163
  142. package/dist-lib/icons/index.js.map +1 -1
  143. package/dist-lib/illustrations/index.d.ts +7 -7
  144. package/dist-lib/illustrations/index.js +255 -106
  145. package/dist-lib/illustrations/index.js.map +1 -1
  146. package/dist-lib/index.js +69 -291
  147. package/dist-lib/lib/cva.js +2 -0
  148. package/dist-lib/lib/format.js +71 -87
  149. package/dist-lib/lib/format.js.map +1 -1
  150. package/dist-lib/lib/return-focus.js +11 -11
  151. package/dist-lib/lib/return-focus.js.map +1 -1
  152. package/dist-lib/lib/strings.js +167 -135
  153. package/dist-lib/lib/strings.js.map +1 -1
  154. package/dist-lib/lib/strings.mn.js +150 -113
  155. package/dist-lib/lib/strings.mn.js.map +1 -1
  156. package/dist-lib/lib/utils.js +9 -9
  157. package/dist-lib/lib/utils.js.map +1 -1
  158. package/dist-lib/styles.css +3 -1
  159. package/package.json +50 -50
  160. package/dist-lib/__tests__/helpers/color.d.ts +0 -9
  161. package/dist-lib/__tests__/helpers/theme.d.ts +0 -18
  162. package/dist-lib/icon.js.map +0 -1
  163. package/dist-lib/index.js.map +0 -1
@@ -1,111 +1,117 @@
1
1
  "use client";
2
- import { jsxs as p, jsx as n } from "react/jsx-runtime";
3
- import { forwardRef as T, useRef as F, useId as B, useState as D, useCallback as U } from "react";
4
- import { Upload as C, File as E, X } from "../../icons/index.js";
5
- import { cn as z } from "../../lib/utils.js";
6
- import { useStrings as _ } from "../../hooks/use-strings.js";
7
- import { formatString as h } from "../../lib/strings.js";
8
- function q(s, t) {
9
- return s < 1024 ? h(t.bytes, { n: s }) : s < 1024 * 1024 ? h(t.kilobytes, { n: (s / 1024).toFixed(1) }) : h(t.megabytes, { n: (s / 1024 / 1024).toFixed(1) });
2
+ import { cn as e } from "../../lib/utils.js";
3
+ import { formatString as t } from "../../lib/strings.js";
4
+ import { useStrings as n } from "../../hooks/use-strings.js";
5
+ import { File as r, Upload as i, X as a } from "../../icons/index.js";
6
+ import { forwardRef as o, useCallback as s, useId as c, useRef as l, useState as u } from "react";
7
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
8
+ //#region src/components/ui/FileUpload.tsx
9
+ function p(e, n) {
10
+ return e < 1024 ? t(n.bytes, { n: e }) : e < 1048576 ? t(n.kilobytes, { n: (e / 1024).toFixed(1) }) : t(n.megabytes, { n: (e / 1024 / 1024).toFixed(1) });
10
11
  }
11
- function G(s, t) {
12
- if (!t) return !0;
13
- const a = t.split(",").map((r) => r.trim().toLowerCase()).filter(Boolean);
14
- if (!a.length) return !0;
15
- const d = s.name.toLowerCase(), l = s.type.toLowerCase();
16
- return a.some((r) => r.startsWith(".") ? d.endsWith(r) : r.endsWith("/*") ? l.startsWith(r.slice(0, -1)) : l === r);
12
+ function m(e, t) {
13
+ if (!t) return !0;
14
+ let n = t.split(",").map((e) => e.trim().toLowerCase()).filter(Boolean);
15
+ if (!n.length) return !0;
16
+ let r = e.name.toLowerCase(), i = e.type.toLowerCase();
17
+ return n.some((e) => e.startsWith(".") ? r.endsWith(e) : e.endsWith("/*") ? i.startsWith(e.slice(0, -1)) : i === e);
17
18
  }
18
- const H = T(function({ accept: t, multiple: a, maxSize: d, value: l, onChange: r, onReject: i, hint: y, disabled: g, className: L }, W) {
19
- const b = _(), $ = F(null), w = B(), [I, A] = D([]), [M, x] = D(!1), f = F(0), c = l ?? I, v = U(
20
- (e) => {
21
- l === void 0 && A(e), r == null || r(e);
22
- },
23
- [r, l]
24
- ), k = U(
25
- (e) => {
26
- const o = [], u = [], N = [];
27
- for (const m of Array.from(e))
28
- G(m, t) ? d && m.size > d ? u.push(m) : o.push(m) : N.push(m);
29
- N.length && (i == null || i(N, "type")), u.length && (i == null || i(u, "size")), o.length && v(a ? [...c, ...o] : o.slice(0, 1));
30
- },
31
- [t, c, d, a, i, v]
32
- ), O = (e) => v(c.filter((o, u) => u !== e)), S = (e) => {
33
- e.preventDefault(), f.current = 0, x(!1), !g && k(e.dataTransfer.files);
34
- };
35
- return /* @__PURE__ */ p("div", { ref: W, className: z("flex flex-col gap-3", L), children: [
36
- /* @__PURE__ */ p(
37
- "label",
38
- {
39
- htmlFor: w,
40
- onDragEnter: () => {
41
- f.current += 1, g || x(!0);
42
- },
43
- onDragOver: (e) => e.preventDefault(),
44
- onDragLeave: () => {
45
- f.current = Math.max(0, f.current - 1), f.current === 0 && x(!1);
46
- },
47
- onDrop: S,
48
- className: z(
49
- "group relative flex cursor-pointer flex-col items-center justify-center gap-2",
50
- "border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8",
51
- "text-center transition-colors",
52
- "hover:border-border-strong hover:bg-background-muted",
53
- "focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2",
54
- M && "border-accent bg-accent-soft",
55
- g && "pointer-events-none opacity-50"
56
- ),
57
- children: [
58
- /* @__PURE__ */ n(C, { className: "text-foreground-muted size-5", "aria-hidden": !0 }),
59
- /* @__PURE__ */ p("div", { className: "space-y-1", children: [
60
- /* @__PURE__ */ n("p", { className: "text-sm font-medium", children: b.fileUpload.drop }),
61
- y && /* @__PURE__ */ n("p", { className: "text-foreground-muted text-xs", children: y })
62
- ] }),
63
- /* @__PURE__ */ n(
64
- "input",
65
- {
66
- ref: $,
67
- id: w,
68
- type: "file",
69
- accept: t,
70
- multiple: a,
71
- disabled: g,
72
- className: "sr-only",
73
- onChange: (e) => {
74
- e.target.files && k(e.target.files), e.target.value = "";
75
- }
76
- }
77
- )
78
- ]
79
- }
80
- ),
81
- c.length > 0 && /* @__PURE__ */ n("ul", { className: "flex flex-col gap-2", children: c.map((e, o) => /* @__PURE__ */ p(
82
- "li",
83
- {
84
- className: "border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2",
85
- children: [
86
- /* @__PURE__ */ n(E, { className: "text-foreground-muted size-4 shrink-0", "aria-hidden": !0 }),
87
- /* @__PURE__ */ p("div", { className: "min-w-0 flex-1", children: [
88
- /* @__PURE__ */ n("p", { className: "truncate text-sm", title: e.name, children: e.name }),
89
- /* @__PURE__ */ n("p", { className: "text-foreground-muted text-xs", children: q(e.size, b.fileUpload) })
90
- ] }),
91
- /* @__PURE__ */ n(
92
- "button",
93
- {
94
- type: "button",
95
- onClick: () => O(o),
96
- className: "text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
97
- "aria-label": h(b.fileUpload.remove, { name: e.name }),
98
- children: /* @__PURE__ */ n(X, { className: "size-4", "aria-hidden": !0 })
99
- }
100
- )
101
- ]
102
- },
103
- `${e.name}-${e.size}-${e.lastModified}-${o}`
104
- )) })
105
- ] });
19
+ var h = o(function({ accept: o, multiple: h, maxSize: g, value: _, onChange: v, onReject: y, hint: b, disabled: x, className: S }, C) {
20
+ let w = n(), T = l(null), E = c(), [D, O] = u([]), [k, A] = u(!1), j = l(0), M = _ ?? D, N = s((e) => {
21
+ _ === void 0 && O(e), v?.(e);
22
+ }, [v, _]), P = s((e) => {
23
+ let t = [], n = [], r = [];
24
+ for (let i of Array.from(e)) m(i, o) ? g && i.size > g ? n.push(i) : t.push(i) : r.push(i);
25
+ r.length && y?.(r, "type"), n.length && y?.(n, "size"), t.length && N(h ? [...M, ...t] : t.slice(0, 1));
26
+ }, [
27
+ o,
28
+ M,
29
+ g,
30
+ h,
31
+ y,
32
+ N
33
+ ]), F = (e) => N(M.filter((t, n) => n !== e));
34
+ return /* @__PURE__ */ f("div", {
35
+ ref: C,
36
+ className: e("flex flex-col gap-3", S),
37
+ children: [/* @__PURE__ */ f("label", {
38
+ htmlFor: E,
39
+ onDragEnter: () => {
40
+ j.current += 1, x || A(!0);
41
+ },
42
+ onDragOver: (e) => e.preventDefault(),
43
+ onDragLeave: () => {
44
+ j.current = Math.max(0, j.current - 1), j.current === 0 && A(!1);
45
+ },
46
+ onDrop: (e) => {
47
+ e.preventDefault(), j.current = 0, A(!1), !x && P(e.dataTransfer.files);
48
+ },
49
+ className: e("group relative flex cursor-pointer flex-col items-center justify-center gap-2", "border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8", "text-center transition-colors", "hover:border-border-strong hover:bg-background-muted", "focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2", k && "border-accent bg-accent-soft", x && "pointer-events-none opacity-50"),
50
+ children: [
51
+ /* @__PURE__ */ d(i, {
52
+ className: "text-foreground-muted size-5",
53
+ "aria-hidden": !0
54
+ }),
55
+ /* @__PURE__ */ f("div", {
56
+ className: "space-y-1",
57
+ children: [/* @__PURE__ */ d("p", {
58
+ className: "text-sm font-medium",
59
+ children: w.fileUpload.drop
60
+ }), b && /* @__PURE__ */ d("p", {
61
+ className: "text-foreground-muted text-xs",
62
+ children: b
63
+ })]
64
+ }),
65
+ /* @__PURE__ */ d("input", {
66
+ ref: T,
67
+ id: E,
68
+ type: "file",
69
+ accept: o,
70
+ multiple: h,
71
+ disabled: x,
72
+ className: "sr-only",
73
+ onChange: (e) => {
74
+ e.target.files && P(e.target.files), e.target.value = "";
75
+ }
76
+ })
77
+ ]
78
+ }), M.length > 0 && /* @__PURE__ */ d("ul", {
79
+ className: "flex flex-col gap-2",
80
+ children: M.map((e, n) => /* @__PURE__ */ f("li", {
81
+ className: "border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2",
82
+ children: [
83
+ /* @__PURE__ */ d(r, {
84
+ className: "text-foreground-muted size-4 shrink-0",
85
+ "aria-hidden": !0
86
+ }),
87
+ /* @__PURE__ */ f("div", {
88
+ className: "min-w-0 flex-1",
89
+ children: [/* @__PURE__ */ d("p", {
90
+ className: "truncate text-sm",
91
+ title: e.name,
92
+ children: e.name
93
+ }), /* @__PURE__ */ d("p", {
94
+ className: "text-foreground-muted text-xs",
95
+ children: p(e.size, w.fileUpload)
96
+ })]
97
+ }),
98
+ /* @__PURE__ */ d("button", {
99
+ type: "button",
100
+ onClick: () => F(n),
101
+ className: "text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-none focus-visible:ring-2 focus-visible:ring-offset-2",
102
+ "aria-label": t(w.fileUpload.remove, { name: e.name }),
103
+ children: /* @__PURE__ */ d(a, {
104
+ className: "size-4",
105
+ "aria-hidden": !0
106
+ })
107
+ })
108
+ ]
109
+ }, `${e.name}-${e.size}-${e.lastModified}-${n}`))
110
+ })]
111
+ });
106
112
  });
107
- H.displayName = "FileUpload";
108
- export {
109
- H as FileUpload
110
- };
111
- //# sourceMappingURL=FileUpload.js.map
113
+ h.displayName = "FileUpload";
114
+ //#endregion
115
+ export { h as FileUpload };
116
+
117
+ //# sourceMappingURL=FileUpload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FileUpload.js","sources":["../../../src/components/ui/FileUpload.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useId,\n useRef,\n useState,\n type DragEvent as ReactDragEvent,\n type ReactNode,\n} from 'react';\nimport { File as FileIcon, Upload, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString, type UiStrings } from '@/lib/strings';\n\nexport type FileRejectReason = 'size' | 'type';\n\nexport interface FileUploadProps {\n /** Accepted file types, e.g. `image/*` or `.pdf,.docx`. */\n accept?: string;\n /** Allow multiple files. */\n multiple?: boolean;\n /** Max file size in bytes. Files larger than this are rejected. */\n maxSize?: number;\n /** Controlled file list. */\n value?: File[];\n /** Called when files are added or removed. */\n onChange?: (files: File[]) => void;\n /** Called with the files that were dropped because of `maxSize` or `accept`. */\n onReject?: (files: File[], reason: FileRejectReason) => void;\n /** Helper text inside the drop zone. */\n hint?: ReactNode;\n /** Disable the picker entirely. */\n disabled?: boolean;\n className?: string;\n}\n\nfunction formatSize(bytes: number, s: UiStrings['fileUpload']) {\n if (bytes < 1024) return formatString(s.bytes, { n: bytes });\n if (bytes < 1024 * 1024) return formatString(s.kilobytes, { n: (bytes / 1024).toFixed(1) });\n return formatString(s.megabytes, { n: (bytes / 1024 / 1024).toFixed(1) });\n}\n\n/** Mirror the browser's `accept` matching for dropped files (which skip the picker filter). */\nfunction matchesAccept(file: File, accept?: string): boolean {\n if (!accept) return true;\n const rules = accept\n .split(',')\n .map((r) => r.trim().toLowerCase())\n .filter(Boolean);\n if (!rules.length) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return rules.some((rule) => {\n if (rule.startsWith('.')) return name.endsWith(rule);\n if (rule.endsWith('/*')) return type.startsWith(rule.slice(0, -1));\n return type === rule;\n });\n}\n\n/**\n * Drag-and-drop file picker with an inline file list. Uncontrolled by default;\n * pass `value` + `onChange` to control externally.\n */\nexport const FileUpload = forwardRef<HTMLDivElement, FileUploadProps>(function FileUpload(\n { accept, multiple, maxSize, value, onChange, onReject, hint, disabled, className },\n ref,\n) {\n const strings = useStrings();\n const inputRef = useRef<HTMLInputElement>(null);\n const inputId = useId();\n const [internal, setInternal] = useState<File[]>([]);\n const [over, setOver] = useState(false);\n // dragenter/dragleave fire for every child element; count nesting depth so\n // the highlight does not flicker while the pointer crosses the label's children.\n const dragDepth = useRef(0);\n const files = value ?? internal;\n\n const update = useCallback(\n (next: File[]) => {\n if (value === undefined) setInternal(next);\n onChange?.(next);\n },\n [onChange, value],\n );\n\n const addFiles = useCallback(\n (incoming: FileList | File[]) => {\n const accepted: File[] = [];\n const tooLarge: File[] = [];\n const wrongType: File[] = [];\n for (const f of Array.from(incoming)) {\n if (!matchesAccept(f, accept)) wrongType.push(f);\n else if (maxSize && f.size > maxSize) tooLarge.push(f);\n else accepted.push(f);\n }\n if (wrongType.length) onReject?.(wrongType, 'type');\n if (tooLarge.length) onReject?.(tooLarge, 'size');\n if (!accepted.length) return;\n update(multiple ? [...files, ...accepted] : accepted.slice(0, 1));\n },\n [accept, files, maxSize, multiple, onReject, update],\n );\n\n const remove = (idx: number) => update(files.filter((_, i) => i !== idx));\n\n const onDrop = (e: ReactDragEvent<HTMLLabelElement>) => {\n e.preventDefault();\n dragDepth.current = 0;\n setOver(false);\n if (disabled) return;\n addFiles(e.dataTransfer.files);\n };\n\n return (\n <div ref={ref} className={cn('flex flex-col gap-3', className)}>\n <label\n htmlFor={inputId}\n onDragEnter={() => {\n dragDepth.current += 1;\n if (!disabled) setOver(true);\n }}\n onDragOver={(e) => e.preventDefault()}\n onDragLeave={() => {\n dragDepth.current = Math.max(0, dragDepth.current - 1);\n if (dragDepth.current === 0) setOver(false);\n }}\n onDrop={onDrop}\n className={cn(\n 'group relative flex cursor-pointer flex-col items-center justify-center gap-2',\n 'border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8',\n 'text-center transition-colors',\n 'hover:border-border-strong hover:bg-background-muted',\n 'focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n over && 'border-accent bg-accent-soft',\n disabled && 'pointer-events-none opacity-50',\n )}\n >\n <Upload className=\"text-foreground-muted size-5\" aria-hidden />\n <div className=\"space-y-1\">\n <p className=\"text-sm font-medium\">{strings.fileUpload.drop}</p>\n {hint && <p className=\"text-foreground-muted text-xs\">{hint}</p>}\n </div>\n <input\n ref={inputRef}\n id={inputId}\n type=\"file\"\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n className=\"sr-only\"\n onChange={(e) => {\n if (e.target.files) addFiles(e.target.files);\n // Allow re-selecting the same file after removing it.\n e.target.value = '';\n }}\n />\n </label>\n\n {files.length > 0 && (\n <ul className=\"flex flex-col gap-2\">\n {files.map((file, idx) => (\n <li\n key={`${file.name}-${file.size}-${file.lastModified}-${idx}`}\n className=\"border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2\"\n >\n <FileIcon className=\"text-foreground-muted size-4 shrink-0\" aria-hidden />\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm\" title={file.name}>\n {file.name}\n </p>\n <p className=\"text-foreground-muted text-xs\">\n {formatSize(file.size, strings.fileUpload)}\n </p>\n </div>\n <button\n type=\"button\"\n onClick={() => remove(idx)}\n className=\"text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-none focus-visible:ring-2 focus-visible:ring-offset-2\"\n aria-label={formatString(strings.fileUpload.remove, { name: file.name })}\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n});\nFileUpload.displayName = 'FileUpload';\n"],"names":["formatSize","bytes","s","formatString","matchesAccept","file","accept","rules","name","type","rule","FileUpload","forwardRef","multiple","maxSize","value","onChange","onReject","hint","disabled","className","ref","strings","useStrings","inputRef","useRef","inputId","useId","internal","setInternal","useState","over","setOver","dragDepth","files","update","useCallback","next","addFiles","incoming","accepted","tooLarge","wrongType","f","remove","idx","_","i","onDrop","cn","jsxs","jsx","Upload","FileIcon"],"mappings":";;;;;;;AAsCA,SAASA,EAAWC,GAAeC,GAA4B;AAC7D,SAAID,IAAQ,OAAaE,EAAaD,EAAE,OAAO,EAAE,GAAGD,GAAO,IACvDA,IAAQ,OAAO,OAAaE,EAAaD,EAAE,WAAW,EAAE,IAAID,IAAQ,MAAM,QAAQ,CAAC,GAAG,IACnFE,EAAaD,EAAE,WAAW,EAAE,IAAID,IAAQ,OAAO,MAAM,QAAQ,CAAC,EAAA,CAAG;AAC1E;AAGA,SAASG,EAAcC,GAAYC,GAA0B;AAC3D,MAAI,CAACA,EAAQ,QAAO;AACpB,QAAMC,IAAQD,EACX,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,EAAE,OAAO,YAAA,CAAa,EACjC,OAAO,OAAO;AACjB,MAAI,CAACC,EAAM,OAAQ,QAAO;AAC1B,QAAMC,IAAOH,EAAK,KAAK,YAAA,GACjBI,IAAOJ,EAAK,KAAK,YAAA;AACvB,SAAOE,EAAM,KA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AA,CAqB7D,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ,CAAC;AACDlC,EAAW,cAAc;"}
1
+ {"version":3,"file":"FileUpload.js","names":[],"sources":["../../../src/components/ui/FileUpload.tsx"],"sourcesContent":["'use client';\n\nimport {\n forwardRef,\n useCallback,\n useId,\n useRef,\n useState,\n type DragEvent as ReactDragEvent,\n type ReactNode,\n} from 'react';\nimport { File as FileIcon, Upload, X } from '@/icons';\nimport { cn } from '@/lib/utils';\nimport { useStrings } from '@/hooks/use-strings';\nimport { formatString, type UiStrings } from '@/lib/strings';\n\nexport type FileRejectReason = 'size' | 'type';\n\nexport interface FileUploadProps {\n /** Accepted file types, e.g. `image/*` or `.pdf,.docx`. */\n accept?: string;\n /** Allow multiple files. */\n multiple?: boolean;\n /** Max file size in bytes. Files larger than this are rejected. */\n maxSize?: number;\n /** Controlled file list. */\n value?: File[];\n /** Called when files are added or removed. */\n onChange?: (files: File[]) => void;\n /** Called with the files that were dropped because of `maxSize` or `accept`. */\n onReject?: (files: File[], reason: FileRejectReason) => void;\n /** Helper text inside the drop zone. */\n hint?: ReactNode;\n /** Disable the picker entirely. */\n disabled?: boolean;\n className?: string;\n}\n\nfunction formatSize(bytes: number, s: UiStrings['fileUpload']) {\n if (bytes < 1024) return formatString(s.bytes, { n: bytes });\n if (bytes < 1024 * 1024) return formatString(s.kilobytes, { n: (bytes / 1024).toFixed(1) });\n return formatString(s.megabytes, { n: (bytes / 1024 / 1024).toFixed(1) });\n}\n\n/** Mirror the browser's `accept` matching for dropped files (which skip the picker filter). */\nfunction matchesAccept(file: File, accept?: string): boolean {\n if (!accept) return true;\n const rules = accept\n .split(',')\n .map((r) => r.trim().toLowerCase())\n .filter(Boolean);\n if (!rules.length) return true;\n const name = file.name.toLowerCase();\n const type = file.type.toLowerCase();\n return rules.some((rule) => {\n if (rule.startsWith('.')) return name.endsWith(rule);\n if (rule.endsWith('/*')) return type.startsWith(rule.slice(0, -1));\n return type === rule;\n });\n}\n\n/**\n * Drag-and-drop file picker with an inline file list. Uncontrolled by default;\n * pass `value` + `onChange` to control externally.\n */\nexport const FileUpload = forwardRef<HTMLDivElement, FileUploadProps>(function FileUpload(\n { accept, multiple, maxSize, value, onChange, onReject, hint, disabled, className },\n ref,\n) {\n const strings = useStrings();\n const inputRef = useRef<HTMLInputElement>(null);\n const inputId = useId();\n const [internal, setInternal] = useState<File[]>([]);\n const [over, setOver] = useState(false);\n // dragenter/dragleave fire for every child element; count nesting depth so\n // the highlight does not flicker while the pointer crosses the label's children.\n const dragDepth = useRef(0);\n const files = value ?? internal;\n\n const update = useCallback(\n (next: File[]) => {\n if (value === undefined) setInternal(next);\n onChange?.(next);\n },\n [onChange, value],\n );\n\n const addFiles = useCallback(\n (incoming: FileList | File[]) => {\n const accepted: File[] = [];\n const tooLarge: File[] = [];\n const wrongType: File[] = [];\n for (const f of Array.from(incoming)) {\n if (!matchesAccept(f, accept)) wrongType.push(f);\n else if (maxSize && f.size > maxSize) tooLarge.push(f);\n else accepted.push(f);\n }\n if (wrongType.length) onReject?.(wrongType, 'type');\n if (tooLarge.length) onReject?.(tooLarge, 'size');\n if (!accepted.length) return;\n update(multiple ? [...files, ...accepted] : accepted.slice(0, 1));\n },\n [accept, files, maxSize, multiple, onReject, update],\n );\n\n const remove = (idx: number) => update(files.filter((_, i) => i !== idx));\n\n const onDrop = (e: ReactDragEvent<HTMLLabelElement>) => {\n e.preventDefault();\n dragDepth.current = 0;\n setOver(false);\n if (disabled) return;\n addFiles(e.dataTransfer.files);\n };\n\n return (\n <div ref={ref} className={cn('flex flex-col gap-3', className)}>\n <label\n htmlFor={inputId}\n onDragEnter={() => {\n dragDepth.current += 1;\n if (!disabled) setOver(true);\n }}\n onDragOver={(e) => e.preventDefault()}\n onDragLeave={() => {\n dragDepth.current = Math.max(0, dragDepth.current - 1);\n if (dragDepth.current === 0) setOver(false);\n }}\n onDrop={onDrop}\n className={cn(\n 'group relative flex cursor-pointer flex-col items-center justify-center gap-2',\n 'border-border-input bg-background-subtle rounded-md border border-dashed px-6 py-8',\n 'text-center transition-colors',\n 'hover:border-border-strong hover:bg-background-muted',\n 'focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',\n over && 'border-accent bg-accent-soft',\n disabled && 'pointer-events-none opacity-50',\n )}\n >\n <Upload className=\"text-foreground-muted size-5\" aria-hidden />\n <div className=\"space-y-1\">\n <p className=\"text-sm font-medium\">{strings.fileUpload.drop}</p>\n {hint && <p className=\"text-foreground-muted text-xs\">{hint}</p>}\n </div>\n <input\n ref={inputRef}\n id={inputId}\n type=\"file\"\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n className=\"sr-only\"\n onChange={(e) => {\n if (e.target.files) addFiles(e.target.files);\n // Allow re-selecting the same file after removing it.\n e.target.value = '';\n }}\n />\n </label>\n\n {files.length > 0 && (\n <ul className=\"flex flex-col gap-2\">\n {files.map((file, idx) => (\n <li\n key={`${file.name}-${file.size}-${file.lastModified}-${idx}`}\n className=\"border-border bg-card flex items-center gap-3 rounded-md border px-3 py-2\"\n >\n <FileIcon className=\"text-foreground-muted size-4 shrink-0\" aria-hidden />\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm\" title={file.name}>\n {file.name}\n </p>\n <p className=\"text-foreground-muted text-xs\">\n {formatSize(file.size, strings.fileUpload)}\n </p>\n </div>\n <button\n type=\"button\"\n onClick={() => remove(idx)}\n className=\"text-foreground-muted hover:bg-background-muted hover:text-foreground focus-visible:ring-ring focus-visible:ring-offset-background rounded-sm p-1 outline-none focus-visible:ring-2 focus-visible:ring-offset-2\"\n aria-label={formatString(strings.fileUpload.remove, { name: file.name })}\n >\n <X className=\"size-4\" aria-hidden />\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n});\nFileUpload.displayName = 'FileUpload';\n"],"mappings":";;;;;;;;AAsCA,SAAS,EAAW,GAAe,GAA4B;CAG7D,OAFI,IAAQ,OAAa,EAAa,EAAE,OAAO,EAAE,GAAG,E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ACG;KACE;KACA;KACV,WAAU;KACV,WAAW,MAAM;MAGf,AAFI,EAAE,OAAO,SAAO,EAAS,EAAE,OAAO,KAAK,GAE3C,EAAE,OAAO,QAAQ;KACnB;IACD,CAAA;GACI;EAEN,CAAA,GAAA,EAAM,SAAS,KACd,kBAAC,MAAD;GAAI,WAAU;GACX,UAAA,EAAM,KAAK,GAAM,MAChB,kBAAC,MAAD;IAEE,WAAU;IAFZ,UAAA;KAIE,kBAAC,GAAD;MAAU,WAAU;MAAwC,eAAA;KAAa,CAAA;KACzE,kBAAC,OAAD;MAAK,WAAU;MAAf,UAAA,CACE,kBAAC,KAAD;OAAG,WAAU;OAAmB,OAAO,EAAK;OACzC,UAAA,EAAK;MACL,CAAA,GACH,kBAAC,KAAD;OAAG,WAAU;OACV,UAAA,EAAW,EAAK,MAAM,EAAQ,UAAU;MACxC,CAAA,CACA;;KACL,kBAAC,UAAD;MACE,MAAK;MACL,eAAe,EAAO,CAAG;MACzB,WAAU;MACV,cAAY,EAAa,EAAQ,WAAW,QAAQ,EAAE,MAAM,EAAK,KAAK,CAAC;MAEvE,UAAA,kBAAC,GAAD;OAAG,WAAU;OAAS,eAAA;MAAa,CAAA;KAC7B,CAAA;IACN;GApBG,GAAA,GAAG,EAAK,KAAK,GAAG,EAAK,KAAK,GAAG,EAAK,aAAa,GAAG,GAoBrD,CACL;EACC,CAAA,CAEH;;AAET,CAAC;AACD,EAAW,cAAc"}
@@ -6,17 +6,17 @@ import * as LabelPrimitive from '@radix-ui/react-label';
6
6
  * like react-hook-form's `FormProvider` — plus one shared live region for
7
7
  * validation announcements.
8
8
  */
9
- export declare function Form<TFieldValues extends FieldValues = FieldValues, TContext = unknown, TTransformedValues = TFieldValues>({ children, ...form }: FormProviderProps<TFieldValues, TContext, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
9
+ export declare function Form<TFieldValues extends FieldValues = FieldValues, TContext = unknown, TTransformedValues = TFieldValues>({ children, ...form }: FormProviderProps<TFieldValues, TContext, TTransformedValues>): import("react").JSX.Element;
10
10
  export declare namespace Form {
11
11
  var displayName: string;
12
12
  }
13
- export declare function FormField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: ControllerProps<TFieldValues, TName>): import("react/jsx-runtime").JSX.Element;
13
+ export declare function FormField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: ControllerProps<TFieldValues, TName>): import("react").JSX.Element;
14
14
  export declare function useFormField(): {
15
15
  invalid: boolean;
16
16
  isDirty: boolean;
17
17
  isTouched: boolean;
18
18
  isValidating: boolean;
19
- error?: import('react-hook-form').FieldError;
19
+ error?: import('react-hook-form').FieldError | undefined;
20
20
  id: string;
21
21
  name: string;
22
22
  formItemId: string;
@@ -26,7 +26,9 @@ export declare function useFormField(): {
26
26
  };
27
27
  export declare const FormItem: import('react').ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & import('react').RefAttributes<HTMLDivElement>>;
28
28
  export declare const FormLabel: import('react').ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & import('react').RefAttributes<HTMLLabelElement>, "ref"> & import('react').RefAttributes<HTMLLabelElement>>;
29
- export declare const FormControl: import('react').ForwardRefExoticComponent<Omit<import('@radix-ui/react-slot').SlotProps & import('react').RefAttributes<HTMLElement>, "ref"> & import('react').RefAttributes<HTMLElement>>;
29
+ export declare const FormControl: import('react').ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLElement> & {
30
+ children?: React.ReactNode;
31
+ } & import('react').RefAttributes<HTMLElement>, "ref"> & import('react').RefAttributes<HTMLElement>>;
30
32
  export declare const FormDescription: import('react').ForwardRefExoticComponent<HTMLAttributes<HTMLParagraphElement> & import('react').RefAttributes<HTMLParagraphElement>>;
31
33
  /**
32
34
  * Field-level validation message. Not a live region on its own — it is
@@ -1,131 +1,126 @@
1
1
  "use client";
2
- import { jsxs as b, jsx as i } from "react/jsx-runtime";
3
- import { forwardRef as a, useId as D, useContext as f, createContext as u, Children as N, isValidElement as h } from "react";
4
- import * as C from "@radix-ui/react-label";
5
- import { FormProvider as j, Controller as S, useFormContext as p } from "react-hook-form";
6
- import { Slot as E } from "@radix-ui/react-slot";
7
- import { cn as l } from "../../lib/utils.js";
8
- function F(o, e = []) {
9
- if (!o) return e;
10
- for (const r of Object.values(o)) {
11
- if (!r || typeof r != "object") continue;
12
- const t = r.message;
13
- typeof t == "string" && t ? e.push(t) : "type" in r || F(r, e);
14
- }
15
- return e;
2
+ import { cn as e } from "../../lib/utils.js";
3
+ import { Children as t, createContext as n, forwardRef as r, isValidElement as i, useContext as a, useId as o } from "react";
4
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
5
+ import { Slot as l } from "@radix-ui/react-slot";
6
+ import * as u from "@radix-ui/react-label";
7
+ import { Controller as d, FormProvider as f, useFormContext as p } from "react-hook-form";
8
+ //#region src/components/ui/Form.tsx
9
+ function m(e, t = []) {
10
+ if (!e) return t;
11
+ for (let n of Object.values(e)) {
12
+ if (!n || typeof n != "object") continue;
13
+ let e = n.message;
14
+ typeof e == "string" && e ? t.push(e) : "type" in n || m(n, t);
15
+ }
16
+ return t;
16
17
  }
17
- function L() {
18
- const { formState: o } = p(), e = F(o.errors);
19
- return /* @__PURE__ */ i("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: e.join(". ") });
18
+ function h() {
19
+ let { formState: e } = p(), t = m(e.errors);
20
+ return /* @__PURE__ */ s("div", {
21
+ role: "status",
22
+ "aria-live": "polite",
23
+ "aria-atomic": "true",
24
+ className: "sr-only",
25
+ children: t.join(". ")
26
+ });
20
27
  }
21
- function M({ children: o, ...e }) {
22
- return /* @__PURE__ */ b(j, { ...e, children: [
23
- o,
24
- /* @__PURE__ */ i(L, {})
25
- ] });
28
+ function g({ children: e, ...t }) {
29
+ return /* @__PURE__ */ c(f, {
30
+ ...t,
31
+ children: [e, /* @__PURE__ */ s(h, {})]
32
+ });
26
33
  }
27
- M.displayName = "Form";
28
- const y = u(null);
29
- function q(o) {
30
- return /* @__PURE__ */ i(y.Provider, { value: { name: o.name }, children: /* @__PURE__ */ i(S, { ...o }) });
34
+ g.displayName = "Form";
35
+ var _ = n(null);
36
+ function v(e) {
37
+ return /* @__PURE__ */ s(_.Provider, {
38
+ value: { name: e.name },
39
+ children: /* @__PURE__ */ s(d, { ...e })
40
+ });
31
41
  }
32
- const x = u(null);
33
- function d() {
34
- const o = f(y), e = f(x), { getFieldState: r, formState: t } = p();
35
- if (!o)
36
- throw new Error("useFormField must be used inside <FormField>");
37
- const s = r(o.name, t), n = (e == null ? void 0 : e.id) ?? "";
38
- return {
39
- id: n,
40
- name: o.name,
41
- formItemId: `${n}-item`,
42
- formDescriptionId: `${n}-desc`,
43
- formMessageId: `${n}-error`,
44
- hasDescription: (e == null ? void 0 : e.hasDescription) ?? !1,
45
- ...s
46
- };
42
+ var y = n(null);
43
+ function b() {
44
+ let e = a(_), t = a(y), { getFieldState: n, formState: r } = p();
45
+ if (!e) throw Error("useFormField must be used inside <FormField>");
46
+ let i = n(e.name, r), o = t?.id ?? "";
47
+ return {
48
+ id: o,
49
+ name: e.name,
50
+ formItemId: `${o}-item`,
51
+ formDescriptionId: `${o}-desc`,
52
+ formMessageId: `${o}-error`,
53
+ hasDescription: t?.hasDescription ?? !1,
54
+ ...i
55
+ };
47
56
  }
48
- function g(o) {
49
- return N.toArray(o).some((e) => {
50
- if (!h(e)) return !1;
51
- if (e.type === I) return !0;
52
- const r = e.props.children;
53
- return (typeof e.type == "string" || typeof e.type == "symbol") && r ? g(r) : !1;
54
- });
57
+ function x(e) {
58
+ return t.toArray(e).some((e) => {
59
+ if (!i(e)) return !1;
60
+ if (e.type === T) return !0;
61
+ let t = e.props.children;
62
+ return (typeof e.type == "string" || typeof e.type == "symbol") && t ? x(t) : !1;
63
+ });
55
64
  }
56
- const P = a(
57
- function({ className: e, children: r, ...t }, s) {
58
- const n = D(), m = g(r);
59
- return /* @__PURE__ */ i(x.Provider, { value: { id: n, hasDescription: m }, children: /* @__PURE__ */ i("div", { ref: s, className: l("flex flex-col gap-1.5", e), ...t, children: r }) });
60
- }
61
- );
62
- P.displayName = "FormItem";
63
- const w = a(function({ className: e, ...r }, t) {
64
- const { formItemId: s, error: n } = d();
65
- return /* @__PURE__ */ i(
66
- C.Root,
67
- {
68
- ref: t,
69
- htmlFor: s,
70
- className: l("text-foreground text-sm font-medium", n && "text-danger-text", e),
71
- ...r
72
- }
73
- );
65
+ var S = r(function({ className: t, children: n, ...r }, i) {
66
+ let a = o(), c = x(n);
67
+ return /* @__PURE__ */ s(y.Provider, {
68
+ value: {
69
+ id: a,
70
+ hasDescription: c
71
+ },
72
+ children: /* @__PURE__ */ s("div", {
73
+ ref: i,
74
+ className: e("flex flex-col gap-1.5", t),
75
+ ...r,
76
+ children: n
77
+ })
78
+ });
74
79
  });
75
- w.displayName = "FormLabel";
76
- const R = a(
77
- function(e, r) {
78
- const { error: t, formItemId: s, formDescriptionId: n, formMessageId: m, hasDescription: c } = d(), v = [c ? n : null, t ? m : null].filter(Boolean).join(" ") || void 0;
79
- return /* @__PURE__ */ i(
80
- E,
81
- {
82
- ref: r,
83
- id: s,
84
- "aria-describedby": v,
85
- "aria-invalid": !!t,
86
- ...e
87
- }
88
- );
89
- }
90
- );
91
- R.displayName = "FormControl";
92
- const I = a(function({ className: e, ...r }, t) {
93
- const { formDescriptionId: s } = d();
94
- return /* @__PURE__ */ i(
95
- "p",
96
- {
97
- ref: t,
98
- id: s,
99
- className: l("text-foreground-subtle text-xs", e),
100
- ...r
101
- }
102
- );
80
+ S.displayName = "FormItem";
81
+ var C = r(function({ className: t, ...n }, r) {
82
+ let { formItemId: i, error: a } = b();
83
+ return /* @__PURE__ */ s(u.Root, {
84
+ ref: r,
85
+ htmlFor: i,
86
+ className: e("text-foreground text-sm font-medium", a && "text-danger-text", t),
87
+ ...n
88
+ });
103
89
  });
104
- I.displayName = "FormDescription";
105
- const $ = a(
106
- function({ className: e, children: r, ...t }, s) {
107
- const { error: n, formMessageId: m } = d(), c = n ? String((n == null ? void 0 : n.message) ?? "") : r;
108
- return c ? /* @__PURE__ */ i(
109
- "p",
110
- {
111
- ref: s,
112
- id: m,
113
- className: l("text-danger-text text-xs", e),
114
- ...t,
115
- children: c
116
- }
117
- ) : null;
118
- }
119
- );
120
- $.displayName = "FormError";
121
- export {
122
- M as Form,
123
- R as FormControl,
124
- I as FormDescription,
125
- $ as FormError,
126
- q as FormField,
127
- P as FormItem,
128
- w as FormLabel,
129
- d as useFormField
130
- };
131
- //# sourceMappingURL=Form.js.map
90
+ C.displayName = "FormLabel";
91
+ var w = r(function(e, t) {
92
+ let { error: n, formItemId: r, formDescriptionId: i, formMessageId: a, hasDescription: o } = b(), c = [o ? i : null, n ? a : null].filter(Boolean).join(" ") || void 0;
93
+ return /* @__PURE__ */ s(l, {
94
+ ref: t,
95
+ id: r,
96
+ "aria-describedby": c,
97
+ "aria-invalid": !!n,
98
+ ...e
99
+ });
100
+ });
101
+ w.displayName = "FormControl";
102
+ var T = r(function({ className: t, ...n }, r) {
103
+ let { formDescriptionId: i } = b();
104
+ return /* @__PURE__ */ s("p", {
105
+ ref: r,
106
+ id: i,
107
+ className: e("text-foreground-subtle text-xs", t),
108
+ ...n
109
+ });
110
+ });
111
+ T.displayName = "FormDescription";
112
+ var E = r(function({ className: t, children: n, ...r }, i) {
113
+ let { error: a, formMessageId: o } = b(), c = a ? String(a?.message ?? "") : n;
114
+ return c ? /* @__PURE__ */ s("p", {
115
+ ref: i,
116
+ id: o,
117
+ className: e("text-danger-text text-xs", t),
118
+ ...r,
119
+ children: c
120
+ }) : null;
121
+ });
122
+ E.displayName = "FormError";
123
+ //#endregion
124
+ export { g as Form, w as FormControl, T as FormDescription, E as FormError, v as FormField, S as FormItem, C as FormLabel, b as useFormField };
125
+
126
+ //# sourceMappingURL=Form.js.map