@oneplatformdev/ui 0.0.1-beta.3 → 0.0.1-beta.31
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/AlertDialog/AlertDialog.d.ts +14 -0
- package/AlertDialog/AlertDialog.mjs +58 -60
- package/Button/buttonVariants.mjs +3 -3
- package/Combobox/Combobox.mjs +71 -60
- package/Combobox/Combobox.types.d.ts +7 -0
- package/Dropzone/Dropzone.d.ts +22 -0
- package/Dropzone/Dropzone.mjs +136 -0
- package/Dropzone/Dropzone.types.d.ts +36 -0
- package/Dropzone/DropzoneFilePreview.d.ts +4 -0
- package/Dropzone/DropzoneFilePreview.mjs +9 -0
- package/Dropzone/DropzoneUtils.d.ts +4 -0
- package/Dropzone/DropzoneUtils.mjs +15 -0
- package/Dropzone/index.d.ts +2 -0
- package/Dropzone/index.mjs +7 -0
- package/Dropzone/package.json +7 -0
- package/DropzoneFilePreview-Dhtv8F4u.js +67 -0
- package/FormDropzone/FormDropzone.d.ts +4 -0
- package/FormDropzone/FormDropzone.mjs +26 -0
- package/FormDropzone/FormDropzone.types.d.ts +7 -0
- package/FormDropzone/index.d.ts +2 -0
- package/FormDropzone/index.mjs +4 -0
- package/FormDropzone/package.json +7 -0
- package/FormInput/FormInput.mjs +6 -7
- package/FormSelect/FormSelect.types.d.ts +2 -1
- package/Input/Input.mjs +42 -37
- package/Input/Input.types.d.ts +3 -1
- package/Input/index.mjs +5 -8
- package/Search/Search.mjs +10 -11
- package/Sidebar/Sidebar.mjs +13 -14
- package/Tabs/Tabs.d.ts +3 -2
- package/Tabs/Tabs.mjs +20 -6
- package/Tabs/Tabs.types.d.ts +5 -2
- package/Tabs/index.mjs +8 -7
- package/index.css +1 -1
- package/index.d.ts +2 -0
- package/index.mjs +357 -352
- package/package.json +9 -8
@@ -6,6 +6,10 @@ import { FC, PropsWithChildren } from 'react';
|
|
6
6
|
* @public
|
7
7
|
* @see [Documentation](#)
|
8
8
|
* @example
|
9
|
+
* > Import:
|
10
|
+
* ```tsx
|
11
|
+
* import { AlertDialog } from '@oneplatformdev/ui/AlertDialog';
|
12
|
+
* ```
|
9
13
|
* > Simple example:
|
10
14
|
* ```tsx
|
11
15
|
* <AlertDialog
|
@@ -25,6 +29,16 @@ import { FC, PropsWithChildren } from 'react';
|
|
25
29
|
* onConfirm={(event) => console.log(event, 'Confirm')}
|
26
30
|
* />
|
27
31
|
* ```
|
32
|
+
* > Trigger example: Button with icon children
|
33
|
+
* ```tsx
|
34
|
+
* <AlertDialog
|
35
|
+
* trigger={<Button variant="outline" size="icon"><PencilLine /></Button>}
|
36
|
+
* title="Dialog title with icon trigger"
|
37
|
+
* description="Description text..."
|
38
|
+
* onCancel={(event) => console.log(event, 'Cancel')}
|
39
|
+
* onConfirm={(event) => console.log(event, 'Confirm')}
|
40
|
+
* />
|
41
|
+
* ```
|
28
42
|
*
|
29
43
|
* > Full content example:
|
30
44
|
* ```tsx
|
@@ -1,99 +1,97 @@
|
|
1
|
-
import { jsxs as
|
2
|
-
import { cloneElement as a, useId as
|
3
|
-
import { AlertDialogRoot as
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const { slotProps: e = {}, children: r } = n, o = e.trigger ?? {};
|
9
|
-
return l(r, f) ? a(
|
1
|
+
import { jsxs as g, jsx as t } from "react/jsx-runtime";
|
2
|
+
import { cloneElement as a, useId as j, Children as y } from "react";
|
3
|
+
import { AlertDialogRoot as E, AlertDialogContent as u, AlertDialogTrigger as v, AlertDialogHeader as f, AlertDialogTitle as B, AlertDialogDescription as R, AlertDialogFooter as A, AlertDialogAction as D, AlertDialogCancel as k } from "./AlertDialogRoot.mjs";
|
4
|
+
import { isValidReactElement as s } from "@oneplatformdev/utils";
|
5
|
+
const F = (o) => {
|
6
|
+
const { slotProps: e = {}, children: r } = o, i = e.trigger ?? {};
|
7
|
+
return s(r, v) ? a(
|
10
8
|
r,
|
11
9
|
{
|
12
10
|
...r.props || {},
|
13
|
-
...
|
11
|
+
...i
|
14
12
|
}
|
15
|
-
) :
|
16
|
-
},
|
13
|
+
) : /* @__PURE__ */ t(v, { asChild: !0, children: r });
|
14
|
+
}, H = (o) => {
|
17
15
|
const {
|
18
16
|
title: e = "",
|
19
17
|
description: r = "",
|
20
|
-
slotProps:
|
21
|
-
children:
|
22
|
-
} =
|
23
|
-
return
|
24
|
-
|
25
|
-
{ ...
|
26
|
-
) : /* @__PURE__ */ t(
|
27
|
-
e &&
|
18
|
+
slotProps: i = {},
|
19
|
+
children: l
|
20
|
+
} = o, n = i.header ?? {}, d = i.title ?? {}, c = i.description ?? {};
|
21
|
+
return l ? s(l, f) ? a(
|
22
|
+
l,
|
23
|
+
{ ...l.props || {}, ...n }
|
24
|
+
) : /* @__PURE__ */ t(f, { ...n, children: l }) : /* @__PURE__ */ g(f, { children: [
|
25
|
+
e && s(e, B) ? a(
|
28
26
|
e,
|
29
27
|
{ ...e.props || {}, ...d }
|
30
28
|
) : /* @__PURE__ */ t(B, { ...d, children: e }),
|
31
|
-
r &&
|
29
|
+
r && s(r, R) ? a(
|
32
30
|
r,
|
33
|
-
{ ...r.props || {}, ...
|
34
|
-
) : /* @__PURE__ */ t(R, { ...
|
31
|
+
{ ...r.props || {}, ...c }
|
32
|
+
) : /* @__PURE__ */ t(R, { ...c, children: r })
|
35
33
|
] });
|
36
|
-
},
|
34
|
+
}, I = (o) => {
|
37
35
|
const {
|
38
36
|
slotProps: e = {},
|
39
37
|
children: r,
|
40
|
-
onCancel:
|
41
|
-
onConfirm:
|
42
|
-
cancelLabel:
|
38
|
+
onCancel: i,
|
39
|
+
onConfirm: l,
|
40
|
+
cancelLabel: n = "Cancel",
|
43
41
|
actionLabel: d = "Continue",
|
44
|
-
variant:
|
45
|
-
} =
|
46
|
-
return r ?
|
42
|
+
variant: c = "confirm"
|
43
|
+
} = o, x = j(), m = e.footer ?? {}, T = e.cancelButton ?? {}, C = e.actionButton ?? {};
|
44
|
+
return r ? s(r, A) ? a(
|
47
45
|
r,
|
48
|
-
{ ...r.props || {}, ...
|
49
|
-
) : /* @__PURE__ */ t(A, { ...
|
50
|
-
if (!p || !
|
51
|
-
const
|
52
|
-
return
|
53
|
-
}) }) : /* @__PURE__ */
|
54
|
-
|
46
|
+
{ ...r.props || {}, ...m }
|
47
|
+
) : /* @__PURE__ */ t(A, { ...m, children: y.map(r, (p, b) => {
|
48
|
+
if (!p || !s(p)) return;
|
49
|
+
const h = p, P = a(h, { ...h.props || {}, key: h.key || `footer-${x}-action-${b}` });
|
50
|
+
return s(p, D) || s(p, k) ? P : /* @__PURE__ */ t(D, { asChild: !0, children: P });
|
51
|
+
}) }) : /* @__PURE__ */ g(A, { children: [
|
52
|
+
c !== "alert" && /* @__PURE__ */ t(
|
55
53
|
k,
|
56
54
|
{
|
57
55
|
variant: "ghost",
|
58
|
-
onClick:
|
59
|
-
...
|
60
|
-
children:
|
56
|
+
onClick: i,
|
57
|
+
...T,
|
58
|
+
children: n
|
61
59
|
}
|
62
60
|
),
|
63
61
|
/* @__PURE__ */ t(
|
64
|
-
|
62
|
+
D,
|
65
63
|
{
|
66
|
-
onClick:
|
67
|
-
...
|
68
|
-
variant:
|
64
|
+
onClick: l,
|
65
|
+
...C,
|
66
|
+
variant: C.variant || c === "destructive" ? "destructive" : "default",
|
69
67
|
children: d
|
70
68
|
}
|
71
69
|
)
|
72
70
|
] });
|
73
|
-
},
|
71
|
+
}, w = (o) => {
|
74
72
|
const {
|
75
73
|
trigger: e,
|
76
74
|
header: r,
|
77
|
-
footer:
|
78
|
-
slotProps:
|
79
|
-
children:
|
75
|
+
footer: i,
|
76
|
+
slotProps: l = {},
|
77
|
+
children: n,
|
80
78
|
...d
|
81
|
-
} =
|
82
|
-
return /* @__PURE__ */
|
83
|
-
/* @__PURE__ */ t(
|
84
|
-
|
85
|
-
|
79
|
+
} = o, c = l.content ?? {};
|
80
|
+
return /* @__PURE__ */ g(E, { ...d, children: [
|
81
|
+
/* @__PURE__ */ t(F, { ...o, children: e }),
|
82
|
+
n ? s(n, u) ? a(
|
83
|
+
n,
|
86
84
|
{
|
87
|
-
...
|
88
|
-
...
|
85
|
+
...n.props || {},
|
86
|
+
...c
|
89
87
|
}
|
90
|
-
) : /* @__PURE__ */ t(
|
91
|
-
/* @__PURE__ */ t(
|
92
|
-
/* @__PURE__ */ t(
|
88
|
+
) : /* @__PURE__ */ t(u, { ...c, children: n }) : /* @__PURE__ */ g(u, { ...c, children: [
|
89
|
+
/* @__PURE__ */ t(H, { ...o, children: r }),
|
90
|
+
/* @__PURE__ */ t(I, { ...o, children: i })
|
93
91
|
] })
|
94
92
|
] });
|
95
93
|
};
|
96
94
|
export {
|
97
|
-
|
98
|
-
|
95
|
+
w as AlertDialog,
|
96
|
+
w as default
|
99
97
|
};
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { cva as e } from "class-variance-authority";
|
2
|
-
const
|
2
|
+
const r = e(
|
3
3
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
|
4
4
|
{
|
5
5
|
variants: {
|
6
6
|
variant: {
|
7
|
-
default: "bg-primary text-primary-foreground shadow hover:
|
7
|
+
default: "bg-primary text-primary-foreground shadow hover:opacity-[.8]",
|
8
8
|
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
9
9
|
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
10
10
|
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
@@ -25,5 +25,5 @@ const t = e(
|
|
25
25
|
}
|
26
26
|
);
|
27
27
|
export {
|
28
|
-
|
28
|
+
r as buttonVariants
|
29
29
|
};
|
package/Combobox/Combobox.mjs
CHANGED
@@ -1,109 +1,120 @@
|
|
1
1
|
import { jsx as a, jsxs as t } from "react/jsx-runtime";
|
2
|
-
import n, { useEffect as
|
3
|
-
import { LoadingMask as
|
4
|
-
import { Popover as
|
5
|
-
import { Button as
|
2
|
+
import n, { useRef as U, useEffect as w, useCallback as x } from "react";
|
3
|
+
import { LoadingMask as _ } from "../LoadingMask/LoadingMask.mjs";
|
4
|
+
import { Popover as B, PopoverTrigger as F, PopoverContent as V } from "../Popover/Popover.mjs";
|
5
|
+
import { Button as X } from "../Button/Button.mjs";
|
6
6
|
import "../Button/buttonVariants.mjs";
|
7
|
-
import { Command as
|
8
|
-
import { cn as
|
9
|
-
import { useDebounceCallback as
|
10
|
-
import { X as
|
11
|
-
const
|
12
|
-
var
|
7
|
+
import { Command as q, CommandInput as z, CommandList as A, CommandEmpty as H, CommandGroup as J, CommandItem as K } from "../Command/Command.mjs";
|
8
|
+
import { cn as N } from "@oneplatformdev/utils";
|
9
|
+
import { useDebounceCallback as Q } from "@oneplatformdev/hooks";
|
10
|
+
import { X as W, ChevronsUpDown as Y, Check as Z } from "lucide-react";
|
11
|
+
const ie = (S) => {
|
12
|
+
var y;
|
13
13
|
const {
|
14
14
|
value: o,
|
15
|
-
onChange:
|
16
|
-
placeholder:
|
17
|
-
disabled:
|
18
|
-
searchLabel:
|
19
|
-
fetchOptions:
|
15
|
+
onChange: k,
|
16
|
+
placeholder: L,
|
17
|
+
disabled: O,
|
18
|
+
searchLabel: P,
|
19
|
+
fetchOptions: j,
|
20
20
|
options: r,
|
21
|
-
emptyLabel:
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
emptyLabel: D = "No options",
|
22
|
+
onMount: u
|
23
|
+
} = S, s = U(!1), [l, p] = n.useState(!1), [M, h] = n.useState(""), [f, c] = n.useState([]), [i, b] = n.useState(), [v, C] = n.useState(!1);
|
24
|
+
w(() => {
|
25
|
+
r != null && r.length && c(r);
|
25
26
|
}, [r]);
|
26
|
-
const
|
27
|
-
l || (
|
28
|
-
},
|
29
|
-
|
27
|
+
const T = async () => {
|
28
|
+
l || (g(), h(""));
|
29
|
+
}, g = x(async (e) => {
|
30
|
+
C(!0);
|
30
31
|
try {
|
31
|
-
const
|
32
|
-
|
33
|
-
} catch (
|
34
|
-
console.error("Unexpected error while get option:",
|
32
|
+
const m = await j(e);
|
33
|
+
c(m);
|
34
|
+
} catch (m) {
|
35
|
+
console.error("Unexpected error while get option:", m);
|
35
36
|
} finally {
|
36
|
-
|
37
|
+
C(!1);
|
37
38
|
}
|
38
|
-
},
|
39
|
-
|
40
|
-
},
|
41
|
-
|
42
|
-
},
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
|
39
|
+
}, []), E = Q(g, 1e3, { leading: !1, trailing: !0 }), G = (e) => {
|
40
|
+
h(e), E(e);
|
41
|
+
}, d = (e) => {
|
42
|
+
k(e.value), b(e);
|
43
|
+
}, I = () => {
|
44
|
+
d({ value: "", label: "" }), b(void 0);
|
45
|
+
}, R = x(() => {
|
46
|
+
if (!u) {
|
47
|
+
s.current = !0;
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
u({ setOptions: c }).finally(() => {
|
51
|
+
s.current = !0;
|
52
|
+
});
|
53
|
+
}, []);
|
54
|
+
return w(() => (R(), () => {
|
55
|
+
s.current = !1;
|
56
|
+
}), []), /* @__PURE__ */ a("div", { className: "w-full", children: /* @__PURE__ */ t(
|
57
|
+
B,
|
47
58
|
{
|
48
59
|
open: l,
|
49
60
|
onOpenChange: (e) => {
|
50
|
-
|
61
|
+
p(e), e && T();
|
51
62
|
},
|
52
63
|
children: [
|
53
|
-
/* @__PURE__ */ a(
|
54
|
-
|
64
|
+
/* @__PURE__ */ a(F, { asChild: !0, className: "border-border", children: /* @__PURE__ */ t(
|
65
|
+
X,
|
55
66
|
{
|
56
67
|
variant: "outline",
|
57
68
|
role: "combobox",
|
58
69
|
"aria-expanded": l,
|
59
|
-
className:
|
70
|
+
className: N(
|
60
71
|
"w-full justify-between font-normal text-sm border bg-input",
|
61
72
|
l ? "border-2 border-sidebar-accent" : "border-border"
|
62
73
|
),
|
63
|
-
disabled:
|
74
|
+
disabled: O,
|
64
75
|
children: [
|
65
|
-
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((
|
76
|
+
/* @__PURE__ */ a("span", { className: "truncate max-w-[calc(100%-1.5rem)] overflow-hidden whitespace-nowrap", children: o ? ((y = f.find((e) => e.value === o)) == null ? void 0 : y.label) || (i == null ? void 0 : i.label) : /* @__PURE__ */ a("span", { className: "text-gray-400", children: L }) }),
|
66
77
|
o ? /* @__PURE__ */ a(
|
67
|
-
|
78
|
+
W,
|
68
79
|
{
|
69
80
|
className: "opacity-50 w-4 h-4 cursor-pointer hover:opacity-100",
|
70
81
|
onClick: (e) => {
|
71
|
-
e.stopPropagation(),
|
82
|
+
e.stopPropagation(), I();
|
72
83
|
}
|
73
84
|
}
|
74
|
-
) : /* @__PURE__ */ a(
|
85
|
+
) : /* @__PURE__ */ a(Y, { className: "opacity-50 w-4 h-4" })
|
75
86
|
]
|
76
87
|
}
|
77
88
|
) }),
|
78
89
|
/* @__PURE__ */ a(
|
79
|
-
|
90
|
+
V,
|
80
91
|
{
|
81
92
|
className: "w-[var(--radix-popper-anchor-width)] max-w-none p-0",
|
82
93
|
align: "start",
|
83
|
-
children: /* @__PURE__ */ t(
|
94
|
+
children: /* @__PURE__ */ t(q, { shouldFilter: !1, children: [
|
84
95
|
/* @__PURE__ */ a(
|
85
|
-
|
96
|
+
z,
|
86
97
|
{
|
87
|
-
placeholder:
|
88
|
-
value:
|
89
|
-
onValueChange:
|
98
|
+
placeholder: P,
|
99
|
+
value: M,
|
100
|
+
onValueChange: G
|
90
101
|
}
|
91
102
|
),
|
92
|
-
/* @__PURE__ */ t(
|
93
|
-
!
|
94
|
-
/* @__PURE__ */ a(
|
95
|
-
|
103
|
+
/* @__PURE__ */ t(A, { children: [
|
104
|
+
!v && /* @__PURE__ */ a(H, { children: D }),
|
105
|
+
/* @__PURE__ */ a(J, { children: v ? /* @__PURE__ */ a("div", { className: "flex justify-center", children: /* @__PURE__ */ a(_, {}) }) : f.map((e) => /* @__PURE__ */ t(
|
106
|
+
K,
|
96
107
|
{
|
97
108
|
value: e.value,
|
98
109
|
onSelect: () => {
|
99
|
-
o === e.value ?
|
110
|
+
o === e.value ? d({ value: "", label: "" }) : d(e), p(!1);
|
100
111
|
},
|
101
112
|
children: [
|
102
113
|
e.label,
|
103
114
|
/* @__PURE__ */ a(
|
104
|
-
|
115
|
+
Z,
|
105
116
|
{
|
106
|
-
className:
|
117
|
+
className: N(
|
107
118
|
"ml-auto",
|
108
119
|
o === e.value ? "opacity-100" : "opacity-0"
|
109
120
|
)
|
@@ -122,5 +133,5 @@ const te = (w) => {
|
|
122
133
|
) });
|
123
134
|
};
|
124
135
|
export {
|
125
|
-
|
136
|
+
ie as Combobox
|
126
137
|
};
|
@@ -1,7 +1,12 @@
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
2
|
+
|
1
3
|
export interface ComboboxOption {
|
2
4
|
value: string;
|
3
5
|
label: string;
|
4
6
|
}
|
7
|
+
export interface ComboboxPropsOnMountParams {
|
8
|
+
setOptions: Dispatch<SetStateAction<ComboboxOption[]>>;
|
9
|
+
}
|
5
10
|
export interface ComboboxProps {
|
6
11
|
value: string;
|
7
12
|
onChange: (value: string) => void;
|
@@ -12,4 +17,6 @@ export interface ComboboxProps {
|
|
12
17
|
options?: ComboboxOption[];
|
13
18
|
/** CommandEmpty label*/
|
14
19
|
emptyLabel?: string;
|
20
|
+
/** Callback for load data on start component */
|
21
|
+
onMount?: (params: ComboboxPropsOnMountParams) => Promise<ComboboxOption[]>;
|
15
22
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { DropzoneProps } from './Dropzone.types';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Dropzone component - A drag-and-drop file upload area with image previews, error handling, and localization.
|
5
|
+
*
|
6
|
+
* @component
|
7
|
+
* @param {DropzoneProps} props - The props for the Dropzone component.
|
8
|
+
* @param {string[]} [props.acceptTypes=DEFAULT_FILE_TYPES] - Allowed file MIME types.
|
9
|
+
* @param {number} props.maxSizeMB - Maximum allowed file size in megabytes.
|
10
|
+
* @param {number} [props.maxFiles=1] - Maximum number of files that can be uploaded.
|
11
|
+
* @param {DropzoneTranslations} props.translations - Translations for text labels.
|
12
|
+
* @param {(errors: FileRejection[]) => void} [props.onErrors] - Callback triggered when file errors occur.
|
13
|
+
* @param {boolean} [props.hideErrors=false] - Whether to hide error messages.
|
14
|
+
* @param {boolean} [props.disabled=false] - Whether the dropzone is disabled.
|
15
|
+
* @param {DropzoneStyles} [props.classNames] - Custom classNames for different dropzone states.
|
16
|
+
* @param {DropzoneValueItem[]} [props.value=[]] - Current selected files or URLs.
|
17
|
+
* @param {(items: DropzoneValueItem[]) => void} [props.onChangeValue] - Callback triggered when file selection changes.
|
18
|
+
* @param {string} [props.className] - Additional class names for styling.
|
19
|
+
* @param {React.Ref<HTMLDivElement>} ref - Ref for the root dropzone container.
|
20
|
+
* @returns {JSX.Element} The rendered Dropzone component.
|
21
|
+
*/
|
22
|
+
export declare const Dropzone: import('react').ForwardRefExoticComponent<DropzoneProps & import('react').RefAttributes<HTMLDivElement>>;
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import { jsxs as t, jsx as o } from "react/jsx-runtime";
|
2
|
+
import { forwardRef as L, useState as g } from "react";
|
3
|
+
import { useDropzone as M } from "react-dropzone";
|
4
|
+
import { Card as U } from "../Card/Card.mjs";
|
5
|
+
import { File as j, X as O } from "lucide-react";
|
6
|
+
import { cn as m } from "@oneplatformdev/utils";
|
7
|
+
import { F as X, D as Y } from "../DropzoneFilePreview-Dhtv8F4u.js";
|
8
|
+
import { isFile as v, extractName as q } from "./DropzoneUtils.mjs";
|
9
|
+
const G = L(
|
10
|
+
({
|
11
|
+
acceptTypes: y = Y,
|
12
|
+
maxSizeMB: w,
|
13
|
+
maxFiles: a = 1,
|
14
|
+
onErrors: x,
|
15
|
+
hideErrors: b = !1,
|
16
|
+
disabled: p = !1,
|
17
|
+
classNames: l,
|
18
|
+
value: u = [],
|
19
|
+
onChangeValue: s,
|
20
|
+
className: F,
|
21
|
+
labelDropzonePrompt: z = "Drop files here or click to select",
|
22
|
+
labelOrClickToSelect: H = "Click to select files",
|
23
|
+
labelSelectedFiles: D = "Selected Files",
|
24
|
+
labelUploadErrors: I = "Upload Errors",
|
25
|
+
labelFileTooLarge: k = "File is too large",
|
26
|
+
labelInvalidFileType: S = "Invalid file type",
|
27
|
+
...E
|
28
|
+
}, P) => {
|
29
|
+
const [c, h] = g(u), [d, N] = g([]), W = (e, i) => {
|
30
|
+
N(i), x && x(i);
|
31
|
+
const r = [...c, ...e].slice(0, a);
|
32
|
+
h(r), s == null || s(r);
|
33
|
+
}, T = (e, i) => {
|
34
|
+
if (p) return;
|
35
|
+
e.stopPropagation();
|
36
|
+
const r = c.filter((n, f) => f !== i);
|
37
|
+
h(r), s == null || s(r);
|
38
|
+
}, { getRootProps: _, getInputProps: A, isDragActive: B } = M({
|
39
|
+
onDrop: W,
|
40
|
+
accept: y.reduce((e, i) => (e[i] = [], e), {}),
|
41
|
+
maxSize: w * 1024 * 1024,
|
42
|
+
maxFiles: a,
|
43
|
+
disabled: p
|
44
|
+
});
|
45
|
+
return /* @__PURE__ */ t(
|
46
|
+
U,
|
47
|
+
{
|
48
|
+
..._(),
|
49
|
+
...E,
|
50
|
+
className: m(
|
51
|
+
"border-dashed border-2 p-6 text-center flex flex-col items-center justify-center",
|
52
|
+
p && "bg-gray-300 pointer-events-none",
|
53
|
+
d.length > 0 ? "border-red-500" : "border-gray-300",
|
54
|
+
B && "bg-gray-100",
|
55
|
+
F
|
56
|
+
),
|
57
|
+
ref: P,
|
58
|
+
children: [
|
59
|
+
/* @__PURE__ */ o("input", { ...A() }),
|
60
|
+
c.length === 0 && d.length === 0 && /* @__PURE__ */ t(
|
61
|
+
"div",
|
62
|
+
{
|
63
|
+
className: m(
|
64
|
+
"flex flex-col items-center gap-1",
|
65
|
+
l == null ? void 0 : l.idleWrapper
|
66
|
+
),
|
67
|
+
children: [
|
68
|
+
/* @__PURE__ */ o(j, { className: "w-8 h-8 text-gray-500" }),
|
69
|
+
!p && /* @__PURE__ */ o("pre", { className: "font-semibold text-gray-600", children: z })
|
70
|
+
]
|
71
|
+
}
|
72
|
+
),
|
73
|
+
c.length > 0 && /* @__PURE__ */ t("div", { className: m("w-full mt-2", l == null ? void 0 : l.previewWrapper), children: [
|
74
|
+
/* @__PURE__ */ t("pre", { className: "font-semibold text-gray-600", children: [
|
75
|
+
D,
|
76
|
+
":"
|
77
|
+
] }),
|
78
|
+
/* @__PURE__ */ o("ul", { className: "mt-2 text-sm text-gray-500 flex flex-wrap gap-4 items-start justify-center", children: c.map((e, i) => {
|
79
|
+
const r = v(e) ? e.name : q(e), n = v(e) ? (e.size / (1024 * 1024)).toFixed(2) + " MB" : "";
|
80
|
+
return /* @__PURE__ */ t(
|
81
|
+
"li",
|
82
|
+
{
|
83
|
+
className: "flex flex-col items-center gap-2 relative",
|
84
|
+
children: [
|
85
|
+
/* @__PURE__ */ t("div", { className: "relative", children: [
|
86
|
+
/* @__PURE__ */ o(X, { item: e, styles: l }),
|
87
|
+
/* @__PURE__ */ o("div", { className: "absolute top-0 right-0 cursor-pointer bg-gray-300 rounded-sm", children: /* @__PURE__ */ o(
|
88
|
+
O,
|
89
|
+
{
|
90
|
+
size: 16,
|
91
|
+
strokeWidth: 1,
|
92
|
+
color: "black",
|
93
|
+
onClick: (f) => T(f, i)
|
94
|
+
}
|
95
|
+
) })
|
96
|
+
] }),
|
97
|
+
/* @__PURE__ */ t("span", { className: "inline-flex flex-col items-center", children: [
|
98
|
+
/* @__PURE__ */ o("span", { className: "max-w-[80px] text-ellipsis overflow-hidden whitespace-nowrap", children: r }),
|
99
|
+
n && /* @__PURE__ */ t("span", { children: [
|
100
|
+
"(",
|
101
|
+
n,
|
102
|
+
")"
|
103
|
+
] })
|
104
|
+
] })
|
105
|
+
]
|
106
|
+
},
|
107
|
+
i
|
108
|
+
);
|
109
|
+
}) })
|
110
|
+
] }),
|
111
|
+
d.length > 0 && /* @__PURE__ */ t("div", { className: m("w-full mt-4", l == null ? void 0 : l.errorWrapper), children: [
|
112
|
+
/* @__PURE__ */ t("span", { className: "font-semibold text-red-500", children: [
|
113
|
+
I,
|
114
|
+
":"
|
115
|
+
] }),
|
116
|
+
/* @__PURE__ */ o("ul", { className: "mt-2 text-sm text-red-500 list-disc list-inside", children: d.map((e, i) => /* @__PURE__ */ t("li", { children: [
|
117
|
+
e.file.name,
|
118
|
+
" (",
|
119
|
+
(e.file.size / (1024 * 1024)).toFixed(2),
|
120
|
+
" MB)",
|
121
|
+
!b && /* @__PURE__ */ o("ul", { className: "ml-4 list-disc list-inside", children: e.errors.map((r, n) => /* @__PURE__ */ t("li", { children: [
|
122
|
+
r.code === "file-too-large" && k,
|
123
|
+
r.code === "file-invalid-type" && S,
|
124
|
+
r.code !== "file-too-large" && r.code !== "file-invalid-type" && r.message
|
125
|
+
] }, n)) })
|
126
|
+
] }, i)) })
|
127
|
+
] })
|
128
|
+
]
|
129
|
+
}
|
130
|
+
);
|
131
|
+
}
|
132
|
+
);
|
133
|
+
G.displayName = "Dropzone";
|
134
|
+
export {
|
135
|
+
G as Dropzone
|
136
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { FileRejection } from 'react-dropzone';
|
2
|
+
|
3
|
+
export type DropzoneValueItem = File | string;
|
4
|
+
export interface FilePreviewProps {
|
5
|
+
item: DropzoneValueItem;
|
6
|
+
styles?: Pick<DropzoneStyles, 'previewWraper' | 'previewImage' | 'previewFile'>;
|
7
|
+
}
|
8
|
+
export interface DropzoneTranslations {
|
9
|
+
labelDropzonePrompt?: string;
|
10
|
+
labelOrClickToSelect?: string;
|
11
|
+
labelSelectedFiles?: string;
|
12
|
+
labelUploadErrors?: string;
|
13
|
+
labelFileTooLarge?: string;
|
14
|
+
labelInvalidFileType?: string;
|
15
|
+
}
|
16
|
+
export interface DropzoneProps extends DropzoneTranslations, React.HTMLAttributes<HTMLDivElement> {
|
17
|
+
acceptTypes?: string[];
|
18
|
+
maxSizeMB: number;
|
19
|
+
maxFiles?: number;
|
20
|
+
onErrors?: (errors: FileRejection[]) => void;
|
21
|
+
hideErrors?: boolean;
|
22
|
+
disabled?: boolean;
|
23
|
+
classNames?: DropzoneStyles;
|
24
|
+
value?: DropzoneValueItem[];
|
25
|
+
onChangeValue?: (items: DropzoneValueItem[]) => void;
|
26
|
+
}
|
27
|
+
export interface DropzoneStyles {
|
28
|
+
idleWrapper?: string;
|
29
|
+
previewWrapper?: string;
|
30
|
+
errorWrapper?: string;
|
31
|
+
previewWraper?: string;
|
32
|
+
previewImage?: string;
|
33
|
+
previewFile?: string;
|
34
|
+
}
|
35
|
+
export declare const DEFAULT_FILE_TYPES: string[];
|
36
|
+
export declare const DEFAULT_IMAGES_TYPES: string[];
|