@craftzbay/ui 0.11.3 → 1.0.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.
- package/README.md +1 -1
- package/dist-lib/_virtual/_rolldown/runtime.js +11 -0
- package/dist-lib/components/ui/Accordion.js +42 -67
- package/dist-lib/components/ui/Accordion.js.map +1 -1
- package/dist-lib/components/ui/Alert.js +71 -77
- package/dist-lib/components/ui/Alert.js.map +1 -1
- package/dist-lib/components/ui/Avatar.js +67 -92
- package/dist-lib/components/ui/Avatar.js.map +1 -1
- package/dist-lib/components/ui/Badge.js +119 -74
- package/dist-lib/components/ui/Badge.js.map +1 -1
- package/dist-lib/components/ui/Breadcrumbs.js +62 -50
- package/dist-lib/components/ui/Breadcrumbs.js.map +1 -1
- package/dist-lib/components/ui/Button.js +129 -131
- package/dist-lib/components/ui/Button.js.map +1 -1
- package/dist-lib/components/ui/Calendar.d.ts +1 -1
- package/dist-lib/components/ui/Calendar.js +99 -136
- package/dist-lib/components/ui/Calendar.js.map +1 -1
- package/dist-lib/components/ui/Card.js +88 -94
- package/dist-lib/components/ui/Card.js.map +1 -1
- package/dist-lib/components/ui/Carousel.js +125 -170
- package/dist-lib/components/ui/Carousel.js.map +1 -1
- package/dist-lib/components/ui/Chart.d.ts +3 -3
- package/dist-lib/components/ui/Chart.js +435 -464
- package/dist-lib/components/ui/Chart.js.map +1 -1
- package/dist-lib/components/ui/Checkbox.js +60 -69
- package/dist-lib/components/ui/Checkbox.js.map +1 -1
- package/dist-lib/components/ui/Combobox.js +179 -192
- package/dist-lib/components/ui/Combobox.js.map +1 -1
- package/dist-lib/components/ui/CommandPalette.d.ts +2 -2
- package/dist-lib/components/ui/CommandPalette.js +106 -167
- package/dist-lib/components/ui/CommandPalette.js.map +1 -1
- package/dist-lib/components/ui/ContextMenu.d.ts +1 -1
- package/dist-lib/components/ui/ContextMenu.js +89 -154
- package/dist-lib/components/ui/ContextMenu.js.map +1 -1
- package/dist-lib/components/ui/DataGrid.d.ts +1 -1
- package/dist-lib/components/ui/DataGrid.js +99 -96
- package/dist-lib/components/ui/DataGrid.js.map +1 -1
- package/dist-lib/components/ui/DatePicker.js +151 -188
- package/dist-lib/components/ui/DatePicker.js.map +1 -1
- package/dist-lib/components/ui/DesignSystemProvider.d.ts +1 -1
- package/dist-lib/components/ui/DesignSystemProvider.js +120 -130
- package/dist-lib/components/ui/DesignSystemProvider.js.map +1 -1
- package/dist-lib/components/ui/Dialog.d.ts +3 -3
- package/dist-lib/components/ui/Dialog.js +108 -156
- package/dist-lib/components/ui/Dialog.js.map +1 -1
- package/dist-lib/components/ui/Drawer.d.ts +3 -3
- package/dist-lib/components/ui/Drawer.js +90 -124
- package/dist-lib/components/ui/Drawer.js.map +1 -1
- package/dist-lib/components/ui/DropdownMenu.d.ts +1 -1
- package/dist-lib/components/ui/DropdownMenu.js +92 -158
- package/dist-lib/components/ui/DropdownMenu.js.map +1 -1
- package/dist-lib/components/ui/EmptyState.js +31 -44
- package/dist-lib/components/ui/EmptyState.js.map +1 -1
- package/dist-lib/components/ui/ErrorState.js +57 -67
- package/dist-lib/components/ui/ErrorState.js.map +1 -1
- package/dist-lib/components/ui/FileUpload.js +113 -107
- package/dist-lib/components/ui/FileUpload.js.map +1 -1
- package/dist-lib/components/ui/Form.d.ts +6 -4
- package/dist-lib/components/ui/Form.js +117 -122
- package/dist-lib/components/ui/Form.js.map +1 -1
- package/dist-lib/components/ui/Icon.d.ts +1 -1
- package/dist-lib/components/ui/Icon.js +30 -29
- package/dist-lib/components/ui/Icon.js.map +1 -1
- package/dist-lib/components/ui/IconButton.js +61 -63
- package/dist-lib/components/ui/IconButton.js.map +1 -1
- package/dist-lib/components/ui/Input.js +133 -156
- package/dist-lib/components/ui/Input.js.map +1 -1
- package/dist-lib/components/ui/Kbd.js +14 -21
- package/dist-lib/components/ui/Kbd.js.map +1 -1
- package/dist-lib/components/ui/MultiSelect.js +176 -208
- package/dist-lib/components/ui/MultiSelect.js.map +1 -1
- package/dist-lib/components/ui/Pagination.js +152 -149
- package/dist-lib/components/ui/Pagination.js.map +1 -1
- package/dist-lib/components/ui/Popover.js +18 -33
- package/dist-lib/components/ui/Popover.js.map +1 -1
- package/dist-lib/components/ui/Progress.js +77 -99
- package/dist-lib/components/ui/Progress.js.map +1 -1
- package/dist-lib/components/ui/RadioGroup.js +51 -80
- package/dist-lib/components/ui/RadioGroup.js.map +1 -1
- package/dist-lib/components/ui/RelativeTime.js +22 -29
- package/dist-lib/components/ui/RelativeTime.js.map +1 -1
- package/dist-lib/components/ui/ScrollArea.js +39 -58
- package/dist-lib/components/ui/ScrollArea.js.map +1 -1
- package/dist-lib/components/ui/Select.js +108 -131
- package/dist-lib/components/ui/Select.js.map +1 -1
- package/dist-lib/components/ui/Separator.js +18 -24
- package/dist-lib/components/ui/Separator.js.map +1 -1
- package/dist-lib/components/ui/Sheet.d.ts +2 -2
- package/dist-lib/components/ui/Sheet.js +77 -129
- package/dist-lib/components/ui/Sheet.js.map +1 -1
- package/dist-lib/components/ui/Sidebar.d.ts +1 -1
- package/dist-lib/components/ui/Sidebar.js +168 -207
- package/dist-lib/components/ui/Sidebar.js.map +1 -1
- package/dist-lib/components/ui/Skeleton.js +17 -27
- package/dist-lib/components/ui/Skeleton.js.map +1 -1
- package/dist-lib/components/ui/Slider.js +45 -62
- package/dist-lib/components/ui/Slider.js.map +1 -1
- package/dist-lib/components/ui/Snackbar.js +75 -55
- package/dist-lib/components/ui/Snackbar.js.map +1 -1
- package/dist-lib/components/ui/Spinner.js +45 -52
- package/dist-lib/components/ui/Spinner.js.map +1 -1
- package/dist-lib/components/ui/Stepper.js +56 -108
- package/dist-lib/components/ui/Stepper.js.map +1 -1
- package/dist-lib/components/ui/Switch.js +46 -79
- package/dist-lib/components/ui/Switch.js.map +1 -1
- package/dist-lib/components/ui/Table.js +108 -169
- package/dist-lib/components/ui/Table.js.map +1 -1
- package/dist-lib/components/ui/Tabs.js +57 -88
- package/dist-lib/components/ui/Tabs.js.map +1 -1
- package/dist-lib/components/ui/TagInput.js +76 -109
- package/dist-lib/components/ui/TagInput.js.map +1 -1
- package/dist-lib/components/ui/Textarea.js +74 -86
- package/dist-lib/components/ui/Textarea.js.map +1 -1
- package/dist-lib/components/ui/Timeline.d.ts +3 -3
- package/dist-lib/components/ui/Timeline.js +61 -49
- package/dist-lib/components/ui/Timeline.js.map +1 -1
- package/dist-lib/components/ui/Toast.d.ts +1 -1
- package/dist-lib/components/ui/Toast.js +136 -150
- package/dist-lib/components/ui/Toast.js.map +1 -1
- package/dist-lib/components/ui/Tooltip.d.ts +2 -2
- package/dist-lib/components/ui/Tooltip.js +35 -56
- package/dist-lib/components/ui/Tooltip.js.map +1 -1
- package/dist-lib/components/ui/TopNav.js +46 -66
- package/dist-lib/components/ui/TopNav.js.map +1 -1
- package/dist-lib/components/ui/Tree.js +134 -168
- package/dist-lib/components/ui/Tree.js.map +1 -1
- package/dist-lib/hooks/use-debounce.js +24 -33
- package/dist-lib/hooks/use-debounce.js.map +1 -1
- package/dist-lib/hooks/use-delayed-loading.js +20 -18
- package/dist-lib/hooks/use-delayed-loading.js.map +1 -1
- package/dist-lib/hooks/use-field-ids.js +14 -16
- package/dist-lib/hooks/use-field-ids.js.map +1 -1
- package/dist-lib/hooks/use-media-query.js +15 -19
- package/dist-lib/hooks/use-media-query.js.map +1 -1
- package/dist-lib/hooks/use-modifier-key.d.ts +0 -4
- package/dist-lib/hooks/use-modifier-key.js +19 -16
- package/dist-lib/hooks/use-modifier-key.js.map +1 -1
- package/dist-lib/hooks/use-strings.js +10 -10
- package/dist-lib/hooks/use-strings.js.map +1 -1
- package/dist-lib/hooks/use-toast.js +73 -62
- package/dist-lib/hooks/use-toast.js.map +1 -1
- package/dist-lib/icon.js +2 -6
- package/dist-lib/icons/index.d.ts +1 -1
- package/dist-lib/icons/index.js +166 -163
- package/dist-lib/icons/index.js.map +1 -1
- package/dist-lib/illustrations/index.d.ts +7 -7
- package/dist-lib/illustrations/index.js +255 -106
- package/dist-lib/illustrations/index.js.map +1 -1
- package/dist-lib/index.js +69 -291
- package/dist-lib/lib/cva.js +2 -0
- package/dist-lib/lib/format.js +71 -87
- package/dist-lib/lib/format.js.map +1 -1
- package/dist-lib/lib/return-focus.js +11 -11
- package/dist-lib/lib/return-focus.js.map +1 -1
- package/dist-lib/lib/strings.js +167 -135
- package/dist-lib/lib/strings.js.map +1 -1
- package/dist-lib/lib/strings.mn.js +150 -113
- package/dist-lib/lib/strings.mn.js.map +1 -1
- package/dist-lib/lib/utils.js +9 -9
- package/dist-lib/lib/utils.js.map +1 -1
- package/dist-lib/styles.css +3 -1
- package/package.json +53 -53
- package/dist-lib/__tests__/helpers/color.d.ts +0 -9
- package/dist-lib/__tests__/helpers/theme.d.ts +0 -18
- package/dist-lib/icon.js.map +0 -1
- package/dist-lib/index.js.map +0 -1
|
@@ -1,111 +1,117 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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,G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AAamB,EAAQ,WAAW,QAAQ,EAAE,MAAMjB,EAAK,MAAM;AAAA,cAEvE,UAAA,gBAAA8C,EAAC,GAAA,EAAE,WAAU,UAAS,eAAW,GAAA,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,QACpC;AAAA,MAAA;AAAA,MAnBK,GAAG9C,EAAK,IAAI,IAAIA,EAAK,IAAI,IAAIA,EAAK,YAAY,IAAIwC,CAAG;AAAA,IAAA,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,EAAM,CAAC,IACvD,IAAQ,UAAoB,EAAa,EAAE,WAAW,EAAE,IAAI,IAAQ,KAAA,CAAM,QAAQ,CAAC,EAAE,CAAC,IACnF,EAAa,EAAE,WAAW,EAAE,IAAI,IAAQ,OAAO,KAAA,CAAM,QAAQ,CAAC,EAAE,CAAC;AAC1E;AAGA,SAAS,EAAc,GAAY,GAA0B;CAC3D,IAAI,CAAC,GAAQ,OAAO;CACpB,IAAM,IAAQ,EACX,MAAM,GAAG,CAAC,CACV,KAAK,MAAM,EAAE,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAClC,OAAO,OAAO;CACjB,IAAI,CAAC,EAAM,QAAQ,OAAO;CAC1B,IAAM,IAAO,EAAK,KAAK,YAAY,GAC7B,IAAO,EAAK,KAAK,YAAY;CACnC,OAAO,EAAM,MAAM,MACb,EAAK,WAAW,GAAG,IAAU,EAAK,SAAS,CAAI,IAC/C,EAAK,SAAS,IAAI,IAAU,EAAK,WAAW,EAAK,MAAM,GAAG,EAAE,CAAC,IAC1D,MAAS,CACjB;AACH;AAMA,IAAa,IAAa,EAA4C,SACpE,EAAE,WAAQ,aAAU,YAAS,UAAO,aAAU,aAAU,SAAM,aAAU,gBACxE,GACA;CACA,IAAM,IAAU,EAAW,GACrB,IAAW,EAAyB,IAAI,GACxC,IAAU,EAAM,GAChB,CAAC,GAAU,KAAe,EAAiB,CAAC,CAAC,GAC7C,CAAC,GAAM,KAAW,EAAS,EAAK,GAGhC,IAAY,EAAO,CAAC,GACpB,IAAQ,KAAS,GAEj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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
|
|
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
|
|
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<
|
|
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 {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
function g({ children: e, ...t }) {
|
|
29
|
+
return /* @__PURE__ */ c(f, {
|
|
30
|
+
...t,
|
|
31
|
+
children: [e, /* @__PURE__ */ s(h, {})]
|
|
32
|
+
});
|
|
26
33
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|