@alixpartners/ui-components 2.5.0 → 2.5.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.
Files changed (35) hide show
  1. package/README.md +97 -97
  2. package/dist/RichTextEditor-CHGQT1Qj.js +363 -0
  3. package/dist/assets/Datepicker.css +1 -0
  4. package/dist/assets/DragAndDrop.css +1 -1
  5. package/dist/assets/FilePicker.css +1 -1
  6. package/dist/assets/RadioGroup.css +1 -1
  7. package/dist/assets/RichTextEditor.css +1 -0
  8. package/dist/components/Creatable/Creatable.js +1 -1
  9. package/dist/components/Datepicker/Datepicker.d.ts +22 -0
  10. package/dist/components/Datepicker/Datepicker.js +227 -0
  11. package/dist/components/Datepicker/Datepicker.test.d.ts +1 -0
  12. package/dist/components/Datepicker/Datepicker.test.js +40 -0
  13. package/dist/components/DragAndDrop/DragAndDrop.d.ts +4 -1
  14. package/dist/components/DragAndDrop/DragAndDrop.js +96 -84
  15. package/dist/components/DragAndDrop/DragAndDrop.test.js +179 -173
  16. package/dist/components/Dropdown/Dropdown.js +1 -1
  17. package/dist/components/NavBar/NavBar.js +1 -1
  18. package/dist/components/RadioGroup/RadioGroup.d.ts +3 -1
  19. package/dist/components/RadioGroup/RadioGroup.js +16 -14
  20. package/dist/components/RadioGroup/RadioGroup.test.js +8 -0
  21. package/dist/components/RichTextEditor/RichTextEditor.d.ts +26 -0
  22. package/dist/components/RichTextEditor/RichTextEditor.js +10 -0
  23. package/dist/components/RichTextEditor/RichTextEditor.model.d.ts +12 -0
  24. package/dist/components/RichTextEditor/RichTextEditor.test.d.ts +1 -0
  25. package/dist/components/RichTextEditor/RichTextEditor.test.js +91 -0
  26. package/dist/components/SplitButton/SplitButton.js +1 -1
  27. package/dist/components/TagsFields/TagsFields.js +1 -1
  28. package/dist/components/Tooltip/Tooltip.js +1 -1
  29. package/dist/{index-C-3_YVJ1.js → index-D34Qo5Qx.js} +478 -473
  30. package/dist/{index-C4ffg1vf.js → index-DZ4Gof57.js} +1 -1
  31. package/dist/{index-D_3jWVyV.js → index-DgdVwltD.js} +1 -1
  32. package/dist/main.d.ts +2 -0
  33. package/dist/main.js +54 -50
  34. package/dist/web.config +8 -8
  35. package/package.json +88 -88
@@ -0,0 +1,22 @@
1
+ import { TooltipProps } from '../Tooltip/Tooltip';
2
+ export type DatepickerLabelTooltipProps = Omit<TooltipProps, 'children'>;
3
+ type DateFormat = 'MM/DD/YYYY' | 'YYYY/MM/DD' | 'Mon DD, YYYY';
4
+ type DateInput = Date | string | number;
5
+ type DatepickerProps = {
6
+ className?: string;
7
+ label?: string;
8
+ placeholder?: string;
9
+ value?: DateInput | null;
10
+ defaultValue?: DateInput | null;
11
+ disabled?: boolean;
12
+ required?: boolean;
13
+ errorMessage?: string;
14
+ helpText?: string;
15
+ minDate?: DateInput;
16
+ maxDate?: DateInput;
17
+ onChange?: (value: Date | null) => void;
18
+ labelTooltip?: DatepickerLabelTooltipProps;
19
+ dateFormat?: DateFormat;
20
+ };
21
+ export default function Datepicker({ className, label, placeholder, value, defaultValue, disabled, required, errorMessage, helpText, minDate, maxDate, onChange, labelTooltip, dateFormat, }: DatepickerProps): import("react/jsx-runtime").JSX.Element;
22
+ export {};
@@ -0,0 +1,227 @@
1
+ import { jsxs as m, jsx as o, Fragment as re } from "react/jsx-runtime";
2
+ import { c as T } from "../../clsx-OuTLNxxd.js";
3
+ import { useState as F, useEffect as ce, useMemo as J } from "react";
4
+ import v from "../Button/Button.js";
5
+ import W from "../Icon/Icon.js";
6
+ import le from "../Tooltip/Tooltip.js";
7
+ import { R as de, T as se, P as ie, C as _e } from "../../index-DZ4Gof57.js";
8
+ import '../../assets/Datepicker.css';const ue = "Datepicker-module__datepicker___SxV3q", pe = "Datepicker-module__label___uPuKe", De = "Datepicker-module__labelText___BAflA", me = "Datepicker-module__required___cAVa1", he = "Datepicker-module__labelTooltipIcon___n2IvH", ye = "Datepicker-module__inputWrapper___aKtHi", ge = "Datepicker-module__inputIcon___OUb8V", fe = "Datepicker-module__inputText___rwYA-", ke = "Datepicker-module__placeholder___UVl-W", Me = "Datepicker-module__error___C5WX8", Ne = "Datepicker-module__calendarContainer___Bjfa8", Se = "Datepicker-module__calendarHeader___a7I0V", Te = "Datepicker-module__calendarDivider___DRk4M", Ae = "Datepicker-module__headerActions___AP324", Fe = "Datepicker-module__headerAction___nyMJF", Ye = "Datepicker-module__headerActionIcon___J8RC-", be = "Datepicker-module__headerLabel___IPAo-", we = "Datepicker-module__calendarBody___yaLJA", Oe = "Datepicker-module__weekdays___noAbQ", Ee = "Datepicker-module__weekday___0hrfJ", Ie = "Datepicker-module__grid___lJEHW", Ce = "Datepicker-module__gridMonths___n1wAM", Re = "Datepicker-module__gridYears___cI0YR", ze = "Datepicker-module__day___3XU9S", ve = "Datepicker-module__date___G2cRK", xe = "Datepicker-module__month___VKvm3", Pe = "Datepicker-module__year___9OzXM", Ve = "Datepicker-module__daySelected___DkZ5T", Le = "Datepicker-module__dayOutside___CXb-b", $e = "Datepicker-module__dayTodayCurrent___ocAqU", Be = "Datepicker-module__dayTodayDot___ZyD-l", He = "Datepicker-module__calendarFooter___sLvNP", Je = "Datepicker-module__calendarFooterSpacer___3IXgI", We = "Datepicker-module__helperRow___IKmCq", Xe = "Datepicker-module__helpText___g7zEx", Ue = "Datepicker-module__errorText___7o5Rs", qe = "Datepicker-module__disabled___Hlnlo", e = {
9
+ datepicker: ue,
10
+ label: pe,
11
+ labelText: De,
12
+ required: me,
13
+ labelTooltipIcon: he,
14
+ inputWrapper: ye,
15
+ inputIcon: ge,
16
+ inputText: fe,
17
+ placeholder: ke,
18
+ error: Me,
19
+ calendarContainer: Ne,
20
+ calendarHeader: Se,
21
+ calendarDivider: Te,
22
+ headerActions: Ae,
23
+ headerAction: Fe,
24
+ headerActionIcon: Ye,
25
+ headerLabel: be,
26
+ calendarBody: we,
27
+ weekdays: Oe,
28
+ weekday: Ee,
29
+ grid: Ie,
30
+ gridMonths: Ce,
31
+ gridYears: Re,
32
+ day: ze,
33
+ date: ve,
34
+ month: xe,
35
+ year: Pe,
36
+ daySelected: Ve,
37
+ dayOutside: Le,
38
+ dayTodayCurrent: $e,
39
+ dayTodayDot: Be,
40
+ calendarFooter: He,
41
+ calendarFooterSpacer: Je,
42
+ helperRow: We,
43
+ helpText: Xe,
44
+ errorText: Ue,
45
+ disabled: qe
46
+ }, Ke = 7, Ge = 6, je = Ke * Ge, g = 12, Ze = 1, Qe = 1, q = 1, I = 1, et = 1, tt = 1, f = 1, at = 6, nt = "Label", ot = "Today", rt = "ap-icon-date", ct = "ap-icon-info", lt = "ap-icon-expand-more", dt = "ap-icon-expand-less", st = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], x = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], it = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], _t = (t) => {
47
+ if (t instanceof Date)
48
+ return Number.isNaN(t.getTime()) ? null : t;
49
+ if (typeof t == "string" || typeof t == "number") {
50
+ const a = new Date(t);
51
+ return Number.isNaN(a.getTime()) ? null : a;
52
+ }
53
+ return null;
54
+ }, i = (t) => {
55
+ const a = _t(t);
56
+ return a ? new Date(a.getFullYear(), a.getMonth(), a.getDate()) : null;
57
+ }, X = (t, a) => t.getFullYear() === a.getFullYear() && t.getMonth() === a.getMonth() && t.getDate() === a.getDate(), U = (t) => String(t).padStart(2, "0"), ut = (t, a) => {
58
+ const _ = U(t.getMonth() + 1), r = U(t.getDate()), s = t.getFullYear();
59
+ return a === "Mon DD, YYYY" ? `${x[t.getMonth()]} ${r}, ${s}` : a === "YYYY/MM/DD" ? `${s}/${_}/${r}` : `${_}/${r}/${s}`;
60
+ }, pt = (t, a) => {
61
+ const r = new Date(t, a, f).getDay(), s = new Date(t, a + I, 0).getDate(), D = new Date(t, a, 0).getDate(), c = [];
62
+ for (let l = r - Ze; l >= 0; l -= 1)
63
+ c.push({
64
+ date: new Date(t, a - q, D - l),
65
+ inCurrentMonth: !1
66
+ });
67
+ for (let l = f; l <= s; l += 1)
68
+ c.push({
69
+ date: new Date(t, a, l),
70
+ inCurrentMonth: !0
71
+ });
72
+ for (; c.length < je; ) {
73
+ const l = c.length - (r + s) + Qe;
74
+ c.push({
75
+ date: new Date(t, a + I, l),
76
+ inCurrentMonth: !1
77
+ });
78
+ }
79
+ return c;
80
+ };
81
+ function Dt({
82
+ day: t,
83
+ selectedDate: a,
84
+ currentMonth: _,
85
+ minDate: r,
86
+ maxDate: s,
87
+ onSelect: D
88
+ }) {
89
+ const c = i(t.date);
90
+ if (!c) return null;
91
+ const l = r ? i(r) : null, k = s ? i(s) : null, u = !!(l && c < l || k && c > k), h = i(a), M = h ? X(c, h) : !1, y = i(/* @__PURE__ */ new Date()), Y = y ? X(c, y) : !1;
92
+ return /* @__PURE__ */ m("button", { type: "button", className: T(e.day, e.date, !t.inCurrentMonth && e.dayOutside, t.date.getMonth() !== _ && e.dayOutside, u && e.dayOutside, Y && !M && e.dayTodayCurrent, M && e.daySelected), onClick: () => D(c), disabled: u, children: [
93
+ t.date.getDate(),
94
+ Y && !M && /* @__PURE__ */ o("span", { className: e.dayTodayDot })
95
+ ] });
96
+ }
97
+ function mt({
98
+ monthIndex: t,
99
+ activeMonth: a,
100
+ year: _,
101
+ minDate: r,
102
+ maxDate: s,
103
+ onSelect: D
104
+ }) {
105
+ const c = r ? i(r) : null, l = s ? i(s) : null, k = new Date(_, t, f), u = new Date(_, t + I, 0), h = !!(c && u < c || l && k > l);
106
+ return /* @__PURE__ */ o("button", { type: "button", className: T(e.day, e.month, h && e.dayOutside, t === a && e.daySelected), onClick: () => D(t), disabled: h, children: x[t] });
107
+ }
108
+ function ht({
109
+ year: t,
110
+ activeYear: a,
111
+ minDate: _,
112
+ maxDate: r,
113
+ onSelect: s
114
+ }) {
115
+ const D = _ ? i(_) : null, c = r ? i(r) : null, l = new Date(t, 0, f), k = new Date(t, 11, 31), u = !!(D && k < D || c && l > c);
116
+ return /* @__PURE__ */ o("button", { type: "button", className: T(e.day, e.year, u && e.dayOutside, t === a && e.daySelected), onClick: () => s(t), disabled: u, children: t });
117
+ }
118
+ function Tt({
119
+ className: t,
120
+ label: a = nt,
121
+ placeholder: _ = "",
122
+ value: r,
123
+ defaultValue: s = /* @__PURE__ */ new Date(),
124
+ disabled: D = !1,
125
+ required: c = !1,
126
+ errorMessage: l,
127
+ helpText: k,
128
+ minDate: u,
129
+ maxDate: h,
130
+ onChange: M,
131
+ labelTooltip: y,
132
+ dateFormat: Y = "MM/DD/YYYY"
133
+ }) {
134
+ const C = r !== void 0 && !!M, R = i(r), z = i(s), P = i(/* @__PURE__ */ new Date()) ?? /* @__PURE__ */ new Date(), [K, V] = F(!1), [b, L] = F(() => r === null ? null : R ?? z), [p, S] = F("date"), [d, N] = F(() => r === null ? P : R || z || P), [w, O] = F(Math.floor(d.getFullYear() / g) * g);
135
+ ce(() => {
136
+ if (!C) return;
137
+ const n = i(r);
138
+ L(n), n && (N(n), O(Math.floor(n.getFullYear() / g) * g));
139
+ }, [C, r]);
140
+ const G = b ? ut(b, Y) : _, E = i(/* @__PURE__ */ new Date()) ?? /* @__PURE__ */ new Date(), $ = u ? i(u) : null, B = h ? i(h) : null, j = !!($ && E < $ || B && E > B), Z = J(() => pt(d.getFullYear(), d.getMonth()), [d]), Q = J(() => Array.from({
141
+ length: g
142
+ }, (n, A) => w + A), [w]), ee = (n) => {
143
+ C || L(n), M == null || M(n);
144
+ }, te = () => {
145
+ if (p === "date") {
146
+ S("month");
147
+ return;
148
+ }
149
+ if (p === "month") {
150
+ S("year");
151
+ return;
152
+ }
153
+ }, ae = () => {
154
+ if (p === "date") {
155
+ N(new Date(d.getFullYear(), d.getMonth() - q, f));
156
+ return;
157
+ }
158
+ if (p === "month") {
159
+ N(new Date(d.getFullYear() - et, d.getMonth(), f));
160
+ return;
161
+ }
162
+ O((n) => n - g);
163
+ }, ne = () => {
164
+ if (p === "date") {
165
+ N(new Date(d.getFullYear(), d.getMonth() + I, f));
166
+ return;
167
+ }
168
+ if (p === "month") {
169
+ N(new Date(d.getFullYear() + tt, d.getMonth(), f));
170
+ return;
171
+ }
172
+ O((n) => n + g);
173
+ }, H = (n) => {
174
+ ee(n), N(n), V(!1), S("date");
175
+ };
176
+ return /* @__PURE__ */ m("div", { className: T(e.datepicker, t, D && e.disabled), children: [
177
+ a && /* @__PURE__ */ m("label", { className: e.label, children: [
178
+ /* @__PURE__ */ o("span", { className: e.labelText, children: a }),
179
+ c && /* @__PURE__ */ o("span", { className: e.required, children: "*" }),
180
+ y && /* @__PURE__ */ o(le, { content: y.content, size: y.size, theme: y.theme, tipSide: y.tipSide, tipAlignment: y.tipAlignment, startVisible: y.startVisible, children: /* @__PURE__ */ o(W, { icon: ct, className: e.labelTooltipIcon }) })
181
+ ] }),
182
+ /* @__PURE__ */ m(de, { open: K, onOpenChange: (n) => {
183
+ D || (V(n), n || S("date"));
184
+ }, children: [
185
+ /* @__PURE__ */ m(se, { className: T(e.inputWrapper, l && e.error), disabled: D, children: [
186
+ /* @__PURE__ */ o(W, { icon: rt, className: e.inputIcon }),
187
+ /* @__PURE__ */ o("span", { className: T(e.inputText, !b && e.placeholder), children: G })
188
+ ] }),
189
+ /* @__PURE__ */ o(ie, { children: /* @__PURE__ */ m(_e, { side: "bottom", align: "start", sideOffset: at, className: e.calendarContainer, children: [
190
+ /* @__PURE__ */ m("div", { className: e.calendarHeader, children: [
191
+ /* @__PURE__ */ m("button", { type: "button", className: e.headerLabel, onClick: te, disabled: p === "year", children: [
192
+ p === "date" && `${it[d.getMonth()]} ${d.getFullYear()}`,
193
+ p === "month" && `${d.getFullYear()}`,
194
+ p === "year" && `${w} - ${w + g - 1}`
195
+ ] }),
196
+ /* @__PURE__ */ m("div", { className: e.headerActions, children: [
197
+ /* @__PURE__ */ o(v, { size: "md", type: "tertiary", className: e.headerAction, icon: dt, iconClassName: e.headerActionIcon, onClick: ae }),
198
+ /* @__PURE__ */ o(v, { size: "md", type: "tertiary", className: e.headerAction, icon: lt, iconClassName: e.headerActionIcon, onClick: ne })
199
+ ] })
200
+ ] }),
201
+ /* @__PURE__ */ o("div", { className: e.calendarDivider }),
202
+ /* @__PURE__ */ m("div", { className: e.calendarBody, children: [
203
+ p === "date" && /* @__PURE__ */ m(re, { children: [
204
+ /* @__PURE__ */ o("div", { className: e.weekdays, children: st.map((n) => /* @__PURE__ */ o("span", { className: e.weekday, children: n }, n)) }),
205
+ /* @__PURE__ */ o("div", { className: e.grid, children: Z.map((n) => /* @__PURE__ */ o(Dt, { day: n, selectedDate: b, currentMonth: d.getMonth(), minDate: u, maxDate: h, onSelect: H }, n.date.toISOString())) })
206
+ ] }),
207
+ p === "month" && /* @__PURE__ */ o("div", { className: e.gridMonths, children: x.map((n, A) => /* @__PURE__ */ o(mt, { monthIndex: A, activeMonth: d.getMonth(), year: d.getFullYear(), minDate: u, maxDate: h, onSelect: (oe) => {
208
+ N(new Date(d.getFullYear(), oe, f)), S("date");
209
+ } }, n)) }),
210
+ p === "year" && /* @__PURE__ */ o("div", { className: e.gridYears, children: Q.map((n) => /* @__PURE__ */ o(ht, { year: n, activeYear: d.getFullYear(), minDate: u, maxDate: h, onSelect: (A) => {
211
+ N(new Date(A, d.getMonth(), f)), S("month");
212
+ } }, n)) })
213
+ ] }),
214
+ /* @__PURE__ */ m("div", { className: e.calendarFooter, children: [
215
+ /* @__PURE__ */ o("div", { className: e.calendarFooterSpacer }),
216
+ /* @__PURE__ */ o(v, { type: "secondary", size: "md", variant: "default", disabled: j, onClick: () => {
217
+ H(E), O(Math.floor(E.getFullYear() / g) * g);
218
+ }, children: ot })
219
+ ] })
220
+ ] }) })
221
+ ] }),
222
+ /* @__PURE__ */ o("div", { className: e.helperRow, children: l ? /* @__PURE__ */ o("span", { className: e.errorText, children: l }) : k && /* @__PURE__ */ o("span", { className: e.helpText, children: k }) })
223
+ ] });
224
+ }
225
+ export {
226
+ Tt as default
227
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { jsx as l } from "react/jsx-runtime";
2
+ import { d as u, i as c, r as B, g as e, s as d, f as D, v as m } from "../../vi.bdSIJ99Y-017e_Pkz.js";
3
+ import g from "./Datepicker.js";
4
+ u("Datepicker", () => {
5
+ c("should render datepicker container", () => {
6
+ B(/* @__PURE__ */ l(g, {})), e(d.getByTestId("datepicker")).toBeInTheDocument();
7
+ }), c("should render required marker when required is true", () => {
8
+ B(/* @__PURE__ */ l(g, { label: "Start date", required: !0 })), e(d.getByTestId("datepicker-label")).toHaveTextContent("*");
9
+ }), c("should keep calendar closed and trigger disabled when disabled is true", () => {
10
+ B(/* @__PURE__ */ l(g, { disabled: !0 }));
11
+ const t = d.getByTestId("datepicker-trigger");
12
+ e(t).toBeDisabled(), D.click(t), e(d.queryByTestId("datepicker-calendar")).not.toBeInTheDocument();
13
+ }), c("should disable days outside minDate and maxDate", () => {
14
+ B(/* @__PURE__ */ l(g, { defaultValue: new Date(2025, 0, 15), minDate: new Date(2025, 0, 10), maxDate: new Date(2025, 0, 20) })), D.click(d.getByTestId("datepicker-trigger"));
15
+ const t = d.getAllByTestId("datepicker-day"), r = t.find((i) => {
16
+ var a;
17
+ return ((a = i.textContent) == null ? void 0 : a.trim()) === "9";
18
+ }), n = t.find((i) => {
19
+ var a;
20
+ return ((a = i.textContent) == null ? void 0 : a.trim()) === "10";
21
+ }), o = t.find((i) => {
22
+ var a;
23
+ return ((a = i.textContent) == null ? void 0 : a.trim()) === "20";
24
+ }), s = t.find((i) => {
25
+ var a;
26
+ return ((a = i.textContent) == null ? void 0 : a.trim()) === "21";
27
+ });
28
+ e(r).toBeDefined(), e(n).toBeDefined(), e(o).toBeDefined(), e(s).toBeDefined(), e(r).toBeDisabled(), e(n).not.toBeDisabled(), e(o).not.toBeDisabled(), e(s).toBeDisabled();
29
+ }), c("should call onChange with selected date", () => {
30
+ const t = m.fn();
31
+ B(/* @__PURE__ */ l(g, { defaultValue: new Date(2025, 0, 15), onChange: t })), D.click(d.getByTestId("datepicker-trigger"));
32
+ const r = d.getAllByTestId("datepicker-day").find((o) => {
33
+ var s;
34
+ return !o.className.includes("dayOutside") && ((s = o.textContent) == null ? void 0 : s.trim()) === "16";
35
+ });
36
+ e(r).toBeDefined(), D.click(r), e(t).toHaveBeenCalledTimes(1);
37
+ const n = t.mock.calls[0][0];
38
+ e(n).toBeInstanceOf(Date), e(n.getFullYear()).toBe(2025), e(n.getMonth()).toBe(0), e(n.getDate()).toBe(16);
39
+ });
40
+ });
@@ -38,8 +38,10 @@ type DragAndDropProps = {
38
38
  disabled?: boolean;
39
39
  label?: string;
40
40
  required?: boolean;
41
+ errorMessage?: string;
41
42
  fileExtensionsAllowed: string[];
42
43
  maxSize?: number;
44
+ constraintsText?: string;
43
45
  maxFiles?: number;
44
46
  value?: File | File[];
45
47
  onUpload?: (files: UploadFile[]) => void;
@@ -87,11 +89,12 @@ type DragAndDropProps = {
87
89
  * @param {boolean} [props.required] - Whether the field is required; shows an asterisk
88
90
  * @param {string[]} props.fileExtensionsAllowed - Allowed file extensions (e.g. ['pdf','png'])
89
91
  * @param {number} [props.maxSize] - Maximum file size in MB; default no limit
92
+ * @param {string} [props.constraintsText] - Full constraints line; when set, replaces default and `texts.constraints`
90
93
  * @param {number} [props.maxFiles] - Maximum number of files when type is 'multiple'
91
94
  * @param {File | File[]} [props.value] - Controlled value for the component; accepts a single File or array of Files
92
95
  * @param {(files: UploadFile[]) => void} [props.onUpload] - Callback fired with validated files upon selection or drop
93
96
  * @param {boolean} [props.queueFiles] - When true, newly selected files are appended to the existing list
94
97
  * @returns {JSX.Element} The rendered DragAndDrop component
95
98
  */
96
- export default function DragAndDrop({ label, type, disabled, required, fileExtensionsAllowed, maxSize, maxFiles, value, onUpload, onRemoveFile, queueFiles, className, maxSizeErrorMessage, fileExtensionInvalidErrorMessage, texts, fileIcon, errorIcon, deleteIcon, browseButtonIcon, renderFileItem, fileSizeFormatter, browseButtonProps, validator, errors: externalErrors, ...props }: DragAndDropProps): import("react/jsx-runtime").JSX.Element;
99
+ export default function DragAndDrop({ label, type, disabled, required, errorMessage, fileExtensionsAllowed, maxSize, constraintsText, maxFiles, value, onUpload, onRemoveFile, queueFiles, className, maxSizeErrorMessage, fileExtensionInvalidErrorMessage, texts, fileIcon, errorIcon, deleteIcon, browseButtonIcon, renderFileItem, fileSizeFormatter, browseButtonProps, validator, errors: externalErrors, ...props }: DragAndDropProps): import("react/jsx-runtime").JSX.Element;
97
100
  export {};
@@ -1,17 +1,19 @@
1
1
  import { jsxs as _, jsx as t } from "react/jsx-runtime";
2
- import { useId as vr, useRef as Lr, useState as J, useCallback as g, useMemo as A } from "react";
3
- import K from "../Button/Button.js";
4
- import { c as U } from "../../clsx-OuTLNxxd.js";
5
- import x from "../Icon/Icon.js";
6
- import '../../assets/DragAndDrop.css';const Cr = "DragAndDrop-module__disabled___h47do", br = "DragAndDrop-module__required___z3cHB", Or = "DragAndDrop-module__active___ZMuEx", d = {
2
+ import { useId as Cr, useRef as Or, useState as U, useCallback as g, useMemo as A } from "react";
3
+ import x from "../Button/Button.js";
4
+ import { c as rr } from "../../clsx-OuTLNxxd.js";
5
+ import er from "../Icon/Icon.js";
6
+ import '../../assets/DragAndDrop.css';const br = "DragAndDrop-module__disabled___h47do", Br = "DragAndDrop-module__required___z3cHB", Sr = "DragAndDrop-module__active___ZMuEx", wr = "DragAndDrop-module__error___zw69d", d = {
7
7
  "drag-and-drop-container": "DragAndDrop-module__drag-and-drop-container___WHqGh",
8
- disabled: Cr,
9
- required: br,
8
+ disabled: br,
9
+ required: Br,
10
10
  "drag-and-drop-space-text-message": "DragAndDrop-module__drag-and-drop-space-text-message___fL-Ac",
11
11
  "drag-and-drop-space-text-constraints": "DragAndDrop-module__drag-and-drop-space-text-constraints___YrL7J",
12
12
  "drag-and-drop-space": "DragAndDrop-module__drag-and-drop-space___09a0I",
13
- active: Or,
13
+ active: Sr,
14
+ error: wr,
14
15
  "drag-and-drop-space-text": "DragAndDrop-module__drag-and-drop-space-text___-8rqC",
16
+ "error-message": "DragAndDrop-module__error-message___om0Oy",
15
17
  "drag-and-drop-files-list": "DragAndDrop-module__drag-and-drop-files-list___7WNCk",
16
18
  "drag-and-drop-files-list-item": "DragAndDrop-module__drag-and-drop-files-list-item___vQO6M",
17
19
  "drag-and-drop-files-list-item-content": "DragAndDrop-module__drag-and-drop-files-list-item-content___lx7-M",
@@ -24,35 +26,37 @@ import '../../assets/DragAndDrop.css';const Cr = "DragAndDrop-module__disabled__
24
26
  "drag-and-drop-files-list-item-error": "DragAndDrop-module__drag-and-drop-files-list-item-error___yR0DY",
25
27
  "drag-and-drop-files-list-item-icon-error": "DragAndDrop-module__drag-and-drop-files-list-item-icon-error___17EE-",
26
28
  "drag-and-drop-files-list-item-icon-delete": "DragAndDrop-module__drag-and-drop-files-list-item-icon-delete___Z1l-B"
27
- }, Br = (u) => `File size is too large. Must be up to ${u}MB.`, Sr = (u) => `The file format is incorrect. Please make sure it is one of the extensions: ${u}.`;
28
- function Rr({
29
+ }, Er = (u) => `File size is too large. Must be up to ${u}MB.`, $r = (u) => `The file format is incorrect. Please make sure it is one of the extensions: ${u}.`;
30
+ function Pr({
29
31
  label: u,
30
- type: i = "single",
31
- disabled: q,
32
- required: rr,
32
+ type: o = "single",
33
+ disabled: P,
34
+ required: ar,
35
+ errorMessage: b,
33
36
  fileExtensionsAllowed: c,
34
37
  maxSize: p = Number.POSITIVE_INFINITY,
38
+ constraintsText: B,
35
39
  maxFiles: l = Number.POSITIVE_INFINITY,
36
40
  value: D,
37
41
  onUpload: m,
38
42
  onRemoveFile: I,
39
- queueFiles: P,
40
- className: er,
41
- maxSizeErrorMessage: T,
42
- fileExtensionInvalidErrorMessage: v,
43
+ queueFiles: V,
44
+ className: nr,
45
+ maxSizeErrorMessage: v,
46
+ fileExtensionInvalidErrorMessage: T,
43
47
  texts: a,
44
- fileIcon: ar = "ap-icon-document",
45
- errorIcon: nr = "ap-icon-alert",
46
- deleteIcon: dr = "ap-icon-delete",
47
- browseButtonIcon: ir,
48
- renderFileItem: V,
49
- fileSizeFormatter: O,
50
- browseButtonProps: or,
51
- validator: B,
48
+ fileIcon: dr = "ap-icon-document",
49
+ errorIcon: or = "ap-icon-alert",
50
+ deleteIcon: ir = "ap-icon-delete",
51
+ browseButtonIcon: sr,
52
+ renderFileItem: j,
53
+ fileSizeFormatter: S,
54
+ browseButtonProps: tr,
55
+ validator: w,
52
56
  errors: L,
53
- ...sr
57
+ ...lr
54
58
  }) {
55
- const j = vr(), y = Lr(null), [C, Y] = J([]), [G, S] = J(!1), h = D !== void 0, M = c.join(", "), X = p ? `up to ${p}MB` : "", tr = c.map((r) => `.${r.replace(/^\./, "")}`).join(","), Z = g((r, e) => {
59
+ const Y = Cr(), G = Or(null), [C, X] = U([]), [Z, E] = U(!1), h = D !== void 0, F = c.join(", "), cr = c.map((r) => `.${r.replace(/^\./, "")}`).join(","), H = g((r, e) => {
56
60
  if (!r) return r || "";
57
61
  if (a != null && a.errors && e) {
58
62
  if (e === "SIZE_TOO_LARGE" && a.errors.sizeTooLarge)
@@ -61,51 +65,58 @@ function Rr({
61
65
  return typeof a.errors.invalidExtension == "function" ? a.errors.invalidExtension(c) : a.errors.invalidExtension;
62
66
  }
63
67
  return r;
64
- }, [a, p, c]), lr = g(() => a != null && a.browse ? typeof a.browse == "function" ? a.browse(i) : a.browse : i === "single" ? "Browse file" : "Browse files", [a, i]), cr = g(() => a != null && a.drag ? typeof a.drag == "function" ? a.drag(i) : a.drag : i === "single" ? "or drag your file" : "or drag multiple files", [a, i]), _r = g(() => a != null && a.constraints ? a.constraints({
65
- extensions: c,
66
- maxSize: p,
67
- type: i
68
- }) : `${M} ${i === "single" ? "file" : "files"} ${X}`, [a, c, M, p, X, i]), gr = () => {
68
+ }, [a, p, c]), _r = g(() => a != null && a.browse ? typeof a.browse == "function" ? a.browse(o) : a.browse : o === "single" ? "Browse file" : "Browse files", [a, o]), gr = g(() => a != null && a.drag ? typeof a.drag == "function" ? a.drag(o) : a.drag : o === "single" ? "or drag your file" : "or drag multiple files", [a, o]), pr = g(() => {
69
+ if (B !== void 0)
70
+ return B;
71
+ if (a != null && a.constraints)
72
+ return a.constraints({
73
+ extensions: c,
74
+ maxSize: p,
75
+ type: o
76
+ });
77
+ const r = p ? `up to ${p}MB` : "";
78
+ return `${F} ${o === "single" ? "file" : "files"} ${r}`;
79
+ }, [B, a, c, F, p, o]), mr = () => {
69
80
  var r;
70
- N || (r = y.current) == null || r.click();
71
- }, $ = A(() => new Set(c.map((r) => r.toLowerCase().replace(/^\./, ""))), [c]), H = g((r, e) => {
72
- const s = e.maxSize ? e.maxSize * 1024 * 1024 : Number.POSITIVE_INFINITY, o = e.fileExtensionsAllowed.join(", "), f = (T == null ? void 0 : T.replace(/\{maxSize\}/g, String(e.maxSize))) ?? Br(e.maxSize), Nr = (v == null ? void 0 : v.replace(/\{fileExtensionsAllowed\}/g, o)) ?? Sr(o), Ar = r.size <= s, Q = r.name.toLowerCase(), Ir = Q.includes(".") ? Q.split(".").pop() ?? "" : "", Tr = $.size === 0 || $.has(Ir);
73
- return Ar ? Tr ? {
81
+ N || (r = G.current) == null || r.click();
82
+ }, $ = A(() => new Set(c.map((r) => r.toLowerCase().replace(/^\./, ""))), [c]), M = g((r, e) => {
83
+ const s = e.maxSize ? e.maxSize * 1024 * 1024 : Number.POSITIVE_INFINITY, i = e.fileExtensionsAllowed.join(", "), f = (v == null ? void 0 : v.replace(/\{maxSize\}/g, String(e.maxSize))) ?? Er(e.maxSize), Ir = (T == null ? void 0 : T.replace(/\{fileExtensionsAllowed\}/g, i)) ?? $r(i), vr = r.size <= s, K = r.name.toLowerCase(), Tr = K.includes(".") ? K.split(".").pop() ?? "" : "", Lr = $.size === 0 || $.has(Tr);
84
+ return vr ? Lr ? {
74
85
  file: r
75
86
  } : {
76
87
  file: r,
77
- error: Nr,
88
+ error: Ir,
78
89
  errorCode: "INVALID_EXTENSION"
79
90
  } : {
80
91
  file: r,
81
92
  error: f,
82
93
  errorCode: "SIZE_TOO_LARGE"
83
94
  };
84
- }, [$, T, v]), k = A(() => ({
95
+ }, [$, v, T]), k = A(() => ({
85
96
  maxSize: p,
86
97
  fileExtensionsAllowed: c,
87
- type: i,
98
+ type: o,
88
99
  maxFiles: l
89
- }), [p, c, i, l]), b = g((r) => {
100
+ }), [p, c, o, l]), O = g((r) => {
90
101
  let e;
91
- B ? e = r.map((o) => B(o, k)) : e = r.map((o) => H(o, k));
92
- let s = e.map((o) => {
93
- const f = o.error ? Z(o.error, o.errorCode) : void 0;
102
+ w ? e = r.map((i) => w(i, k)) : e = r.map((i) => M(i, k));
103
+ let s = e.map((i) => {
104
+ const f = i.error ? H(i.error, i.errorCode) : void 0;
94
105
  return {
95
- file: o.file,
106
+ file: i.file,
96
107
  // Don't merge external errors here - that happens in files useMemo
97
108
  error: f
98
109
  };
99
110
  });
100
- return i === "single" && s.length > 1 ? s.slice(0, 1) : (l && l > 0 && s.length > l && (s = s.map((o, f) => f < l ? o : {
101
- ...o,
102
- error: o.error ?? `Maximum ${l} file${l === 1 ? "" : "s"} allowed.`
111
+ return o === "single" && s.length > 1 ? s.slice(0, 1) : (l && l > 0 && s.length > l && (s = s.map((i, f) => f < l ? i : {
112
+ ...i,
113
+ error: i.error ?? `Maximum ${l} file${l === 1 ? "" : "s"} allowed.`
103
114
  })), s);
104
- }, [i, l, B, k, Z, H]), n = A(() => {
115
+ }, [o, l, w, k, H, M]), n = A(() => {
105
116
  let r;
106
117
  if (h) {
107
118
  const e = Array.isArray(D) ? D : D ? [D] : [];
108
- r = b(e);
119
+ r = O(e);
109
120
  } else
110
121
  r = C;
111
122
  return r.map((e) => ({
@@ -113,71 +124,72 @@ function Rr({
113
124
  // Validator errors take precedence over external errors
114
125
  error: e.error ?? (L == null ? void 0 : L[e.file.name])
115
126
  }));
116
- }, [h, D, b, C, L]), pr = g((r) => O ? O(r) : (r / 1024).toFixed(2) + " KB", [O]), N = A(() => q || (n == null ? void 0 : n.length) >= l || i === "single" && (n == null ? void 0 : n.length) > 0, [q, n, l, i]), W = g((r) => {
117
- const e = b(r);
127
+ }, [h, D, O, C, L]), fr = g((r) => S ? S(r) : (r / 1024).toFixed(2) + " KB", [S]), N = A(() => P || (n == null ? void 0 : n.length) >= l || o === "single" && (n == null ? void 0 : n.length) > 0, [P, n, l, o]), W = !!b, Q = g((r) => {
128
+ const e = O(r);
118
129
  if (h)
119
130
  m == null || m(e);
120
131
  else {
121
- const s = P ? [...C, ...e] : e;
122
- Y(s), m == null || m(s);
132
+ const s = V ? [...C, ...e] : e;
133
+ X(s), m == null || m(s);
123
134
  }
124
- }, [b, h, P, C, m]), mr = (r) => {
135
+ }, [O, h, V, C, m]), ur = (r) => {
125
136
  if (!r.target.files) return;
126
137
  const e = Array.from(r.target.files);
127
- W(e), r.target.value = "";
128
- }, w = g((r) => {
138
+ Q(e), r.target.value = "";
139
+ }, z = g((r) => {
129
140
  if (!(n != null && n.length) || r < 0 || r >= n.length) return;
130
- const e = n[r], s = n.filter((o, f) => f !== r);
131
- h || Y(s), I == null || I(e.file, s);
132
- }, [h, n, I]), F = A(() => new Map(n.map((r, e) => [e, () => w(e)])), [n, w]), {
133
- onDragOver: E,
134
- onDragLeave: z,
135
- onDrop: R,
136
- ...fr
137
- } = sr, ur = (r) => {
138
- N || (r.preventDefault(), G || S(!0), E == null || E(r));
139
- }, Dr = (r) => {
140
- r.preventDefault(), S(!1), z == null || z(r);
141
- }, hr = (r) => {
141
+ const e = n[r], s = n.filter((i, f) => f !== r);
142
+ h || X(s), I == null || I(e.file, s);
143
+ }, [h, n, I]), J = A(() => new Map(n.map((r, e) => [e, () => z(e)])), [n, z]), {
144
+ onDragOver: R,
145
+ onDragLeave: q,
146
+ onDrop: y,
147
+ ...Dr
148
+ } = lr, hr = (r) => {
149
+ N || (r.preventDefault(), Z || E(!0), R == null || R(r));
150
+ }, Nr = (r) => {
151
+ r.preventDefault(), E(!1), q == null || q(r);
152
+ }, Ar = (r) => {
142
153
  if (N) return;
143
154
  r.preventDefault();
144
155
  const e = Array.from(r.dataTransfer.files);
145
- W(e), r.dataTransfer.clearData(), S(!1), R == null || R(r);
156
+ Q(e), r.dataTransfer.clearData(), E(!1), y == null || y(r);
146
157
  };
147
- return /* @__PURE__ */ _("div", { className: U(d["drag-and-drop-container"], N && d.disabled, er), ...fr, children: [
148
- u && /* @__PURE__ */ _("label", { htmlFor: j, children: [
158
+ return /* @__PURE__ */ _("div", { className: rr(d["drag-and-drop-container"], N && d.disabled, nr), ...Dr, children: [
159
+ u && /* @__PURE__ */ _("label", { htmlFor: Y, children: [
149
160
  u,
150
- rr && /* @__PURE__ */ t("span", { "aria-hidden": "true", className: d.required, children: "*" })
161
+ ar && /* @__PURE__ */ t("span", { "aria-hidden": "true", className: d.required, children: "*" })
151
162
  ] }),
152
- /* @__PURE__ */ _("div", { className: U(d["drag-and-drop-space"], G && d.active), onDragOver: ur, onDragLeave: Dr, onDrop: hr, children: [
153
- /* @__PURE__ */ t(K, { type: "secondary", variant: "default", size: "sm", ...or, disabled: N, onClick: gr, icon: ir, children: lr() }),
154
- /* @__PURE__ */ t("input", { id: j, ref: y, type: "file", style: {
163
+ /* @__PURE__ */ _("div", { className: rr(d["drag-and-drop-space"], Z && d.active, W && d.error), onDragOver: hr, onDragLeave: Nr, onDrop: Ar, children: [
164
+ /* @__PURE__ */ t(x, { type: "secondary", variant: "default", size: "sm", ...tr, disabled: N, onClick: mr, icon: sr, children: _r() }),
165
+ /* @__PURE__ */ t("input", { id: Y, ref: G, type: "file", style: {
155
166
  display: "none"
156
- }, multiple: i === "multiple", accept: tr, onChange: mr }),
167
+ }, multiple: o === "multiple", accept: cr, onChange: ur }),
157
168
  /* @__PURE__ */ _("div", { className: d["drag-and-drop-space-text"], children: [
158
- /* @__PURE__ */ t("span", { className: d["drag-and-drop-space-text-message"], children: cr() }),
169
+ /* @__PURE__ */ t("span", { className: d["drag-and-drop-space-text-message"], children: gr() }),
159
170
  /* @__PURE__ */ _("span", { className: d["drag-and-drop-space-text-constraints"], children: [
160
171
  " ",
161
- _r()
172
+ pr()
162
173
  ] })
163
174
  ] })
164
175
  ] }),
165
- (n == null ? void 0 : n.length) > 0 && /* @__PURE__ */ t("ul", { className: d["drag-and-drop-files-list"], children: n == null ? void 0 : n.map((r, e) => V ? /* @__PURE__ */ t("li", { children: V(r, e, F.get(e) ?? (() => w(e))) }, e) : /* @__PURE__ */ t("li", { className: d["drag-and-drop-files-list-item"], children: /* @__PURE__ */ _("div", { className: d["drag-and-drop-files-list-item-content"], children: [
166
- /* @__PURE__ */ t("span", { className: d["drag-and-drop-files-list-item-icon-container"], children: /* @__PURE__ */ t(x, { icon: ar, className: d["drag-and-drop-files-list-item-icon"] }) }),
176
+ W && /* @__PURE__ */ t("span", { title: b, className: d["error-message"], children: b }),
177
+ (n == null ? void 0 : n.length) > 0 && /* @__PURE__ */ t("ul", { className: d["drag-and-drop-files-list"], children: n == null ? void 0 : n.map((r, e) => j ? /* @__PURE__ */ t("li", { children: j(r, e, J.get(e) ?? (() => z(e))) }, e) : /* @__PURE__ */ t("li", { className: d["drag-and-drop-files-list-item"], children: /* @__PURE__ */ _("div", { className: d["drag-and-drop-files-list-item-content"], children: [
178
+ /* @__PURE__ */ t("span", { className: d["drag-and-drop-files-list-item-icon-container"], children: /* @__PURE__ */ t(er, { icon: dr, className: d["drag-and-drop-files-list-item-icon"] }) }),
167
179
  /* @__PURE__ */ _("div", { className: d["drag-and-drop-files-list-item-content-data"], children: [
168
180
  /* @__PURE__ */ _("div", { className: d["drag-and-drop-files-list-item-text"], children: [
169
181
  /* @__PURE__ */ t("span", { className: d["drag-and-drop-files-list-item-name"], children: r.file.name }),
170
- /* @__PURE__ */ t("span", { className: d["drag-and-drop-files-list-item-size"], children: pr(r.file.size) }),
182
+ /* @__PURE__ */ t("span", { className: d["drag-and-drop-files-list-item-size"], children: fr(r.file.size) }),
171
183
  r.error && /* @__PURE__ */ _("span", { className: d["drag-and-drop-files-list-item-error"], children: [
172
- /* @__PURE__ */ t(x, { icon: nr, className: d["drag-and-drop-files-list-item-icon-error"] }),
184
+ /* @__PURE__ */ t(er, { icon: or, className: d["drag-and-drop-files-list-item-icon-error"] }),
173
185
  r.error
174
186
  ] })
175
187
  ] }),
176
- /* @__PURE__ */ t(K, { type: "tertiary", variant: "default", size: "sm", onClick: F.get(e), icon: dr, iconClassName: d["drag-and-drop-files-list-item-icon-delete"], "aria-label": `Remove ${r.file.name}` })
188
+ /* @__PURE__ */ t(x, { type: "tertiary", variant: "default", size: "sm", onClick: J.get(e), icon: ir, iconClassName: d["drag-and-drop-files-list-item-icon-delete"], "aria-label": `Remove ${r.file.name}` })
177
189
  ] })
178
190
  ] }) }, e)) })
179
191
  ] });
180
192
  }
181
193
  export {
182
- Rr as default
194
+ Pr as default
183
195
  };