@la-batcave/ui 3.1.2
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 +95 -0
- package/dist/Alert.d.ts +27 -0
- package/dist/Alert.js +56 -0
- package/dist/Avatar.d.ts +20 -0
- package/dist/Avatar.js +40 -0
- package/dist/Badge.d.ts +56 -0
- package/dist/Badge.js +74 -0
- package/dist/Button.d.ts +53 -0
- package/dist/Button.js +66 -0
- package/dist/Card.d.ts +18 -0
- package/dist/Card.js +98 -0
- package/dist/CodeBlock.d.ts +45 -0
- package/dist/CodeBlock.js +306 -0
- package/dist/Collapse.d.ts +58 -0
- package/dist/Collapse.js +89 -0
- package/dist/Combobox.d.ts +44 -0
- package/dist/Combobox.js +409 -0
- package/dist/DarkMode.d.ts +59 -0
- package/dist/DarkMode.js +56 -0
- package/dist/DatePicker.d.ts +48 -0
- package/dist/DatePicker.js +2954 -0
- package/dist/Dialog.d.ts +119 -0
- package/dist/Dialog.js +337 -0
- package/dist/Drawer.d.ts +28 -0
- package/dist/Drawer.js +1126 -0
- package/dist/Dropdown.d.ts +23 -0
- package/dist/Dropdown.js +247 -0
- package/dist/EasyForm.d.ts +138 -0
- package/dist/EasyForm.js +286 -0
- package/dist/HoverCard.d.ts +10 -0
- package/dist/HoverCard.js +195 -0
- package/dist/Input.d.ts +230 -0
- package/dist/Input.js +2216 -0
- package/dist/LogViewer.d.ts +57 -0
- package/dist/LogViewer.js +120 -0
- package/dist/Menubar.d.ts +32 -0
- package/dist/Menubar.js +398 -0
- package/dist/Navbar.d.ts +20 -0
- package/dist/Navbar.js +31 -0
- package/dist/Pagination.d.ts +78 -0
- package/dist/Pagination.js +106 -0
- package/dist/Popover.d.ts +11 -0
- package/dist/Popover.js +28 -0
- package/dist/ProgressBar.d.ts +35 -0
- package/dist/ProgressBar.js +210 -0
- package/dist/Resizable.d.ts +23 -0
- package/dist/Resizable.js +1532 -0
- package/dist/Separator.d.ts +4 -0
- package/dist/Separator.js +46 -0
- package/dist/Sheet.d.ts +29 -0
- package/dist/Sheet.js +104 -0
- package/dist/Sidebar.d.ts +117 -0
- package/dist/Sidebar.js +237 -0
- package/dist/Skeleton.d.ts +57 -0
- package/dist/Skeleton.js +47 -0
- package/dist/Table.d.ts +71 -0
- package/dist/Table.js +94 -0
- package/dist/Tabs.d.ts +76 -0
- package/dist/Tabs.js +202 -0
- package/dist/Toast.d.ts +54 -0
- package/dist/Toast.js +827 -0
- package/dist/Tooltip.d.ts +29 -0
- package/dist/Tooltip.js +352 -0
- package/dist/Typography.d.ts +101 -0
- package/dist/Typography.js +123 -0
- package/dist/Widget.d.ts +133 -0
- package/dist/Widget.js +207 -0
- package/dist/_shared/Combination-D_l4PLF_.js +676 -0
- package/dist/_shared/index-B03TCNO5.js +142 -0
- package/dist/_shared/index-B1f-hyuh.js +31 -0
- package/dist/_shared/index-BC7vfx-u.js +13 -0
- package/dist/_shared/index-BrLJJgkl.js +67 -0
- package/dist/_shared/index-C0gNQvxa.js +269 -0
- package/dist/_shared/index-C3aZemLI.js +268 -0
- package/dist/_shared/index-CXeb1OMI.js +198 -0
- package/dist/_shared/index-CukUn3R0.js +626 -0
- package/dist/_shared/index-DLcqcWxM.js +29 -0
- package/dist/_shared/index-DlSuDb9N.js +283 -0
- package/dist/_shared/index-V-Ajw7Ac.js +79 -0
- package/dist/_shared/index-uPOYJZpG.js +34 -0
- package/dist/_shared/index-uu9PT5Nu.js +1588 -0
- package/dist/_shared/utils-eGXXUFl7.js +2935 -0
- package/dist/backgrounds/Aurora.d.ts +7 -0
- package/dist/backgrounds/Aurora.js +126 -0
- package/dist/backgrounds/Iridescence.d.ts +7 -0
- package/dist/backgrounds/Iridescence.js +77 -0
- package/dist/backgrounds/Lightning.d.ts +8 -0
- package/dist/backgrounds/Lightning.js +75 -0
- package/dist/backgrounds/LiquidChrome.d.ts +9 -0
- package/dist/backgrounds/LiquidChrome.js +89 -0
- package/dist/backgrounds/Particles.d.ts +15 -0
- package/dist/backgrounds/Particles.js +137 -0
- package/dist/backgrounds/PixelSnow.d.ts +9 -0
- package/dist/backgrounds/PixelSnow.js +52 -0
- package/dist/backgrounds/Silk.d.ts +8 -0
- package/dist/backgrounds/Silk.js +92 -0
- package/dist/backgrounds/Squares.d.ts +9 -0
- package/dist/backgrounds/Squares.js +75 -0
- package/dist/backgrounds/Threads.d.ts +7 -0
- package/dist/backgrounds/Threads.js +110 -0
- package/dist/backgrounds/Waves.d.ts +14 -0
- package/dist/backgrounds/Waves.js +139 -0
- package/dist/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/package.json +318 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
3
|
+
declare const DropdownMenu: React.FC<DropdownMenuPrimitive.DropdownMenuProps>;
|
|
4
|
+
declare const DropdownMenuTrigger: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
declare const DropdownMenuGroup: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export interface DropdownMenuContentProps extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> {
|
|
7
|
+
/** Portal container. @default document.body */
|
|
8
|
+
container?: HTMLElement;
|
|
9
|
+
}
|
|
10
|
+
declare const DropdownMenuContent: React.ForwardRefExoticComponent<DropdownMenuContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
|
+
export interface DropdownMenuItemProps extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> {
|
|
12
|
+
/** Whether the item triggers a destructive action. */
|
|
13
|
+
inset?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const DropdownMenuItem: React.ForwardRefExoticComponent<DropdownMenuItemProps & React.RefAttributes<HTMLDivElement>>;
|
|
16
|
+
export interface DropdownMenuSeparatorProps extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator> {
|
|
17
|
+
}
|
|
18
|
+
declare const DropdownMenuSeparator: React.ForwardRefExoticComponent<DropdownMenuSeparatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
19
|
+
export interface DropdownMenuLabelProps extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> {
|
|
20
|
+
inset?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare const DropdownMenuLabel: React.ForwardRefExoticComponent<DropdownMenuLabelProps & React.RefAttributes<HTMLDivElement>>;
|
|
23
|
+
export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuLabel, DropdownMenuGroup, };
|
package/dist/Dropdown.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
3
|
+
import * as d from "react";
|
|
4
|
+
import { c as m, a as P, u as O } from "./_shared/index-CXeb1OMI.js";
|
|
5
|
+
import { c as T } from "./_shared/index-DLcqcWxM.js";
|
|
6
|
+
import { P as G } from "./_shared/index-V-Ajw7Ac.js";
|
|
7
|
+
import { P as k, C as L, I as $, S as K, L as U, c as v, R as B, G as z, A as F, a as H, b as W, d as j, e as X, f as q, g as J, h as Q } from "./_shared/index-CukUn3R0.js";
|
|
8
|
+
import { u as D } from "./_shared/index-BC7vfx-u.js";
|
|
9
|
+
import { c as f } from "./_shared/utils-eGXXUFl7.js";
|
|
10
|
+
var M = "DropdownMenu", [V] = P(
|
|
11
|
+
M,
|
|
12
|
+
[v]
|
|
13
|
+
), s = v(), [Y, _] = V(M), b = (e) => {
|
|
14
|
+
const {
|
|
15
|
+
__scopeDropdownMenu: r,
|
|
16
|
+
children: o,
|
|
17
|
+
dir: n,
|
|
18
|
+
open: a,
|
|
19
|
+
defaultOpen: u,
|
|
20
|
+
onOpenChange: i,
|
|
21
|
+
modal: p = !0
|
|
22
|
+
} = e, c = s(r), g = d.useRef(null), [l, w] = O({
|
|
23
|
+
prop: a,
|
|
24
|
+
defaultProp: u ?? !1,
|
|
25
|
+
onChange: i,
|
|
26
|
+
caller: M
|
|
27
|
+
});
|
|
28
|
+
return /* @__PURE__ */ t(
|
|
29
|
+
Y,
|
|
30
|
+
{
|
|
31
|
+
scope: r,
|
|
32
|
+
triggerId: D(),
|
|
33
|
+
triggerRef: g,
|
|
34
|
+
contentId: D(),
|
|
35
|
+
open: l,
|
|
36
|
+
onOpenChange: w,
|
|
37
|
+
onOpenToggle: d.useCallback(() => w((E) => !E), [w]),
|
|
38
|
+
modal: p,
|
|
39
|
+
children: /* @__PURE__ */ t(B, { ...c, open: l, onOpenChange: w, dir: n, modal: p, children: o })
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
b.displayName = M;
|
|
44
|
+
var h = "DropdownMenuTrigger", R = d.forwardRef(
|
|
45
|
+
(e, r) => {
|
|
46
|
+
const { __scopeDropdownMenu: o, disabled: n = !1, ...a } = e, u = _(h, o), i = s(o);
|
|
47
|
+
return /* @__PURE__ */ t(F, { asChild: !0, ...i, children: /* @__PURE__ */ t(
|
|
48
|
+
G.button,
|
|
49
|
+
{
|
|
50
|
+
type: "button",
|
|
51
|
+
id: u.triggerId,
|
|
52
|
+
"aria-haspopup": "menu",
|
|
53
|
+
"aria-expanded": u.open,
|
|
54
|
+
"aria-controls": u.open ? u.contentId : void 0,
|
|
55
|
+
"data-state": u.open ? "open" : "closed",
|
|
56
|
+
"data-disabled": n ? "" : void 0,
|
|
57
|
+
disabled: n,
|
|
58
|
+
...a,
|
|
59
|
+
ref: T(r, u.triggerRef),
|
|
60
|
+
onPointerDown: m(e.onPointerDown, (p) => {
|
|
61
|
+
!n && p.button === 0 && p.ctrlKey === !1 && (u.onOpenToggle(), u.open || p.preventDefault());
|
|
62
|
+
}),
|
|
63
|
+
onKeyDown: m(e.onKeyDown, (p) => {
|
|
64
|
+
n || (["Enter", " "].includes(p.key) && u.onOpenToggle(), p.key === "ArrowDown" && u.onOpenChange(!0), ["Enter", " ", "ArrowDown"].includes(p.key) && p.preventDefault());
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
) });
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
R.displayName = h;
|
|
71
|
+
var Z = "DropdownMenuPortal", N = (e) => {
|
|
72
|
+
const { __scopeDropdownMenu: r, ...o } = e, n = s(r);
|
|
73
|
+
return /* @__PURE__ */ t(k, { ...n, ...o });
|
|
74
|
+
};
|
|
75
|
+
N.displayName = Z;
|
|
76
|
+
var x = "DropdownMenuContent", I = d.forwardRef(
|
|
77
|
+
(e, r) => {
|
|
78
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = _(x, o), u = s(o), i = d.useRef(!1);
|
|
79
|
+
return /* @__PURE__ */ t(
|
|
80
|
+
L,
|
|
81
|
+
{
|
|
82
|
+
id: a.contentId,
|
|
83
|
+
"aria-labelledby": a.triggerId,
|
|
84
|
+
...u,
|
|
85
|
+
...n,
|
|
86
|
+
ref: r,
|
|
87
|
+
onCloseAutoFocus: m(e.onCloseAutoFocus, (p) => {
|
|
88
|
+
i.current || a.triggerRef.current?.focus(), i.current = !1, p.preventDefault();
|
|
89
|
+
}),
|
|
90
|
+
onInteractOutside: m(e.onInteractOutside, (p) => {
|
|
91
|
+
const c = p.detail.originalEvent, g = c.button === 0 && c.ctrlKey === !0, l = c.button === 2 || g;
|
|
92
|
+
(!a.modal || l) && (i.current = !0);
|
|
93
|
+
}),
|
|
94
|
+
style: {
|
|
95
|
+
...e.style,
|
|
96
|
+
"--radix-dropdown-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
97
|
+
"--radix-dropdown-menu-content-available-width": "var(--radix-popper-available-width)",
|
|
98
|
+
"--radix-dropdown-menu-content-available-height": "var(--radix-popper-available-height)",
|
|
99
|
+
"--radix-dropdown-menu-trigger-width": "var(--radix-popper-anchor-width)",
|
|
100
|
+
"--radix-dropdown-menu-trigger-height": "var(--radix-popper-anchor-height)"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
I.displayName = x;
|
|
107
|
+
var ee = "DropdownMenuGroup", y = d.forwardRef(
|
|
108
|
+
(e, r) => {
|
|
109
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
110
|
+
return /* @__PURE__ */ t(z, { ...a, ...n, ref: r });
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
y.displayName = ee;
|
|
114
|
+
var oe = "DropdownMenuLabel", S = d.forwardRef(
|
|
115
|
+
(e, r) => {
|
|
116
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
117
|
+
return /* @__PURE__ */ t(U, { ...a, ...n, ref: r });
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
S.displayName = oe;
|
|
121
|
+
var re = "DropdownMenuItem", C = d.forwardRef(
|
|
122
|
+
(e, r) => {
|
|
123
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
124
|
+
return /* @__PURE__ */ t($, { ...a, ...n, ref: r });
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
C.displayName = re;
|
|
128
|
+
var ne = "DropdownMenuCheckboxItem", ae = d.forwardRef((e, r) => {
|
|
129
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
130
|
+
return /* @__PURE__ */ t(H, { ...a, ...n, ref: r });
|
|
131
|
+
});
|
|
132
|
+
ae.displayName = ne;
|
|
133
|
+
var te = "DropdownMenuRadioGroup", de = d.forwardRef((e, r) => {
|
|
134
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
135
|
+
return /* @__PURE__ */ t(W, { ...a, ...n, ref: r });
|
|
136
|
+
});
|
|
137
|
+
de.displayName = te;
|
|
138
|
+
var pe = "DropdownMenuRadioItem", se = d.forwardRef((e, r) => {
|
|
139
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
140
|
+
return /* @__PURE__ */ t(j, { ...a, ...n, ref: r });
|
|
141
|
+
});
|
|
142
|
+
se.displayName = pe;
|
|
143
|
+
var ue = "DropdownMenuItemIndicator", ie = d.forwardRef((e, r) => {
|
|
144
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
145
|
+
return /* @__PURE__ */ t(X, { ...a, ...n, ref: r });
|
|
146
|
+
});
|
|
147
|
+
ie.displayName = ue;
|
|
148
|
+
var ce = "DropdownMenuSeparator", A = d.forwardRef((e, r) => {
|
|
149
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
150
|
+
return /* @__PURE__ */ t(K, { ...a, ...n, ref: r });
|
|
151
|
+
});
|
|
152
|
+
A.displayName = ce;
|
|
153
|
+
var le = "DropdownMenuArrow", we = d.forwardRef(
|
|
154
|
+
(e, r) => {
|
|
155
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
156
|
+
return /* @__PURE__ */ t(q, { ...a, ...n, ref: r });
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
we.displayName = le;
|
|
160
|
+
var me = "DropdownMenuSubTrigger", fe = d.forwardRef((e, r) => {
|
|
161
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
162
|
+
return /* @__PURE__ */ t(J, { ...a, ...n, ref: r });
|
|
163
|
+
});
|
|
164
|
+
fe.displayName = me;
|
|
165
|
+
var Me = "DropdownMenuSubContent", ge = d.forwardRef((e, r) => {
|
|
166
|
+
const { __scopeDropdownMenu: o, ...n } = e, a = s(o);
|
|
167
|
+
return /* @__PURE__ */ t(
|
|
168
|
+
Q,
|
|
169
|
+
{
|
|
170
|
+
...a,
|
|
171
|
+
...n,
|
|
172
|
+
ref: r,
|
|
173
|
+
style: {
|
|
174
|
+
...e.style,
|
|
175
|
+
"--radix-dropdown-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
|
|
176
|
+
"--radix-dropdown-menu-content-available-width": "var(--radix-popper-available-width)",
|
|
177
|
+
"--radix-dropdown-menu-content-available-height": "var(--radix-popper-available-height)",
|
|
178
|
+
"--radix-dropdown-menu-trigger-width": "var(--radix-popper-anchor-width)",
|
|
179
|
+
"--radix-dropdown-menu-trigger-height": "var(--radix-popper-anchor-height)"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
ge.displayName = Me;
|
|
185
|
+
var De = b, ve = R, _e = N, be = I, he = y, Re = S, Ne = C, xe = A;
|
|
186
|
+
const Le = De, $e = ve, Ke = he, Ie = d.forwardRef(({ className: e, sideOffset: r = 4, container: o, ...n }, a) => /* @__PURE__ */ t(_e, { container: o, children: /* @__PURE__ */ t(
|
|
187
|
+
be,
|
|
188
|
+
{
|
|
189
|
+
ref: a,
|
|
190
|
+
sideOffset: r,
|
|
191
|
+
className: f(
|
|
192
|
+
"z-50 bg-card border border-border rounded-lg shadow-lg p-1 min-w-[180px]",
|
|
193
|
+
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
194
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",
|
|
195
|
+
"outline-none",
|
|
196
|
+
e
|
|
197
|
+
),
|
|
198
|
+
...n
|
|
199
|
+
}
|
|
200
|
+
) }));
|
|
201
|
+
Ie.displayName = "DropdownMenuContent";
|
|
202
|
+
const ye = d.forwardRef(({ className: e, inset: r, ...o }, n) => /* @__PURE__ */ t(
|
|
203
|
+
Ne,
|
|
204
|
+
{
|
|
205
|
+
ref: n,
|
|
206
|
+
className: f(
|
|
207
|
+
"flex items-center gap-2 px-3 py-2 text-sm rounded-md cursor-pointer outline-none",
|
|
208
|
+
"text-foreground hover:bg-muted focus:bg-muted",
|
|
209
|
+
"data-[disabled]:opacity-50 data-[disabled]:pointer-events-none",
|
|
210
|
+
r && "pl-8",
|
|
211
|
+
e
|
|
212
|
+
),
|
|
213
|
+
...o
|
|
214
|
+
}
|
|
215
|
+
));
|
|
216
|
+
ye.displayName = "DropdownMenuItem";
|
|
217
|
+
const Se = d.forwardRef(({ className: e, ...r }, o) => /* @__PURE__ */ t(
|
|
218
|
+
xe,
|
|
219
|
+
{
|
|
220
|
+
ref: o,
|
|
221
|
+
className: f("mx-1 my-1 h-px bg-border", e),
|
|
222
|
+
...r
|
|
223
|
+
}
|
|
224
|
+
));
|
|
225
|
+
Se.displayName = "DropdownMenuSeparator";
|
|
226
|
+
const Ce = d.forwardRef(({ className: e, inset: r, ...o }, n) => /* @__PURE__ */ t(
|
|
227
|
+
Re,
|
|
228
|
+
{
|
|
229
|
+
ref: n,
|
|
230
|
+
className: f(
|
|
231
|
+
"px-3 py-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground",
|
|
232
|
+
r && "pl-8",
|
|
233
|
+
e
|
|
234
|
+
),
|
|
235
|
+
...o
|
|
236
|
+
}
|
|
237
|
+
));
|
|
238
|
+
Ce.displayName = "DropdownMenuLabel";
|
|
239
|
+
export {
|
|
240
|
+
Le as DropdownMenu,
|
|
241
|
+
Ie as DropdownMenuContent,
|
|
242
|
+
Ke as DropdownMenuGroup,
|
|
243
|
+
ye as DropdownMenuItem,
|
|
244
|
+
Ce as DropdownMenuLabel,
|
|
245
|
+
Se as DropdownMenuSeparator,
|
|
246
|
+
$e as DropdownMenuTrigger
|
|
247
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ValidationRules {
|
|
3
|
+
/** Field is required. Pass a string for a custom error message. */
|
|
4
|
+
required?: boolean | string;
|
|
5
|
+
/** Minimum value (number/slider) or minimum length (string). */
|
|
6
|
+
min?: number | {
|
|
7
|
+
value: number;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
/** Maximum value (number/slider) or maximum length (string). */
|
|
11
|
+
max?: number | {
|
|
12
|
+
value: number;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
/** Minimum string length. */
|
|
16
|
+
minLength?: number | {
|
|
17
|
+
value: number;
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
/** Maximum string length. */
|
|
21
|
+
maxLength?: number | {
|
|
22
|
+
value: number;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
/** Regex pattern the value must match. */
|
|
26
|
+
pattern?: RegExp | {
|
|
27
|
+
value: RegExp;
|
|
28
|
+
message: string;
|
|
29
|
+
};
|
|
30
|
+
/** Custom validator. Return an error message string, or undefined if valid. */
|
|
31
|
+
custom?: (value: unknown, values: FormValues) => string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export type FormValues = Record<string, unknown>;
|
|
34
|
+
interface BaseField {
|
|
35
|
+
/** Unique field name, used as key in values. */
|
|
36
|
+
name: string;
|
|
37
|
+
/** Label displayed above/next to the field. */
|
|
38
|
+
label?: string;
|
|
39
|
+
/** Placeholder text. */
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
/** Whether the field is disabled. */
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
/** Validation rules. */
|
|
44
|
+
validation?: ValidationRules;
|
|
45
|
+
}
|
|
46
|
+
export interface TextField extends BaseField {
|
|
47
|
+
type: "text" | "email" | "password" | "number";
|
|
48
|
+
icon?: React.ComponentType<{
|
|
49
|
+
size?: number;
|
|
50
|
+
className?: string;
|
|
51
|
+
}>;
|
|
52
|
+
iconPosition?: "left" | "right";
|
|
53
|
+
prefix?: React.ReactNode;
|
|
54
|
+
suffix?: React.ReactNode;
|
|
55
|
+
defaultValue?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface SelectOption {
|
|
58
|
+
value: string;
|
|
59
|
+
label: string;
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface SelectOptionGroup {
|
|
63
|
+
group: string;
|
|
64
|
+
options: SelectOption[];
|
|
65
|
+
}
|
|
66
|
+
export interface SelectField extends BaseField {
|
|
67
|
+
type: "select";
|
|
68
|
+
options: (SelectOption | SelectOptionGroup)[];
|
|
69
|
+
native?: boolean;
|
|
70
|
+
defaultValue?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface TextareaField extends BaseField {
|
|
73
|
+
type: "textarea";
|
|
74
|
+
rows?: number;
|
|
75
|
+
icon?: React.ComponentType<{
|
|
76
|
+
size?: number;
|
|
77
|
+
className?: string;
|
|
78
|
+
}>;
|
|
79
|
+
iconPosition?: "left" | "right";
|
|
80
|
+
defaultValue?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface ToggleField extends BaseField {
|
|
83
|
+
type: "toggle";
|
|
84
|
+
description?: string;
|
|
85
|
+
labelPosition?: "left" | "right";
|
|
86
|
+
defaultValue?: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface CheckboxField extends BaseField {
|
|
89
|
+
type: "checkbox";
|
|
90
|
+
description?: string;
|
|
91
|
+
labelPosition?: "left" | "right";
|
|
92
|
+
defaultValue?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export interface RadioOption {
|
|
95
|
+
value: string;
|
|
96
|
+
label: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
}
|
|
100
|
+
export interface RadioField extends BaseField {
|
|
101
|
+
type: "radio";
|
|
102
|
+
options: RadioOption[];
|
|
103
|
+
defaultValue?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface SliderField extends BaseField {
|
|
106
|
+
type: "slider";
|
|
107
|
+
min?: number;
|
|
108
|
+
max?: number;
|
|
109
|
+
step?: number;
|
|
110
|
+
renderValue?: (value: number) => string;
|
|
111
|
+
defaultValue?: number[];
|
|
112
|
+
}
|
|
113
|
+
export interface RowField {
|
|
114
|
+
type: "row";
|
|
115
|
+
/** Fields displayed side by side in a grid row. */
|
|
116
|
+
fields: EasyFormField[];
|
|
117
|
+
}
|
|
118
|
+
export type EasyFormField = TextField | SelectField | TextareaField | ToggleField | CheckboxField | RadioField | SliderField | RowField;
|
|
119
|
+
export interface EasyFormProps {
|
|
120
|
+
/** Array of field configurations. */
|
|
121
|
+
fields: EasyFormField[];
|
|
122
|
+
/** Called with all form values when the form is submitted and validation passes. */
|
|
123
|
+
onSubmit?: (values: FormValues) => void;
|
|
124
|
+
/** Called whenever a field value changes. */
|
|
125
|
+
onChange?: (values: FormValues, changedField: string) => void;
|
|
126
|
+
/** Default values for the form fields. Keys are field names. */
|
|
127
|
+
defaultValues?: FormValues;
|
|
128
|
+
/** Custom submit button. If not provided, no submit button is rendered. */
|
|
129
|
+
submitButton?: React.ReactNode;
|
|
130
|
+
/** Custom reset button. Resets all fields to defaultValues. */
|
|
131
|
+
resetButton?: React.ReactNode;
|
|
132
|
+
/** Gap between fields. @default "gap-4" */
|
|
133
|
+
gap?: string;
|
|
134
|
+
/** Additional CSS classes for the form element. */
|
|
135
|
+
className?: string;
|
|
136
|
+
}
|
|
137
|
+
declare const EasyForm: React.ForwardRefExoticComponent<EasyFormProps & React.RefAttributes<HTMLFormElement>>;
|
|
138
|
+
export { EasyForm };
|
package/dist/EasyForm.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as L, jsx as o } from "react/jsx-runtime";
|
|
3
|
+
import * as T from "react";
|
|
4
|
+
import { useState as N, useRef as _, useCallback as w } from "react";
|
|
5
|
+
import { Slider as z, RadioGroup as H, RadioGroupItem as J, Checkbox as K, Toggle as Q, Textarea as U, Select as $, SelectGroup as W, SelectItem as R, Input as X } from "./Input.js";
|
|
6
|
+
import { c as C } from "./_shared/utils-eGXXUFl7.js";
|
|
7
|
+
function V(e) {
|
|
8
|
+
return "group" in e;
|
|
9
|
+
}
|
|
10
|
+
function Y(e) {
|
|
11
|
+
if (e.type !== "row") {
|
|
12
|
+
if ("defaultValue" in e && e.defaultValue !== void 0) return e.defaultValue;
|
|
13
|
+
switch (e.type) {
|
|
14
|
+
case "toggle":
|
|
15
|
+
case "checkbox":
|
|
16
|
+
return !1;
|
|
17
|
+
case "slider":
|
|
18
|
+
return [e.min ?? 0];
|
|
19
|
+
case "number":
|
|
20
|
+
return "";
|
|
21
|
+
default:
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function y(e) {
|
|
27
|
+
const n = [];
|
|
28
|
+
for (const c of e)
|
|
29
|
+
c.type === "row" ? n.push(...y(c.fields)) : n.push(c);
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
function G(e, n) {
|
|
33
|
+
const c = {};
|
|
34
|
+
for (const t of y(e)) {
|
|
35
|
+
const i = t.name;
|
|
36
|
+
c[i] = n?.[i] !== void 0 ? n[i] : Y(t);
|
|
37
|
+
}
|
|
38
|
+
return c;
|
|
39
|
+
}
|
|
40
|
+
function h(e) {
|
|
41
|
+
return typeof e == "object" && e !== null && "value" in e ? e.value : e;
|
|
42
|
+
}
|
|
43
|
+
function g(e, n) {
|
|
44
|
+
return typeof e == "object" && e !== null && "message" in e ? e.message : n;
|
|
45
|
+
}
|
|
46
|
+
function M(e, n, c) {
|
|
47
|
+
const t = e.validation;
|
|
48
|
+
if (!t) return;
|
|
49
|
+
if (t.required && (n == null || n === "" || Array.isArray(n) && n.length === 0))
|
|
50
|
+
return typeof t.required == "string" ? t.required : `${e.label || e.name} est requis`;
|
|
51
|
+
const i = typeof n == "string" ? n : "", a = typeof n == "number" ? n : Number(n);
|
|
52
|
+
if (t.minLength !== void 0 && typeof n == "string") {
|
|
53
|
+
const r = h(t.minLength);
|
|
54
|
+
if (i.length < r)
|
|
55
|
+
return g(t.minLength, `Minimum ${r} caracteres`);
|
|
56
|
+
}
|
|
57
|
+
if (t.maxLength !== void 0 && typeof n == "string") {
|
|
58
|
+
const r = h(t.maxLength);
|
|
59
|
+
if (i.length > r)
|
|
60
|
+
return g(t.maxLength, `Maximum ${r} caracteres`);
|
|
61
|
+
}
|
|
62
|
+
if (t.min !== void 0) {
|
|
63
|
+
const r = h(t.min), l = Array.isArray(n) ? n[0] : a;
|
|
64
|
+
if (typeof l == "number" && l < r)
|
|
65
|
+
return g(t.min, `Minimum ${r}`);
|
|
66
|
+
}
|
|
67
|
+
if (t.max !== void 0) {
|
|
68
|
+
const r = h(t.max), l = Array.isArray(n) ? n[n.length - 1] : a;
|
|
69
|
+
if (typeof l == "number" && l > r)
|
|
70
|
+
return g(t.max, `Maximum ${r}`);
|
|
71
|
+
}
|
|
72
|
+
if (t.pattern !== void 0 && typeof n == "string" && !h(t.pattern).test(i))
|
|
73
|
+
return g(t.pattern, "Format invalide");
|
|
74
|
+
if (t.custom)
|
|
75
|
+
return t.custom(n, c);
|
|
76
|
+
}
|
|
77
|
+
function Z({ field: e, value: n, error: c, onValueChange: t }) {
|
|
78
|
+
const { name: i } = e;
|
|
79
|
+
switch (e.type) {
|
|
80
|
+
case "text":
|
|
81
|
+
case "email":
|
|
82
|
+
case "password":
|
|
83
|
+
case "number":
|
|
84
|
+
return /* @__PURE__ */ o(
|
|
85
|
+
X,
|
|
86
|
+
{
|
|
87
|
+
type: e.type,
|
|
88
|
+
label: e.label,
|
|
89
|
+
placeholder: e.placeholder,
|
|
90
|
+
disabled: e.disabled,
|
|
91
|
+
icon: e.icon,
|
|
92
|
+
iconPosition: e.iconPosition,
|
|
93
|
+
prefix: e.prefix,
|
|
94
|
+
suffix: e.suffix,
|
|
95
|
+
value: n,
|
|
96
|
+
onChange: (a) => t(i, a.target.value),
|
|
97
|
+
error: c
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
case "select": {
|
|
101
|
+
const a = e.options.some(V);
|
|
102
|
+
return e.native ? /* @__PURE__ */ o(
|
|
103
|
+
$,
|
|
104
|
+
{
|
|
105
|
+
label: e.label,
|
|
106
|
+
placeholder: e.placeholder,
|
|
107
|
+
disabled: e.disabled,
|
|
108
|
+
native: !0,
|
|
109
|
+
value: n,
|
|
110
|
+
onValueChange: (r) => t(i, r),
|
|
111
|
+
children: e.options.map(
|
|
112
|
+
(r, l) => V(r) ? /* @__PURE__ */ o("optgroup", { label: r.group, children: r.options.map((u) => /* @__PURE__ */ o("option", { value: u.value, disabled: u.disabled, children: u.label }, u.value)) }, l) : /* @__PURE__ */ o("option", { value: r.value, disabled: r.disabled, children: r.label }, r.value)
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
) : /* @__PURE__ */ o(
|
|
116
|
+
$,
|
|
117
|
+
{
|
|
118
|
+
label: e.label,
|
|
119
|
+
placeholder: e.placeholder,
|
|
120
|
+
disabled: e.disabled,
|
|
121
|
+
value: n,
|
|
122
|
+
onValueChange: (r) => t(i, r),
|
|
123
|
+
children: a ? e.options.map(
|
|
124
|
+
(r, l) => V(r) ? /* @__PURE__ */ o(W, { label: r.group, children: r.options.map((u) => /* @__PURE__ */ o(R, { value: u.value, disabled: u.disabled, children: u.label }, u.value)) }, l) : /* @__PURE__ */ o(R, { value: r.value, disabled: r.disabled, children: r.label }, r.value)
|
|
125
|
+
) : e.options.map((r) => /* @__PURE__ */ o(R, { value: r.value, disabled: r.disabled, children: r.label }, r.value))
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
case "textarea":
|
|
130
|
+
return /* @__PURE__ */ o(
|
|
131
|
+
U,
|
|
132
|
+
{
|
|
133
|
+
label: e.label,
|
|
134
|
+
placeholder: e.placeholder,
|
|
135
|
+
disabled: e.disabled,
|
|
136
|
+
rows: e.rows,
|
|
137
|
+
icon: e.icon,
|
|
138
|
+
iconPosition: e.iconPosition,
|
|
139
|
+
value: n,
|
|
140
|
+
onChange: (a) => t(i, a.target.value),
|
|
141
|
+
error: c
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
case "toggle":
|
|
145
|
+
return /* @__PURE__ */ o(
|
|
146
|
+
Q,
|
|
147
|
+
{
|
|
148
|
+
label: e.label,
|
|
149
|
+
description: e.description,
|
|
150
|
+
disabled: e.disabled,
|
|
151
|
+
labelPosition: e.labelPosition,
|
|
152
|
+
checked: n,
|
|
153
|
+
onChange: (a) => t(i, a)
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
case "checkbox":
|
|
157
|
+
return /* @__PURE__ */ o(
|
|
158
|
+
K,
|
|
159
|
+
{
|
|
160
|
+
label: e.label,
|
|
161
|
+
description: e.description,
|
|
162
|
+
disabled: e.disabled,
|
|
163
|
+
labelPosition: e.labelPosition,
|
|
164
|
+
checked: n,
|
|
165
|
+
onChange: (a) => t(i, a)
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
case "radio":
|
|
169
|
+
return /* @__PURE__ */ o(
|
|
170
|
+
H,
|
|
171
|
+
{
|
|
172
|
+
label: e.label,
|
|
173
|
+
disabled: e.disabled,
|
|
174
|
+
value: n,
|
|
175
|
+
onValueChange: (a) => t(i, a),
|
|
176
|
+
children: e.options.map((a) => /* @__PURE__ */ o(
|
|
177
|
+
J,
|
|
178
|
+
{
|
|
179
|
+
value: a.value,
|
|
180
|
+
label: a.label,
|
|
181
|
+
description: a.description,
|
|
182
|
+
disabled: a.disabled
|
|
183
|
+
},
|
|
184
|
+
a.value
|
|
185
|
+
))
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
case "slider":
|
|
189
|
+
return /* @__PURE__ */ o(
|
|
190
|
+
z,
|
|
191
|
+
{
|
|
192
|
+
label: e.label,
|
|
193
|
+
disabled: e.disabled,
|
|
194
|
+
min: e.min,
|
|
195
|
+
max: e.max,
|
|
196
|
+
step: e.step,
|
|
197
|
+
renderValue: e.renderValue,
|
|
198
|
+
value: n,
|
|
199
|
+
onValueChange: (a) => t(i, a)
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
default:
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const ae = T.forwardRef(function({
|
|
207
|
+
fields: n,
|
|
208
|
+
onSubmit: c,
|
|
209
|
+
onChange: t,
|
|
210
|
+
defaultValues: i,
|
|
211
|
+
submitButton: a,
|
|
212
|
+
resetButton: r,
|
|
213
|
+
gap: l = "gap-4",
|
|
214
|
+
className: u
|
|
215
|
+
}, q) {
|
|
216
|
+
const [p, P] = N(
|
|
217
|
+
() => G(n, i)
|
|
218
|
+
), [I, f] = N({}), v = _(!1), D = w(
|
|
219
|
+
(s, d) => {
|
|
220
|
+
P((b) => {
|
|
221
|
+
const m = { ...b, [s]: d };
|
|
222
|
+
if (v.current) {
|
|
223
|
+
const j = y(n).find((x) => x.name === s);
|
|
224
|
+
if (j) {
|
|
225
|
+
const x = M(j, d, m);
|
|
226
|
+
f((A) => {
|
|
227
|
+
if (x) return { ...A, [s]: x };
|
|
228
|
+
const { [s]: B, ...O } = A;
|
|
229
|
+
return O;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return t?.(m, s), m;
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
[n, t]
|
|
237
|
+
), E = w(
|
|
238
|
+
(s) => {
|
|
239
|
+
s.preventDefault(), v.current = !0;
|
|
240
|
+
const d = y(n), b = {};
|
|
241
|
+
for (const m of d) {
|
|
242
|
+
const k = M(m, p[m.name], p);
|
|
243
|
+
k && (b[m.name] = k);
|
|
244
|
+
}
|
|
245
|
+
f(b), Object.keys(b).length === 0 && c?.(p);
|
|
246
|
+
},
|
|
247
|
+
[n, p, c]
|
|
248
|
+
), F = w(() => {
|
|
249
|
+
const s = G(n, i);
|
|
250
|
+
P(s), f({}), v.current = !1;
|
|
251
|
+
}, [n, i]);
|
|
252
|
+
function S(s, d) {
|
|
253
|
+
return s.type === "row" ? /* @__PURE__ */ o("div", { className: C("grid gap-4", `grid-cols-${s.fields.length}`), children: s.fields.map((b, m) => S(b, m)) }, d) : /* @__PURE__ */ o(
|
|
254
|
+
Z,
|
|
255
|
+
{
|
|
256
|
+
field: s,
|
|
257
|
+
value: p[s.name],
|
|
258
|
+
error: I[s.name],
|
|
259
|
+
onValueChange: D
|
|
260
|
+
},
|
|
261
|
+
s.name
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return /* @__PURE__ */ L(
|
|
265
|
+
"form",
|
|
266
|
+
{
|
|
267
|
+
ref: q,
|
|
268
|
+
onSubmit: E,
|
|
269
|
+
onReset: (s) => {
|
|
270
|
+
s.preventDefault(), F();
|
|
271
|
+
},
|
|
272
|
+
className: C("flex flex-col", l, u),
|
|
273
|
+
noValidate: !0,
|
|
274
|
+
children: [
|
|
275
|
+
n.map((s, d) => S(s, d)),
|
|
276
|
+
(a || r) && /* @__PURE__ */ L("div", { className: "flex items-center justify-end gap-2 mt-2", children: [
|
|
277
|
+
r && /* @__PURE__ */ o("span", { onClick: F, className: "cursor-pointer", children: r }),
|
|
278
|
+
a && /* @__PURE__ */ o("button", { type: "submit", className: "contents", children: a })
|
|
279
|
+
] })
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
export {
|
|
285
|
+
ae as EasyForm
|
|
286
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
|
|
3
|
+
declare const HoverCard: React.FC<HoverCardPrimitive.HoverCardProps>;
|
|
4
|
+
declare const HoverCardTrigger: React.ForwardRefExoticComponent<HoverCardPrimitive.HoverCardTriggerProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
5
|
+
export interface HoverCardContentProps extends React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content> {
|
|
6
|
+
/** Portal container. @default document.body */
|
|
7
|
+
container?: HTMLElement;
|
|
8
|
+
}
|
|
9
|
+
declare const HoverCardContent: React.ForwardRefExoticComponent<HoverCardContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export { HoverCard, HoverCardTrigger, HoverCardContent };
|