@tedi-design-system/react 14.4.0-rc.9 → 15.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle-stats.html +1 -1
- package/community.cjs.js +1 -1
- package/community.es.js +221 -223
- package/index.css +1 -1
- package/package.json +1 -1
- package/src/community/components/layout/footer/footer.cjs.js +1 -1
- package/src/community/components/layout/footer/footer.es.js +9 -9
- package/src/community/components/layout/header/components/header-role/header-role.cjs.js +1 -1
- package/src/community/components/layout/header/components/header-role/header-role.es.js +1 -1
- package/src/community/components/layout/sidenav/sidenav.cjs.js +1 -1
- package/src/community/components/layout/sidenav/sidenav.es.js +6 -6
- package/src/community/index.d.ts +0 -1
- package/src/tedi/components/buttons/collapse/collapse.cjs.js +1 -1
- package/src/tedi/components/buttons/collapse/collapse.d.ts +5 -0
- package/src/tedi/components/buttons/collapse/collapse.es.js +60 -60
- package/src/tedi/components/form/file-upload/file-upload.cjs.js +1 -1
- package/src/tedi/components/form/file-upload/file-upload.es.js +109 -90
- package/src/tedi/components/form/file-upload/file-upload.module.scss.cjs.js +1 -1
- package/src/tedi/components/form/file-upload/file-upload.module.scss.es.js +3 -1
- package/src/tedi/components/form/radio/radio.cjs.js +1 -1
- package/src/tedi/components/form/radio/radio.es.js +42 -41
- package/src/tedi/components/layout/sidenav/components/sidenav-dropdown/sidenav-dropdown.cjs.js +1 -1
- package/src/tedi/components/layout/sidenav/components/sidenav-dropdown/sidenav-dropdown.es.js +58 -45
- package/src/tedi/components/layout/sidenav/components/sidenav-item/sidenav-item.cjs.js +1 -1
- package/src/tedi/components/layout/sidenav/components/sidenav-item/sidenav-item.es.js +126 -104
- package/src/tedi/components/layout/sidenav/components/sidenav-toggle/sidenav-toggle.cjs.js +1 -1
- package/src/tedi/components/layout/sidenav/components/sidenav-toggle/sidenav-toggle.d.ts +1 -1
- package/src/tedi/components/layout/sidenav/components/sidenav-toggle/sidenav-toggle.es.js +20 -17
- package/src/tedi/components/layout/sidenav/sidenav.d.ts +1 -9
- package/src/tedi/helpers/hooks/use-file-upload.cjs.js +1 -1
- package/src/tedi/helpers/hooks/use-file-upload.d.ts +6 -0
- package/src/tedi/helpers/hooks/use-file-upload.es.js +67 -50
- package/src/tedi/providers/label-provider/labels-map.cjs.js +1 -1
- package/src/tedi/providers/label-provider/labels-map.d.ts +44 -0
- package/src/tedi/providers/label-provider/labels-map.es.js +37 -2
- package/src/community/components/collapse/collapse.cjs.js +0 -1
- package/src/community/components/collapse/collapse.d.ts +0 -56
- package/src/community/components/collapse/collapse.es.js +0 -67
- package/src/community/components/collapse/collapse.module.scss.cjs.js +0 -1
- package/src/community/components/collapse/collapse.module.scss.es.js +0 -12
|
@@ -1,159 +1,181 @@
|
|
|
1
|
-
import { jsx as s, jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Icon as
|
|
5
|
-
import { Collapse as
|
|
6
|
-
import { Link as
|
|
1
|
+
import { jsx as s, jsxs as l, Fragment as M } from "react/jsx-runtime";
|
|
2
|
+
import Q, { useState as O, createElement as R } from "react";
|
|
3
|
+
import o from "../../../../../../../external/classnames/index.es.js";
|
|
4
|
+
import { Icon as P } from "../../../../base/icon/icon.es.js";
|
|
5
|
+
import { Collapse as B } from "../../../../buttons/collapse/collapse.es.js";
|
|
6
|
+
import { Link as w } from "../../../../navigation/link/link.es.js";
|
|
7
7
|
import e from "../../sidenav.module.scss.es.js";
|
|
8
|
-
import { SideNavDropdown as
|
|
9
|
-
import { Tooltip as
|
|
10
|
-
|
|
8
|
+
import { SideNavDropdown as U } from "../sidenav-dropdown/sidenav-dropdown.es.js";
|
|
9
|
+
import { Tooltip as f } from "../../../../overlays/tooltip/tooltip.es.js";
|
|
10
|
+
import { useLabels as V } from "../../../../../providers/label-provider/use-labels.es.js";
|
|
11
|
+
const X = (j) => {
|
|
11
12
|
const {
|
|
12
|
-
icon:
|
|
13
|
-
children:
|
|
14
|
-
isActive:
|
|
15
|
-
onClick:
|
|
16
|
-
subItems:
|
|
17
|
-
subItemGroups:
|
|
18
|
-
as:
|
|
19
|
-
onItemClick:
|
|
20
|
-
className:
|
|
21
|
-
level:
|
|
22
|
-
isCollapsed:
|
|
23
|
-
isDefaultOpen:
|
|
24
|
-
sideNavItemSize:
|
|
25
|
-
...
|
|
26
|
-
} =
|
|
13
|
+
icon: i,
|
|
14
|
+
children: n,
|
|
15
|
+
isActive: b,
|
|
16
|
+
onClick: I,
|
|
17
|
+
subItems: y,
|
|
18
|
+
subItemGroups: z,
|
|
19
|
+
as: S,
|
|
20
|
+
onItemClick: h,
|
|
21
|
+
className: H,
|
|
22
|
+
level: c = 1,
|
|
23
|
+
isCollapsed: m = !1,
|
|
24
|
+
isDefaultOpen: K = !1,
|
|
25
|
+
sideNavItemSize: $ = "default",
|
|
26
|
+
..._
|
|
27
|
+
} = j, { getLabel: T } = V(), [d, D] = O(K ?? !1), [L, A] = O(!1), u = Q.useId(), p = z ?? (y ? [{ subItems: y }] : null), r = !!p, F = o(
|
|
27
28
|
e["tedi-sidenav__item"],
|
|
28
|
-
e[`tedi-sidenav__item--${
|
|
29
|
+
e[`tedi-sidenav__item--${$}`],
|
|
29
30
|
{
|
|
30
|
-
[e[`tedi-sidenav__item--level-${
|
|
31
|
-
[e["tedi-sidenav__item--current"]]:
|
|
32
|
-
[e["tedi-sidenav__item--has-children"]]:
|
|
31
|
+
[e[`tedi-sidenav__item--level-${c}`]]: c > 1,
|
|
32
|
+
[e["tedi-sidenav__item--current"]]: b,
|
|
33
|
+
[e["tedi-sidenav__item--has-children"]]: r
|
|
33
34
|
},
|
|
34
|
-
|
|
35
|
-
),
|
|
36
|
-
const
|
|
35
|
+
H
|
|
36
|
+
), v = (a) => {
|
|
37
|
+
const t = {
|
|
37
38
|
color: "white",
|
|
38
|
-
className:
|
|
39
|
-
},
|
|
40
|
-
...
|
|
41
|
-
...
|
|
42
|
-
className:
|
|
39
|
+
className: o(e["tedi-sidenav__icon"])
|
|
40
|
+
}, N = typeof a == "string" ? { ...t, name: a } : {
|
|
41
|
+
...t,
|
|
42
|
+
...a,
|
|
43
|
+
className: o(t.className, a == null ? void 0 : a.className)
|
|
43
44
|
};
|
|
44
|
-
return /* @__PURE__ */ s(
|
|
45
|
-
}, G = (
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
}, W =
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
return /* @__PURE__ */ s(P, { ...N });
|
|
46
|
+
}, G = (a) => {
|
|
47
|
+
I == null || I(a), r || h == null || h();
|
|
48
|
+
}, k = (a) => {
|
|
49
|
+
D(a);
|
|
50
|
+
}, W = (a) => {
|
|
51
|
+
(a.key === "Enter" || a.key === " ") && (a.preventDefault(), D((g) => {
|
|
52
|
+
const t = !g;
|
|
53
|
+
return k(t), t;
|
|
54
|
+
}));
|
|
55
|
+
}, q = r && (_.href || _.to), C = {
|
|
56
|
+
..._,
|
|
57
|
+
as: S,
|
|
52
58
|
onClick: G,
|
|
53
|
-
className:
|
|
59
|
+
className: o(e["tedi-sidenav__link"], q && e["tedi-sidenav__link--has-children-link"]),
|
|
54
60
|
noStyle: !0,
|
|
55
61
|
role: "menuitem",
|
|
56
|
-
"aria-current":
|
|
57
|
-
"aria-label":
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
"aria-current": b ? "page" : void 0,
|
|
63
|
+
"aria-label": m && typeof n == "string" ? n : void 0,
|
|
64
|
+
...r ? {
|
|
65
|
+
"aria-haspopup": "true",
|
|
66
|
+
"aria-expanded": d,
|
|
67
|
+
"aria-controls": u
|
|
68
|
+
} : {}
|
|
69
|
+
}, x = () => !m && (p == null ? void 0 : p.map((a, g) => {
|
|
70
|
+
var t;
|
|
71
|
+
return /* @__PURE__ */ l("div", { children: [
|
|
72
|
+
(a == null ? void 0 : a.subHeading) && /* @__PURE__ */ s("div", { className: e["tedi-sidenav__subheading"], children: a.subHeading }),
|
|
73
|
+
/* @__PURE__ */ s("ul", { className: e["tedi-sidenav__list"], role: "menu", children: (t = a.subItems) == null ? void 0 : t.map((N, J) => /* @__PURE__ */ R(
|
|
74
|
+
X,
|
|
64
75
|
{
|
|
65
|
-
as:
|
|
66
|
-
...
|
|
67
|
-
key:
|
|
68
|
-
level:
|
|
69
|
-
onItemClick:
|
|
70
|
-
isCollapsed:
|
|
71
|
-
className:
|
|
76
|
+
as: S,
|
|
77
|
+
...N,
|
|
78
|
+
key: J,
|
|
79
|
+
level: c + 1,
|
|
80
|
+
onItemClick: h,
|
|
81
|
+
isCollapsed: m,
|
|
82
|
+
className: o(e["tedi-sidenav__sub-item"], N.className)
|
|
72
83
|
}
|
|
73
84
|
)) })
|
|
74
|
-
] },
|
|
75
|
-
})),
|
|
76
|
-
|
|
85
|
+
] }, g);
|
|
86
|
+
})), E = /* @__PURE__ */ s("li", { "data-name": "sidenav-item", className: F, children: r && m ? /* @__PURE__ */ s(
|
|
87
|
+
U,
|
|
77
88
|
{
|
|
78
|
-
trigger: /* @__PURE__ */ s(
|
|
89
|
+
trigger: /* @__PURE__ */ s(f.Trigger, { children: /* @__PURE__ */ l(
|
|
79
90
|
"span",
|
|
80
91
|
{
|
|
81
|
-
className:
|
|
92
|
+
className: o(e["tedi-sidenav__link"], L && e["tedi-sidenav__link--active"]),
|
|
82
93
|
children: [
|
|
83
|
-
|
|
94
|
+
i && v(i),
|
|
84
95
|
/* @__PURE__ */ s(
|
|
85
|
-
|
|
96
|
+
P,
|
|
86
97
|
{
|
|
87
|
-
name:
|
|
98
|
+
name: L ? "chevron_right" : "expand_more",
|
|
88
99
|
color: "white",
|
|
89
100
|
className: e["tedi-sidenav__toggle-icon"],
|
|
90
101
|
size: 18
|
|
91
102
|
}
|
|
92
103
|
),
|
|
93
|
-
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children:
|
|
104
|
+
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children: n })
|
|
94
105
|
]
|
|
95
106
|
}
|
|
96
107
|
) }),
|
|
97
|
-
groups:
|
|
108
|
+
groups: p,
|
|
98
109
|
onOpenChange: A
|
|
99
110
|
}
|
|
100
|
-
) :
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
-
|
|
103
|
-
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children:
|
|
111
|
+
) : r && c === 1 ? _.href || _.to ? /* @__PURE__ */ l(M, { children: [
|
|
112
|
+
/* @__PURE__ */ l(w, { ...C, children: [
|
|
113
|
+
i && v(i),
|
|
114
|
+
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children: n })
|
|
104
115
|
] }),
|
|
105
116
|
/* @__PURE__ */ s("div", { className: e["tedi-sidenav__link-collapse-wrapper"], children: /* @__PURE__ */ s(
|
|
106
|
-
|
|
117
|
+
B,
|
|
107
118
|
{
|
|
108
|
-
id:
|
|
119
|
+
id: u,
|
|
109
120
|
hideCollapseText: !0,
|
|
110
|
-
open:
|
|
111
|
-
onToggle:
|
|
121
|
+
open: d,
|
|
122
|
+
onToggle: k,
|
|
123
|
+
toggleLabel: T("sidenav.toggleSubmenuChildren", {
|
|
124
|
+
isCollapsedInternal: d,
|
|
125
|
+
children: n
|
|
126
|
+
}),
|
|
112
127
|
className: e["tedi-sidenav__collapse"],
|
|
113
|
-
children:
|
|
128
|
+
children: x()
|
|
114
129
|
}
|
|
115
130
|
) })
|
|
116
131
|
] }) : /* @__PURE__ */ s(
|
|
117
|
-
|
|
132
|
+
B,
|
|
118
133
|
{
|
|
119
|
-
id:
|
|
134
|
+
id: u,
|
|
120
135
|
hideCollapseText: !0,
|
|
121
|
-
open:
|
|
122
|
-
onToggle:
|
|
136
|
+
open: d,
|
|
137
|
+
onToggle: k,
|
|
123
138
|
className: e["tedi-sidenav__collapse"],
|
|
124
|
-
|
|
139
|
+
toggleLabel: T("sidenav.toggleSubmenuChildren", {
|
|
140
|
+
isCollapsedInternal: d,
|
|
141
|
+
children: n
|
|
142
|
+
}),
|
|
143
|
+
title: /* @__PURE__ */ l(
|
|
125
144
|
"span",
|
|
126
145
|
{
|
|
127
|
-
className:
|
|
146
|
+
className: o(
|
|
128
147
|
e["tedi-sidenav__link"],
|
|
129
|
-
|
|
148
|
+
d && e["tedi-sidenav__link--active"]
|
|
130
149
|
),
|
|
131
|
-
role: "
|
|
132
|
-
"aria-
|
|
150
|
+
role: "button",
|
|
151
|
+
"aria-expanded": d,
|
|
152
|
+
"aria-controls": u,
|
|
153
|
+
"aria-current": b ? "page" : void 0,
|
|
154
|
+
onKeyDown: W,
|
|
133
155
|
children: [
|
|
134
|
-
|
|
135
|
-
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children:
|
|
156
|
+
i && v(i),
|
|
157
|
+
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children: n })
|
|
136
158
|
]
|
|
137
159
|
}
|
|
138
160
|
),
|
|
139
|
-
children:
|
|
161
|
+
children: x()
|
|
140
162
|
}
|
|
141
|
-
) :
|
|
142
|
-
/* @__PURE__ */
|
|
143
|
-
|
|
144
|
-
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children:
|
|
163
|
+
) : r ? /* @__PURE__ */ l(M, { children: [
|
|
164
|
+
/* @__PURE__ */ l(w, { ...C, children: [
|
|
165
|
+
i && v(i),
|
|
166
|
+
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children: n }),
|
|
145
167
|
/* @__PURE__ */ s("i", { className: e["tedi-sidenav__bullet"] })
|
|
146
168
|
] }),
|
|
147
|
-
|
|
148
|
-
] }) : /* @__PURE__ */ s(
|
|
149
|
-
|
|
150
|
-
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children:
|
|
169
|
+
x()
|
|
170
|
+
] }) : /* @__PURE__ */ s(f.Trigger, { children: /* @__PURE__ */ l(w, { ...C, children: [
|
|
171
|
+
i && v(i),
|
|
172
|
+
/* @__PURE__ */ s("span", { className: e["tedi-sidenav__title"], children: n })
|
|
151
173
|
] }) }) });
|
|
152
|
-
return
|
|
153
|
-
/* @__PURE__ */ s(
|
|
154
|
-
|
|
155
|
-
] }) :
|
|
174
|
+
return c === 1 && m ? /* @__PURE__ */ l(f, { placement: "right", focusManager: { order: ["content"] }, children: [
|
|
175
|
+
/* @__PURE__ */ s(f.Content, { maxWidth: "medium", children: n }),
|
|
176
|
+
E
|
|
177
|
+
] }) : E;
|
|
156
178
|
};
|
|
157
179
|
export {
|
|
158
|
-
|
|
180
|
+
X as SideNavItem
|
|
159
181
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("react/jsx-runtime"),p=require("../../../../../../../external/classnames/index.cjs.js"),b=require("../../../../buttons/button/button.cjs.js"),_=require("../../../../buttons/floating-button/floating-button.cjs.js"),o=require("./sidenav-toggle.module.scss.cjs.js"),y=require("../../../../../providers/label-provider/use-labels.cjs.js"),i=({menuOpen:l,toggleMenu:s,referenceRef:n,getReferenceProps:a=()=>({}),variant:e="mobile"})=>{const{getLabel:c}=y.useLabels(),d=c("header.toggle",l),u=p.default(o.default["tedi-sidenav-toggle"],{[o.default["tedi-sidenav-toggle--open"]]:l,[o.default[`tedi-sidenav-toggle--${e}`]]:!0}),r=e==="collapse"?_.FloatingButton:b.Button,g=t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),s(!l))};return f.jsx(r,{...a(),ref:n,icon:{name:e==="collapse"?l?"right_panel_open":"left_panel_open":l?"close":"menu",className:o.default["tedi-sidenav-toggle__icon"],size:e==="collapse"?18:24},visualType:e==="collapse"?"secondary":"primary",className:u,onClick:()=>s(!l),onKeyDown:g,position:e==="collapse"?"absolute":"static",size:e==="collapse"?"small":"",children:d})};exports.SidenavToggle=i;exports.default=i;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { UnknownType } from '
|
|
2
|
+
import { UnknownType } from '../../../../../types/commonTypes';
|
|
3
3
|
export type SidenavToggleVariant = 'mobile' | 'collapse';
|
|
4
4
|
export type SidenavToggleProps = {
|
|
5
5
|
/**
|
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { Button as
|
|
4
|
-
import { FloatingButton as
|
|
1
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import d from "../../../../../../../external/classnames/index.es.js";
|
|
3
|
+
import { Button as f } from "../../../../buttons/button/button.es.js";
|
|
4
|
+
import { FloatingButton as y } from "../../../../buttons/floating-button/floating-button.es.js";
|
|
5
5
|
import l from "./sidenav-toggle.module.scss.es.js";
|
|
6
|
-
import { useLabels as
|
|
6
|
+
import { useLabels as _ } from "../../../../../providers/label-provider/use-labels.es.js";
|
|
7
7
|
const E = ({
|
|
8
8
|
menuOpen: o,
|
|
9
|
-
toggleMenu:
|
|
10
|
-
referenceRef:
|
|
11
|
-
getReferenceProps:
|
|
9
|
+
toggleMenu: t,
|
|
10
|
+
referenceRef: i,
|
|
11
|
+
getReferenceProps: a = () => ({}),
|
|
12
12
|
variant: e = "mobile"
|
|
13
13
|
}) => {
|
|
14
|
-
const { getLabel:
|
|
14
|
+
const { getLabel: c } = _(), r = c("header.toggle", o), n = d(l["tedi-sidenav-toggle"], {
|
|
15
15
|
[l["tedi-sidenav-toggle--open"]]: o,
|
|
16
16
|
[l[`tedi-sidenav-toggle--${e}`]]: !0
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
}), p = e === "collapse" ? y : f, m = (s) => {
|
|
18
|
+
(s.key === "Enter" || s.key === " ") && (s.preventDefault(), t(!o));
|
|
19
|
+
};
|
|
20
|
+
return /* @__PURE__ */ g(
|
|
21
|
+
p,
|
|
20
22
|
{
|
|
21
|
-
...
|
|
22
|
-
ref:
|
|
23
|
+
...a(),
|
|
24
|
+
ref: i,
|
|
23
25
|
icon: {
|
|
24
26
|
name: e === "collapse" ? o ? "right_panel_open" : "left_panel_open" : o ? "close" : "menu",
|
|
25
27
|
className: l["tedi-sidenav-toggle__icon"],
|
|
26
28
|
size: e === "collapse" ? 18 : 24
|
|
27
29
|
},
|
|
28
30
|
visualType: e === "collapse" ? "secondary" : "primary",
|
|
29
|
-
className:
|
|
30
|
-
onClick:
|
|
31
|
+
className: n,
|
|
32
|
+
onClick: () => t(!o),
|
|
33
|
+
onKeyDown: m,
|
|
31
34
|
position: e === "collapse" ? "absolute" : "static",
|
|
32
35
|
size: e === "collapse" ? "small" : "",
|
|
33
|
-
children:
|
|
36
|
+
children: r
|
|
34
37
|
}
|
|
35
38
|
);
|
|
36
39
|
};
|
|
@@ -84,15 +84,7 @@ export declare const SideNav: (<C extends React.ElementType = "a">(props: SideNa
|
|
|
84
84
|
Item: <C extends React.ElementType = "a">(props: SideNavItemProps<C> & {
|
|
85
85
|
onItemClick?: () => void;
|
|
86
86
|
level?: number;
|
|
87
|
-
isCollapsed
|
|
88
|
-
/**
|
|
89
|
-
* Show dividers between navigation items
|
|
90
|
-
* @default true
|
|
91
|
-
*/
|
|
92
|
-
? /**
|
|
93
|
-
* Show dividers between navigation items
|
|
94
|
-
* @default true
|
|
95
|
-
*/: boolean;
|
|
87
|
+
isCollapsed?: boolean;
|
|
96
88
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
97
89
|
Dropdown: <C extends React.ElementType = "a">({ trigger, groups, onOpenChange, }: {
|
|
98
90
|
trigger: React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),A=require("../../providers/label-provider/use-labels.cjs.js"),$=({accept:g,maxSize:r},o)=>{if(!g&&!r)return;const a=[g&&`${o("file-upload.accept")} ${g.replaceAll(",",", ")}`,r&&`${o("file-upload.max-size")} ${r}MB`].filter(Boolean).join(". ");return a.length?{text:a}:void 0},H=()=>`${Date.now()}-${Math.random().toString(36).slice(2)}`,I=g=>{const{getLabel:r}=A.useLabels(),{accept:o,maxSize:a,multiple:w=!1,validateIndividually:E=!1,defaultFiles:S=[],onChange:u,onDelete:f,files:x,announcementTimeout:T=5e3}=g,F=x!==void 0,[b,j]=m.useState(S),p=F?x:b,[L,h]=m.useState($({accept:o,maxSize:a},r)),[R,M]=m.useState(""),y=m.useRef(!0);m.useEffect(()=>()=>{y.current=!1},[]);const d=m.useRef(null),U=s=>{var n;if(!o)return!0;const l=o.split(",").map(e=>e.trim().toLowerCase()),t=s.name.includes(".")?`.${(n=s.name.split(".").pop())==null?void 0:n.toLowerCase()}`:"",i=s.type.toLowerCase();return l.includes(t)||l.includes(i)},V=s=>{const l=s.reduce((t,{type:i,file:n})=>(t[i].push(n.name),t),{extension:[],size:[]});return Object.entries(l).filter(([t,i])=>i.length).map(([t,i])=>{const n=i.map(e=>`'${e}'`).join(", ");return r(`file-upload.${t}-rejected`,n)}).join(". ")};return{innerFiles:p,uploadErrorHelper:L,onFileChange:s=>{if(s.target.files){const l=Array.from(s.target.files),t=[],i=l.map(e=>{const c=U(e),v=!a||e.size<=a*1024**2;c||t.push({type:"extension",file:e}),v||t.push({type:"size",file:e});const z=new File([e],e.name,{type:e.type,lastModified:e.lastModified});return Object.assign(z,{id:H(),isLoading:!1,isValid:c&&v})});let n=[];if(!w&&i.length>0)i[0].isValid&&(n=[i[0]]);else if(E)n=[...p,...i];else{const e=i.filter(c=>c.isValid);e.length>0&&(n=[...p,...e])}if(n.length>0&&(F||j(n),u==null||u(n),t.length===0)){const e=n.length-p.length,c=r("file-upload.success-added",e.toString())||`${e} file(s) added successfully`;y.current&&M(c)}if(t.length){const e=t.map(v=>v.file.name).join(", "),c=r("file-upload.failed-some",e)||`Upload failed for: ${e}`;y.current&&M(c),h({type:"error",text:V(t)})}else h($({accept:o,maxSize:a},r));setTimeout(()=>{y.current&&M("")},T),d.current&&(d.current.value="")}},onFileRemove:s=>{const l=p.filter(t=>t!==s);F||j(l),f==null||f(s),u==null||u(l),l.length===0&&h($({accept:o,maxSize:a},r)),d.current&&(d.current.value="")},handleClear:()=>{const s=[...p];return s.forEach(l=>f==null?void 0:f(l)),F||j([]),u==null||u([]),h($({accept:o,maxSize:a},r)),d.current&&(d.current.value=""),s},fileInputRef:d,announcement:R}};exports.useFileUpload=I;
|
|
@@ -19,6 +19,11 @@ export interface UseFileUploadProps {
|
|
|
19
19
|
onChange?: (files: FileUploadFile[]) => void;
|
|
20
20
|
onDelete?: (file: FileUploadFile) => void;
|
|
21
21
|
files?: FileUploadFile[];
|
|
22
|
+
/**
|
|
23
|
+
* How long (ms) the announcement message should be visible.
|
|
24
|
+
* @default 5000
|
|
25
|
+
*/
|
|
26
|
+
announcementTimeout?: number;
|
|
22
27
|
}
|
|
23
28
|
export declare const useFileUpload: (props: UseFileUploadProps) => {
|
|
24
29
|
innerFiles: FileUploadFile[];
|
|
@@ -27,4 +32,5 @@ export declare const useFileUpload: (props: UseFileUploadProps) => {
|
|
|
27
32
|
onFileRemove: (file: FileUploadFile) => void;
|
|
28
33
|
handleClear: () => FileUploadFile[];
|
|
29
34
|
fileInputRef: React.RefObject<HTMLInputElement>;
|
|
35
|
+
announcement: string;
|
|
30
36
|
};
|
|
@@ -1,80 +1,97 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useLabels as
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
1
|
+
import F, { useEffect as I } from "react";
|
|
2
|
+
import { useLabels as U } from "../../providers/label-provider/use-labels.es.js";
|
|
3
|
+
const $ = ({ accept: m, maxSize: r }, o) => {
|
|
4
|
+
if (!m && !r) return;
|
|
5
5
|
const a = [
|
|
6
|
-
|
|
6
|
+
m && `${o("file-upload.accept")} ${m.replaceAll(",", ", ")}`,
|
|
7
7
|
r && `${o("file-upload.max-size")} ${r}MB`
|
|
8
8
|
].filter(Boolean).join(". ");
|
|
9
9
|
return a.length ? { text: a } : void 0;
|
|
10
|
-
},
|
|
11
|
-
const { getLabel: r } =
|
|
10
|
+
}, b = () => `${Date.now()}-${Math.random().toString(36).slice(2)}`, k = (m) => {
|
|
11
|
+
const { getLabel: r } = U(), {
|
|
12
12
|
accept: o,
|
|
13
13
|
maxSize: a,
|
|
14
|
-
multiple:
|
|
15
|
-
validateIndividually:
|
|
16
|
-
defaultFiles:
|
|
14
|
+
multiple: w = !1,
|
|
15
|
+
validateIndividually: E = !1,
|
|
16
|
+
defaultFiles: R = [],
|
|
17
17
|
onChange: c,
|
|
18
|
-
onDelete:
|
|
19
|
-
files:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
onDelete: f,
|
|
19
|
+
files: M,
|
|
20
|
+
announcementTimeout: T = 5e3
|
|
21
|
+
} = m, g = M !== void 0, [L, j] = F.useState(R), p = g ? M : L, [S, h] = F.useState(
|
|
22
|
+
$({ accept: o, maxSize: a }, r)
|
|
23
|
+
), [V, x] = F.useState(""), y = F.useRef(!0);
|
|
24
|
+
I(() => () => {
|
|
25
|
+
y.current = !1;
|
|
26
|
+
}, []);
|
|
27
|
+
const d = F.useRef(null), z = (n) => {
|
|
28
|
+
var s;
|
|
24
29
|
if (!o) return !0;
|
|
25
|
-
const l = o.split(",").map((e) => e.trim().toLowerCase()),
|
|
26
|
-
return l.includes(
|
|
27
|
-
},
|
|
28
|
-
const l =
|
|
29
|
-
(
|
|
30
|
+
const l = o.split(",").map((e) => e.trim().toLowerCase()), t = n.name.includes(".") ? `.${(s = n.name.split(".").pop()) == null ? void 0 : s.toLowerCase()}` : "", i = n.type.toLowerCase();
|
|
31
|
+
return l.includes(t) || l.includes(i);
|
|
32
|
+
}, A = (n) => {
|
|
33
|
+
const l = n.reduce(
|
|
34
|
+
(t, { type: i, file: s }) => (t[i].push(s.name), t),
|
|
30
35
|
{ extension: [], size: [] }
|
|
31
36
|
);
|
|
32
|
-
return Object.entries(l).filter(([
|
|
33
|
-
const
|
|
34
|
-
return r(`file-upload.${
|
|
37
|
+
return Object.entries(l).filter(([t, i]) => i.length).map(([t, i]) => {
|
|
38
|
+
const s = i.map((e) => `'${e}'`).join(", ");
|
|
39
|
+
return r(`file-upload.${t}-rejected`, s);
|
|
35
40
|
}).join(". ");
|
|
36
41
|
};
|
|
37
42
|
return {
|
|
38
|
-
innerFiles:
|
|
39
|
-
uploadErrorHelper:
|
|
40
|
-
onFileChange: (
|
|
41
|
-
if (
|
|
42
|
-
const l = Array.from(
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const
|
|
43
|
+
innerFiles: p,
|
|
44
|
+
uploadErrorHelper: S,
|
|
45
|
+
onFileChange: (n) => {
|
|
46
|
+
if (n.target.files) {
|
|
47
|
+
const l = Array.from(n.target.files), t = [], i = l.map((e) => {
|
|
48
|
+
const u = z(e), v = !a || e.size <= a * 1024 ** 2;
|
|
49
|
+
u || t.push({ type: "extension", file: e }), v || t.push({ type: "size", file: e });
|
|
50
|
+
const H = new File([e], e.name, {
|
|
46
51
|
type: e.type,
|
|
47
52
|
lastModified: e.lastModified
|
|
48
53
|
});
|
|
49
|
-
return Object.assign(
|
|
50
|
-
id:
|
|
54
|
+
return Object.assign(H, {
|
|
55
|
+
id: b(),
|
|
51
56
|
isLoading: !1,
|
|
52
|
-
isValid:
|
|
57
|
+
isValid: u && v
|
|
53
58
|
});
|
|
54
59
|
});
|
|
55
|
-
let
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
else if (
|
|
59
|
-
|
|
60
|
+
let s = [];
|
|
61
|
+
if (!w && i.length > 0)
|
|
62
|
+
i[0].isValid && (s = [i[0]]);
|
|
63
|
+
else if (E)
|
|
64
|
+
s = [...p, ...i];
|
|
60
65
|
else {
|
|
61
|
-
const e =
|
|
62
|
-
e.length > 0 && (
|
|
66
|
+
const e = i.filter((u) => u.isValid);
|
|
67
|
+
e.length > 0 && (s = [...p, ...e]);
|
|
63
68
|
}
|
|
64
|
-
|
|
69
|
+
if (s.length > 0 && (g || j(s), c == null || c(s), t.length === 0)) {
|
|
70
|
+
const e = s.length - p.length, u = r("file-upload.success-added", e.toString()) || `${e} file(s) added successfully`;
|
|
71
|
+
y.current && x(u);
|
|
72
|
+
}
|
|
73
|
+
if (t.length) {
|
|
74
|
+
const e = t.map((v) => v.file.name).join(", "), u = r("file-upload.failed-some", e) || `Upload failed for: ${e}`;
|
|
75
|
+
y.current && x(u), h({ type: "error", text: A(t) });
|
|
76
|
+
} else
|
|
77
|
+
h($({ accept: o, maxSize: a }, r));
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
y.current && x("");
|
|
80
|
+
}, T), d.current && (d.current.value = "");
|
|
65
81
|
}
|
|
66
82
|
},
|
|
67
|
-
onFileRemove: (
|
|
68
|
-
const l =
|
|
69
|
-
|
|
83
|
+
onFileRemove: (n) => {
|
|
84
|
+
const l = p.filter((t) => t !== n);
|
|
85
|
+
g || j(l), f == null || f(n), c == null || c(l), l.length === 0 && h($({ accept: o, maxSize: a }, r)), d.current && (d.current.value = "");
|
|
70
86
|
},
|
|
71
87
|
handleClear: () => {
|
|
72
|
-
const
|
|
73
|
-
return
|
|
88
|
+
const n = [...p];
|
|
89
|
+
return n.forEach((l) => f == null ? void 0 : f(l)), g || j([]), c == null || c([]), h($({ accept: o, maxSize: a }, r)), d.current && (d.current.value = ""), n;
|
|
74
90
|
},
|
|
75
|
-
fileInputRef: d
|
|
91
|
+
fileInputRef: d,
|
|
92
|
+
announcement: V
|
|
76
93
|
};
|
|
77
94
|
};
|
|
78
95
|
export {
|
|
79
|
-
|
|
96
|
+
k as useFileUpload
|
|
80
97
|
};
|