@alixpartners/ui-components 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,47 @@
1
+ import { ReactNode } from 'react';
1
2
  import { InteractiveEventHandlers } from '../../types/native-events';
2
3
  import { InputLabelTooltipProps } from '../Input/Input';
3
4
  export type UploadFile = {
4
5
  file: File;
5
6
  error?: string;
6
7
  };
8
+ export type FilePickerContextValue = {
9
+ id: string;
10
+ type: 'single' | 'multiple';
11
+ maxFiles: number;
12
+ fileExtensionsAllowed: string[];
13
+ fileExtensionsAllowedText: string;
14
+ maxSize: number;
15
+ queueFiles: boolean;
16
+ disabled: boolean;
17
+ isUploadDisabled: boolean;
18
+ uploadedFiles: UploadFile[];
19
+ isMaxFilesExceeded: boolean;
20
+ label: string;
21
+ required: boolean;
22
+ placeholder?: string;
23
+ errorMessage?: string;
24
+ helpText?: string;
25
+ helpLink?: string;
26
+ helpLinkText?: string;
27
+ multipleHelpText?: string;
28
+ multipleButtonHelpText?: string;
29
+ labelTooltip?: InputLabelTooltipProps;
30
+ accept: string;
31
+ inputRef: React.RefObject<HTMLInputElement | null>;
32
+ triggerInput: () => void;
33
+ handleKeyDown: (e: React.KeyboardEvent<HTMLDivElement>) => void;
34
+ handleRemoveFile: (fileName: string) => void;
35
+ displayFileSize: (size: number) => string;
36
+ };
37
+ declare function useFilePickerContext(): FilePickerContextValue;
7
38
  type FilePickerProps = {
8
39
  type?: 'single' | 'multiple';
9
40
  maxFiles?: number;
10
41
  fileExtensionsAllowed: string[];
11
42
  maxSize: number;
12
43
  queueFiles?: boolean;
44
+ isUploadDisabled?: boolean;
13
45
  disabled?: boolean;
14
46
  value?: File[];
15
47
  label: string;
@@ -19,30 +51,57 @@ type FilePickerProps = {
19
51
  helpText?: string;
20
52
  helpLink?: string;
21
53
  helpLinkText?: string;
54
+ multipleHelpText?: string;
55
+ multipleButtonHelpText?: string;
22
56
  labelTooltip?: InputLabelTooltipProps;
23
57
  onUpload?: (files: UploadFile[]) => void;
24
58
  onRemoveFile?: (fileName: string) => void;
59
+ children?: ReactNode;
25
60
  } & InteractiveEventHandlers;
26
61
  /**
27
- * FilePicker component for uploading files.
28
- *
29
- * @param {object} props - FilePicker component props
30
- * @param {'single' | 'multiple'} props.type - The type of file picker to display
31
- * @param {number} props.maxFiles - The maximum number of files to upload
32
- * @param {string[]} props.fileExtensionsAllowed - The allowed file extensions
33
- * @param {number} props.maxSize - The maximum file size in MB
34
- * @param {boolean} props.queueFiles - Whether to queue files
35
- * @param {boolean} props.disabled - Whether the component is disabled
36
- * @param {File[]} props.value - The value of the component
37
- * @param {string} props.label - The label of the component
38
- * @param {boolean} props.required - Whether the component is required
39
- * @param {string} props.placeholder - The placeholder of the component
40
- * @param {string} props.errorMessage - The error message of the component
41
- * @param {string} props.helpText - The help text of the component
42
- * @param {string} props.helpLink - The help link of the component
43
- * @param {string} props.helpLinkText - The help link text of the component
44
- * @param {InputLabelTooltipProps} props.labelTooltip - The label tooltip of the component
45
- * @returns {JSX.Element} The rendered FilePicker component
62
+ * FilePicker root. Use with no children for default layout, or compose with
63
+ * FilePicker.Label, FilePicker.BrowseButton, FilePicker.HelpText, FilePicker.UploadedFilesList, etc.
64
+ */
65
+ declare function FilePickerRoot({ type, maxFiles, fileExtensionsAllowed, maxSize, queueFiles, disabled, isUploadDisabled, value, label, required, placeholder, errorMessage, helpText, helpLink, helpLinkText, multipleHelpText, multipleButtonHelpText, labelTooltip, onUpload, onRemoveFile, children, }: FilePickerProps): import("react/jsx-runtime").JSX.Element;
66
+ type FilePickerLabelProps = {
67
+ /** Override label text. If not provided, uses FilePicker's label prop. */
68
+ children?: ReactNode;
69
+ };
70
+ declare function FilePickerLabel({ children }: FilePickerLabelProps): import("react/jsx-runtime").JSX.Element;
71
+ type FilePickerBrowseButtonProps = {
72
+ /** Override button content (e.g. "Browse file" or "Browse files (max 5)"). */
73
+ children?: ReactNode;
74
+ className?: string;
75
+ };
76
+ declare function FilePickerBrowseButton({ children, className }: FilePickerBrowseButtonProps): import("react/jsx-runtime").JSX.Element;
77
+ /**
78
+ * Wrapper for single-file mode: groups the input row and optional delete action.
79
+ * Use with FilePicker.SingleFileRow and FilePicker.SingleFileActions as children.
80
+ */
81
+ declare function FilePickerSingleFileContainer({ children }: {
82
+ children?: ReactNode;
83
+ }): import("react/jsx-runtime").JSX.Element | null;
84
+ /**
85
+ * Single-file mode: shows filename/placeholder and a slot for the browse button.
86
+ * Put FilePicker.BrowseButton (optionally wrapped in Tooltip) as children.
46
87
  */
47
- export default function FilePicker({ type, maxFiles, fileExtensionsAllowed, maxSize, queueFiles, disabled, value, label, required, placeholder, errorMessage, helpText, helpLink, helpLinkText, labelTooltip, onUpload, onRemoveFile, }: FilePickerProps): import("react/jsx-runtime").JSX.Element;
48
- export {};
88
+ declare function FilePickerSingleFileRow({ children }: {
89
+ children?: ReactNode;
90
+ }): import("react/jsx-runtime").JSX.Element | null;
91
+ /** Renders the reserved space and delete button for single-file mode (for use in composed layout). */
92
+ declare function FilePickerSingleFileActions(): import("react/jsx-runtime").JSX.Element | null;
93
+ declare function FilePickerSingleFileDeleteButton(): import("react/jsx-runtime").JSX.Element | null;
94
+ declare function FilePickerHelpText(): import("react/jsx-runtime").JSX.Element;
95
+ declare function FilePickerUploadedFilesList(): import("react/jsx-runtime").JSX.Element | null;
96
+ declare const FilePicker: typeof FilePickerRoot & {
97
+ Label: typeof FilePickerLabel;
98
+ BrowseButton: typeof FilePickerBrowseButton;
99
+ HelpText: typeof FilePickerHelpText;
100
+ UploadedFilesList: typeof FilePickerUploadedFilesList;
101
+ SingleFileContainer: typeof FilePickerSingleFileContainer;
102
+ SingleFileRow: typeof FilePickerSingleFileRow;
103
+ SingleFileActions: typeof FilePickerSingleFileActions;
104
+ SingleFileDeleteButton: typeof FilePickerSingleFileDeleteButton;
105
+ };
106
+ export { useFilePickerContext };
107
+ export default FilePicker;
@@ -1,155 +1,242 @@
1
- import { jsxs as n, jsx as t } from "react/jsx-runtime";
2
- import { useId as Q, useRef as W, useState as q, useEffect as Z } from "react";
3
- import U from "../Tooltip/Tooltip.js";
4
- import P from "../Icon/Icon.js";
5
- import h from "../Button/Button.js";
6
- import { c as ee } from "../../clsx-OuTLNxxd.js";
7
- import '../../assets/FilePicker.css';const ie = "FilePicker-module__container___knCCi", le = "FilePicker-module__label___al7Xe", te = "FilePicker-module__required___41Vjd", ne = "FilePicker-module__labelTooltipIcon___Cc1QF", se = "FilePicker-module__helpers___79-g5", ce = "FilePicker-module__helperText___ja9Rr", re = "FilePicker-module__errorMessage___TvHrL", me = "FilePicker-module__singleFileHelpLinkContainer___mpjUf", oe = "FilePicker-module__singleFileHelpLinkReservedSpace___r8j2b", ae = "FilePicker-module__helpLink___uu45D", ue = "FilePicker-module__input___cL1Hs", pe = "FilePicker-module__singleFileContainer___OFSDt", _e = "FilePicker-module__singleFileInputContainer___MOkES", Fe = "FilePicker-module__inputFileName___sMs7R", de = "FilePicker-module__inputFileNamePlaceholder___-mkDD", Ie = "FilePicker-module__inputButton___ghLlD", he = "FilePicker-module__multipleHelpText___5tnnn", Le = "FilePicker-module__multipleInputButton___WCJp9", ke = "FilePicker-module__multipleFilesList___Kim0I", fe = "FilePicker-module__multipleFilesListItem___01PDS", Ne = "FilePicker-module__multipleFilesListItemContent___pKbho", ge = "FilePicker-module__multipleFilesListItemContentData___5GC-C", Ce = "FilePicker-module__multipleFilesListItemIconContainer___7sUL5", Pe = "FilePicker-module__multipleFilesListItemIcon___nfMX9", xe = "FilePicker-module__multipleFilesListItemText___nPqrL", De = "FilePicker-module__multipleFilesListItemName___NjHhX", ve = "FilePicker-module__multipleFilesListItemSize___wc8LJ", Ee = "FilePicker-module__multipleFilesListItemError___x9qkT", Te = "FilePicker-module__multipleFilesListItemIconError___0RO46", Be = "FilePicker-module__multipleFilesListItemIconDelete___9Z9Dl", He = "FilePicker-module__disabled___szMiq", e = {
8
- container: ie,
9
- label: le,
10
- required: te,
11
- labelTooltipIcon: ne,
12
- helpers: se,
13
- helperText: ce,
14
- errorMessage: re,
15
- singleFileHelpLinkContainer: me,
16
- singleFileHelpLinkReservedSpace: oe,
17
- helpLink: ae,
18
- input: ue,
19
- singleFileContainer: pe,
20
- singleFileInputContainer: _e,
21
- inputFileName: Fe,
22
- inputFileNamePlaceholder: de,
23
- inputButton: Ie,
24
- multipleHelpText: he,
25
- multipleInputButton: Le,
26
- multipleFilesList: ke,
27
- multipleFilesListItem: fe,
28
- multipleFilesListItemContent: Ne,
29
- multipleFilesListItemContentData: ge,
30
- multipleFilesListItemIconContainer: Ce,
31
- multipleFilesListItemIcon: Pe,
32
- multipleFilesListItemText: xe,
33
- multipleFilesListItemName: De,
34
- multipleFilesListItemSize: ve,
35
- multipleFilesListItemError: Ee,
36
- multipleFilesListItemIconError: Te,
37
- multipleFilesListItemIconDelete: Be,
38
- disabled: He
39
- };
40
- function qe({
41
- type: r = "single",
42
- maxFiles: F = 1,
43
- fileExtensionsAllowed: L,
44
- maxSize: p,
45
- queueFiles: R = !1,
46
- disabled: s = !1,
47
- value: d,
48
- label: x,
49
- required: K = !1,
50
- placeholder: V,
51
- errorMessage: a,
52
- helpText: k,
53
- helpLink: D,
54
- helpLinkText: v,
55
- labelTooltip: o,
56
- onUpload: u,
57
- onRemoveFile: f
1
+ import { jsxs as a, jsx as i, Fragment as ne } from "react/jsx-runtime";
2
+ import { createContext as se, useId as re, useRef as oe, useState as v, useCallback as _, useEffect as ce, useContext as ae } from "react";
3
+ import pe from "../Tooltip/Tooltip.js";
4
+ import D from "../Icon/Icon.js";
5
+ import x from "../Button/Button.js";
6
+ import { c as C } from "../../clsx-OuTLNxxd.js";
7
+ import '../../assets/FilePicker.css';const ue = "FilePicker-module__container___knCCi", me = "FilePicker-module__label___al7Xe", de = "FilePicker-module__required___41Vjd", Fe = "FilePicker-module__labelTooltipIcon___Cc1QF", _e = "FilePicker-module__helpers___79-g5", Ie = "FilePicker-module__helperText___ja9Rr", he = "FilePicker-module__errorMessage___TvHrL", Le = "FilePicker-module__singleFileHelpLinkContainer___mpjUf", ge = "FilePicker-module__singleFileHelpLinkReservedSpace___r8j2b", ke = "FilePicker-module__helpLink___uu45D", fe = "FilePicker-module__input___cL1Hs", Pe = "FilePicker-module__singleFileContainer___OFSDt", Ne = "FilePicker-module__singleFileInputContainer___MOkES", xe = "FilePicker-module__inputFileName___sMs7R", Ce = "FilePicker-module__inputFileNamePlaceholder___-mkDD", Te = "FilePicker-module__inputButton___ghLlD", be = "FilePicker-module__multipleHelpText___5tnnn", ye = "FilePicker-module__multipleInputButton___WCJp9", De = "FilePicker-module__multipleFilesList___Kim0I", Be = "FilePicker-module__multipleFilesListItem___01PDS", Se = "FilePicker-module__multipleFilesListItemContent___pKbho", He = "FilePicker-module__multipleFilesListItemContentData___5GC-C", ve = "FilePicker-module__multipleFilesListItemIconContainer___7sUL5", we = "FilePicker-module__multipleFilesListItemIcon___nfMX9", Me = "FilePicker-module__multipleFilesListItemText___nPqrL", Ee = "FilePicker-module__multipleFilesListItemName___NjHhX", ze = "FilePicker-module__multipleFilesListItemSize___wc8LJ", Re = "FilePicker-module__multipleFilesListItemError___x9qkT", je = "FilePicker-module__multipleFilesListItemIconError___0RO46", Ke = "FilePicker-module__multipleFilesListItemIconDelete___9Z9Dl", Ve = "FilePicker-module__disabled___szMiq", t = {
8
+ container: ue,
9
+ label: me,
10
+ required: de,
11
+ labelTooltipIcon: Fe,
12
+ helpers: _e,
13
+ helperText: Ie,
14
+ errorMessage: he,
15
+ singleFileHelpLinkContainer: Le,
16
+ singleFileHelpLinkReservedSpace: ge,
17
+ helpLink: ke,
18
+ input: fe,
19
+ singleFileContainer: Pe,
20
+ singleFileInputContainer: Ne,
21
+ inputFileName: xe,
22
+ inputFileNamePlaceholder: Ce,
23
+ inputButton: Te,
24
+ multipleHelpText: be,
25
+ multipleInputButton: ye,
26
+ multipleFilesList: De,
27
+ multipleFilesListItem: Be,
28
+ multipleFilesListItemContent: Se,
29
+ multipleFilesListItemContentData: He,
30
+ multipleFilesListItemIconContainer: ve,
31
+ multipleFilesListItemIcon: we,
32
+ multipleFilesListItemText: Me,
33
+ multipleFilesListItemName: Ee,
34
+ multipleFilesListItemSize: ze,
35
+ multipleFilesListItemError: Re,
36
+ multipleFilesListItemIconError: je,
37
+ multipleFilesListItemIconDelete: Ke,
38
+ disabled: Ve
39
+ }, w = se(null);
40
+ function p() {
41
+ const e = ae(w);
42
+ if (!e)
43
+ throw new Error("FilePicker compound components must be used within a FilePicker.");
44
+ return e;
45
+ }
46
+ function qe(e) {
47
+ const l = e.name.toLowerCase();
48
+ return l.includes(".") ? l.split(".").pop() ?? "" : "";
49
+ }
50
+ function $e({
51
+ type: e = "single",
52
+ maxFiles: l = 1,
53
+ fileExtensionsAllowed: s,
54
+ maxSize: r,
55
+ queueFiles: h = !1,
56
+ disabled: c = !1,
57
+ isUploadDisabled: E = !1,
58
+ value: L,
59
+ label: z,
60
+ required: R = !1,
61
+ placeholder: j,
62
+ errorMessage: K,
63
+ helpText: V,
64
+ helpLink: q,
65
+ helpLinkText: $,
66
+ multipleHelpText: O,
67
+ multipleButtonHelpText: A,
68
+ labelTooltip: X,
69
+ onUpload: F,
70
+ onRemoveFile: g,
71
+ children: k
58
72
  }) {
59
- var M, j;
60
- const E = Q(), N = W(null), [l, I] = q(d ? d.map((i) => ({
61
- file: i
62
- })) : []), [T, B] = q(!1);
63
- Z(() => {
64
- const i = S(d ?? []);
65
- I(i);
66
- }, [d]);
67
- const O = L.map((i) => `.${i.replace(/^\./, "")}`).join(","), H = L.join(", "), $ = (i) => {
68
- const c = i.name.toLowerCase();
69
- return c.includes(".") ? c.split(".").pop() ?? "" : "";
70
- }, S = (i) => {
71
- const m = l.length + i.length > F;
72
- B(m);
73
- const g = p ? p * 1024 * 1024 : Number.POSITIVE_INFINITY, b = new Set(L.map((_) => _.toLowerCase().replace(/^\./, "")));
74
- return i.map((_) => {
75
- const J = _.size <= g, Y = b.size === 0 || b.has($(_));
76
- let C;
77
- const G = p ? `up to ${p}MB` : "";
78
- return J || (C = `File size is too large. Must be ${G}.`), Y || (C = `The file format is incorrect. Please make sure it is one of the extensions: ${H}.`), {
79
- file: _,
80
- error: C
73
+ const B = re(), f = oe(null), [u, P] = v(L ? L.map((n) => ({
74
+ file: n
75
+ })) : []), [J, T] = v(!1), b = s.join(", "), S = s.map((n) => `.${n.replace(/^\./, "")}`).join(","), N = _((n) => {
76
+ const o = r ? r * 1024 * 1024 : Number.POSITIVE_INFINITY, m = new Set(s.map((d) => d.toLowerCase().replace(/^\./, "")));
77
+ return n.map((d) => {
78
+ const le = d.size <= o, ie = m.size === 0 || m.has(qe(d));
79
+ let y;
80
+ const te = r ? `up to ${r}MB` : "";
81
+ return le || (y = `File size is too large. Must be ${te}.`), ie || (y = `The file format is incorrect. Please make sure it is one of the extensions: ${b}.`), {
82
+ file: d,
83
+ error: y
81
84
  };
82
85
  });
83
- }, X = (i) => (i / 1024).toFixed(2) + " KB", z = () => {
84
- var i;
85
- s || (i = N.current) == null || i.click();
86
- }, w = (i) => {
87
- var c;
88
- s || i.key === "Enter" && ((c = N.current) == null || c.click());
89
- }, A = (i) => {
90
- if (s) return;
91
- const c = i.target.files, m = S(Array.from(c ?? []));
92
- r === "multiple" && R ? (I([...l, ...m]), u == null || u(m)) : (I(m), u == null || u(m)), i.target.value = "";
93
- }, y = (i) => {
94
- if (s || !l) return;
95
- const m = l.length - 1 > F;
96
- B(m), I(l == null ? void 0 : l.filter((g) => g.file.name !== i)), f == null || f(i);
97
- };
98
- return /* @__PURE__ */ n("div", { className: ee(e.container, s && e.disabled), children: [
99
- /* @__PURE__ */ n("label", { htmlFor: E, onClick: (i) => i.preventDefault(), className: e.label, children: [
100
- /* @__PURE__ */ t("span", { title: x, className: e.labelText, children: x }),
101
- K && /* @__PURE__ */ t("span", { "aria-hidden": "true", className: e.required, children: "*" }),
102
- o && /* @__PURE__ */ t(U, { content: o.content, size: o.size, theme: o.theme, tipSide: o.tipSide, tipAlignment: o.tipAlignment, startVisible: o.startVisible, children: /* @__PURE__ */ t(P, { icon: "ap-icon-info", className: e.labelTooltipIcon }) }),
103
- r === "multiple" && /* @__PURE__ */ n("span", { className: e.multipleHelpText, children: [
104
- "Only ",
105
- H,
106
- " files with max size of ",
107
- p,
108
- "MB"
109
- ] })
110
- ] }),
111
- /* @__PURE__ */ t("input", { accept: O, multiple: r === "multiple", ref: N, type: "file", id: E, className: e.input, onChange: A }),
112
- r === "single" && /* @__PURE__ */ n("div", { className: e.singleFileContainer, children: [
113
- /* @__PURE__ */ n("div", { tabIndex: s ? -1 : 0, onClick: z, onKeyDown: w, className: e.singleFileInputContainer, children: [
114
- /* @__PURE__ */ n("span", { className: e.inputFileName, children: [
115
- l && l.length > 0 && /* @__PURE__ */ t("span", { className: e.inputFileNameText, children: l[0].file.name }),
116
- l && l.length === 0 && /* @__PURE__ */ t("span", { className: e.inputFileNamePlaceholder, children: V })
117
- ] }),
118
- /* @__PURE__ */ t(h, { type: "tertiary", variant: "default", size: "md", icon: "ap-icon-upload", className: e.inputButton, tabIndex: -1, disabled: s, children: /* @__PURE__ */ t("span", { children: "Browse file" }) })
119
- ] }),
120
- /* @__PURE__ */ t("span", { className: e.singleFileHelpLinkReservedSpace, children: l && l.length > 0 && /* @__PURE__ */ t(h, { type: "tertiary", variant: "default", size: "md", icon: "ap-icon-delete", className: e.singleFileDeleteButton, onClick: () => y(l[0].file.name), disabled: s }) })
121
- ] }),
122
- r === "multiple" && /* @__PURE__ */ t(h, { type: "secondary", variant: "default", size: "md", icon: "ap-icon-upload", className: e.multipleInputButton, onClick: z, onKeyDown: w, disabled: s, children: /* @__PURE__ */ n("span", { children: [
123
- "Browse files (max ",
124
- F,
125
- " files)"
126
- ] }) }),
127
- /* @__PURE__ */ n("div", { className: e.helpers, children: [
128
- a || T || (M = l[0]) != null && M.error ? /* @__PURE__ */ n("span", { title: a, className: e.errorMessage, children: [
129
- r === "single" && (a || ((j = l[0]) == null ? void 0 : j.error)),
130
- r === "multiple" && (a || (T ? `You can only upload up to ${F} files.` : ""))
131
- ] }) : k && r === "single" && /* @__PURE__ */ t("span", { title: k, className: e.helperText, children: k }),
132
- r === "single" && D && v && /* @__PURE__ */ n("span", { className: e.singleFileHelpLinkContainer, children: [
133
- /* @__PURE__ */ t("a", { href: D, className: e.helpLink, target: "_blank", rel: "noopener noreferrer", tabIndex: s ? -1 : 0, children: v }),
134
- /* @__PURE__ */ t("span", { className: e.singleFileHelpLinkReservedSpace })
135
- ] })
136
- ] }),
137
- r === "multiple" && l && (l == null ? void 0 : l.length) > 0 && /* @__PURE__ */ t("ul", { className: e.multipleFilesList, children: l == null ? void 0 : l.map((i, c) => /* @__PURE__ */ t("li", { className: e.multipleFilesListItem, children: /* @__PURE__ */ n("div", { className: e.multipleFilesListItemContent, children: [
138
- /* @__PURE__ */ t("span", { className: e.multipleFilesListItemIconContainer, children: /* @__PURE__ */ t(P, { icon: "ap-icon-document", className: e.multipleFilesListItemIcon }) }),
139
- /* @__PURE__ */ n("div", { className: e.multipleFilesListItemContentData, children: [
140
- /* @__PURE__ */ n("div", { className: e.multipleFilesListItemText, children: [
141
- /* @__PURE__ */ t("span", { className: e.multipleFilesListItemName, children: i.file.name }),
142
- /* @__PURE__ */ t("span", { className: e.multipleFilesListItemSize, children: X(i.file.size) }),
143
- i.error && /* @__PURE__ */ n("span", { className: e.multipleFilesListItemError, children: [
144
- /* @__PURE__ */ t(P, { icon: "ap-icon-alert", className: e.multipleFilesListItemIconError }),
145
- i.error
146
- ] })
147
- ] }),
148
- /* @__PURE__ */ t(h, { type: "tertiary", variant: "default", size: "sm", onClick: () => y(i.file.name), icon: "ap-icon-delete", iconClassName: e.multipleFilesListItemIconDelete, disabled: s })
149
- ] })
150
- ] }) }, c)) })
86
+ }, [s, b, r]), H = _((n) => {
87
+ const o = u.length;
88
+ return T(o + n.length > l), N(n);
89
+ }, [l, u.length, N]);
90
+ ce(() => {
91
+ const n = N(L ?? []);
92
+ P(n), T(n.length > l);
93
+ }, [L, l, N]);
94
+ const Y = _((n) => (n / 1024).toFixed(2) + " KB", []), G = _(() => {
95
+ var n;
96
+ c || (n = f.current) == null || n.click();
97
+ }, [c]), Q = _((n) => {
98
+ var o;
99
+ c || n.key === "Enter" && ((o = f.current) == null || o.click());
100
+ }, [c]), W = _((n) => {
101
+ if (c) return;
102
+ const o = n.target.files, m = H(Array.from(o ?? []));
103
+ if (e === "multiple" && h) {
104
+ const d = [...u, ...m];
105
+ P(d), F == null || F(d);
106
+ } else
107
+ P(m), F == null || F(m);
108
+ n.target.value = "";
109
+ }, [c, e, h, u, H, F]), Z = _((n) => {
110
+ if (c || !u) return;
111
+ const o = u.filter((m) => m.file.name !== n);
112
+ T(o.length > l), P(o), g == null || g(n);
113
+ }, [c, u, l, g]), U = {
114
+ id: B,
115
+ type: e,
116
+ maxFiles: l,
117
+ fileExtensionsAllowed: s,
118
+ fileExtensionsAllowedText: b,
119
+ maxSize: r,
120
+ queueFiles: h,
121
+ disabled: c,
122
+ isUploadDisabled: E,
123
+ uploadedFiles: u,
124
+ isMaxFilesExceeded: J,
125
+ label: z,
126
+ required: R,
127
+ placeholder: j,
128
+ errorMessage: K,
129
+ helpText: V,
130
+ helpLink: q,
131
+ helpLinkText: $,
132
+ multipleHelpText: O,
133
+ multipleButtonHelpText: A,
134
+ labelTooltip: X,
135
+ accept: S,
136
+ inputRef: f,
137
+ triggerInput: G,
138
+ handleKeyDown: Q,
139
+ handleRemoveFile: Z,
140
+ displayFileSize: Y
141
+ }, ee = k != null && (Array.isArray(k) ? k.length > 0 : !0);
142
+ return /* @__PURE__ */ a(w.Provider, { value: U, children: [
143
+ /* @__PURE__ */ i("input", { accept: S, multiple: e === "multiple", ref: f, type: "file", id: B, className: t.input, onChange: W }),
144
+ /* @__PURE__ */ i("div", { className: C(t.container, c && t.disabled), children: ee ? k : /* @__PURE__ */ i(Oe, {}) })
145
+ ] });
146
+ }
147
+ function Oe() {
148
+ const e = p();
149
+ return /* @__PURE__ */ a(ne, { children: [
150
+ /* @__PURE__ */ i(I.Label, {}),
151
+ e.type === "single" && /* @__PURE__ */ i(I.SingleFileRow, { children: /* @__PURE__ */ i(I.BrowseButton, {}) }),
152
+ e.type === "single" && e.uploadedFiles.length > 0 && /* @__PURE__ */ i("span", { className: t.singleFileHelpLinkReservedSpace, children: /* @__PURE__ */ i(I.SingleFileDeleteButton, {}) }),
153
+ e.type === "multiple" && /* @__PURE__ */ i(I.BrowseButton, {}),
154
+ /* @__PURE__ */ i(I.HelpText, {}),
155
+ /* @__PURE__ */ i(I.UploadedFilesList, {})
156
+ ] });
157
+ }
158
+ function Ae({
159
+ children: e
160
+ }) {
161
+ const l = p(), s = e ?? l.label;
162
+ return /* @__PURE__ */ a("label", { htmlFor: l.id, onClick: (r) => r.preventDefault(), className: C(t.label, l.type === "multiple" && t.labelMultiple), children: [
163
+ /* @__PURE__ */ i("span", { title: l.label, className: t.labelText, children: s }),
164
+ l.required && /* @__PURE__ */ i("span", { "aria-hidden": "true", className: t.required, children: "*" }),
165
+ l.labelTooltip && /* @__PURE__ */ i(pe, { content: l.labelTooltip.content, size: l.labelTooltip.size, theme: l.labelTooltip.theme, tipSide: l.labelTooltip.tipSide, tipAlignment: l.labelTooltip.tipAlignment, startVisible: l.labelTooltip.startVisible, children: /* @__PURE__ */ i(D, { icon: "ap-icon-info", className: t.labelTooltipIcon }) }),
166
+ l.type === "multiple" && l.multipleHelpText && /* @__PURE__ */ i("span", { className: t.multipleHelpText, children: l.multipleHelpText })
167
+ ] });
168
+ }
169
+ function Xe({
170
+ children: e,
171
+ className: l
172
+ }) {
173
+ const s = p();
174
+ return s.type === "multiple" ? /* @__PURE__ */ i(x, { type: "secondary", variant: "default", size: "md", icon: "ap-icon-upload", className: C(t.multipleInputButton, l), onClick: s.triggerInput, onKeyDown: s.handleKeyDown, disabled: s.disabled || s.isUploadDisabled, children: /* @__PURE__ */ i("span", { children: e ?? `Browse files ${s.multipleButtonHelpText ?? ""}` }) }) : /* @__PURE__ */ i(x, { type: "tertiary", variant: "default", size: "md", icon: "ap-icon-upload", className: C(t.inputButton, l), tabIndex: -1, disabled: s.disabled || s.isUploadDisabled, onClick: (r) => {
175
+ r.preventDefault(), r.stopPropagation(), s.triggerInput();
176
+ }, children: /* @__PURE__ */ i("span", { children: e ?? "Browse file" }) });
177
+ }
178
+ function Je({
179
+ children: e
180
+ }) {
181
+ return p().type !== "single" ? null : /* @__PURE__ */ i("div", { className: t.singleFileContainer, children: e });
182
+ }
183
+ function Ye({
184
+ children: e
185
+ }) {
186
+ const l = p();
187
+ return l.type !== "single" ? null : /* @__PURE__ */ a("div", { tabIndex: l.disabled ? -1 : 0, onClick: l.triggerInput, onKeyDown: l.handleKeyDown, className: t.singleFileInputContainer, children: [
188
+ /* @__PURE__ */ i("span", { className: t.inputFileName, children: l.uploadedFiles.length > 0 ? /* @__PURE__ */ i("span", { className: t.inputFileNameText, children: l.uploadedFiles[0].file.name }) : /* @__PURE__ */ i("span", { className: t.inputFileNamePlaceholder, children: l.placeholder }) }),
189
+ e
151
190
  ] });
152
191
  }
192
+ function Ge() {
193
+ return p().type !== "single" ? null : /* @__PURE__ */ i("span", { className: t.singleFileHelpLinkReservedSpace, children: /* @__PURE__ */ i(M, {}) });
194
+ }
195
+ function M() {
196
+ const e = p();
197
+ if (e.type !== "single" || e.uploadedFiles.length === 0) return null;
198
+ const l = e.uploadedFiles[0].file.name;
199
+ return /* @__PURE__ */ i(x, { type: "tertiary", variant: "default", size: "md", icon: "ap-icon-delete", className: t.singleFileDeleteButton, onClick: () => e.handleRemoveFile(l), disabled: e.disabled });
200
+ }
201
+ function Qe() {
202
+ var r, h;
203
+ const e = p(), l = e.errorMessage || e.isMaxFilesExceeded || e.type === "single" && ((r = e.uploadedFiles[0]) == null ? void 0 : r.error), s = e.type === "single" ? e.errorMessage || ((h = e.uploadedFiles[0]) == null ? void 0 : h.error) : e.errorMessage || (e.isMaxFilesExceeded ? `You can only upload up to ${e.maxFiles} files.` : "");
204
+ return /* @__PURE__ */ a("div", { className: t.helpers, children: [
205
+ l ? /* @__PURE__ */ i("span", { title: e.errorMessage, className: t.errorMessage, children: s }) : e.helpText && e.type === "single" && /* @__PURE__ */ i("span", { title: e.helpText, className: t.helperText, children: e.helpText }),
206
+ e.type === "single" && e.helpLink && e.helpLinkText && /* @__PURE__ */ a("span", { className: t.singleFileHelpLinkContainer, children: [
207
+ /* @__PURE__ */ i("a", { href: e.helpLink, className: t.helpLink, target: "_blank", rel: "noopener noreferrer", tabIndex: e.disabled ? -1 : 0, children: e.helpLinkText }),
208
+ /* @__PURE__ */ i("span", { className: t.singleFileHelpLinkReservedSpace })
209
+ ] })
210
+ ] });
211
+ }
212
+ function We() {
213
+ const e = p();
214
+ return e.type !== "multiple" || !e.uploadedFiles.length ? null : /* @__PURE__ */ i("ul", { className: t.multipleFilesList, children: e.uploadedFiles.map((l, s) => /* @__PURE__ */ i("li", { className: t.multipleFilesListItem, children: /* @__PURE__ */ a("div", { className: t.multipleFilesListItemContent, children: [
215
+ /* @__PURE__ */ i("span", { className: t.multipleFilesListItemIconContainer, children: /* @__PURE__ */ i(D, { icon: "ap-icon-document", className: t.multipleFilesListItemIcon }) }),
216
+ /* @__PURE__ */ a("div", { className: t.multipleFilesListItemContentData, children: [
217
+ /* @__PURE__ */ a("div", { className: t.multipleFilesListItemText, children: [
218
+ /* @__PURE__ */ i("span", { className: t.multipleFilesListItemName, children: l.file.name }),
219
+ /* @__PURE__ */ i("span", { className: t.multipleFilesListItemSize, children: e.displayFileSize(l.file.size) }),
220
+ l.error && /* @__PURE__ */ a("span", { className: t.multipleFilesListItemError, children: [
221
+ /* @__PURE__ */ i(D, { icon: "ap-icon-alert", className: t.multipleFilesListItemIconError }),
222
+ l.error
223
+ ] })
224
+ ] }),
225
+ /* @__PURE__ */ i(x, { type: "tertiary", variant: "default", size: "sm", onClick: () => e.handleRemoveFile(l.file.name), icon: "ap-icon-delete", iconClassName: t.multipleFilesListItemIconDelete, disabled: e.disabled })
226
+ ] })
227
+ ] }) }, s)) });
228
+ }
229
+ const I = Object.assign($e, {
230
+ Label: Ae,
231
+ BrowseButton: Xe,
232
+ HelpText: Qe,
233
+ UploadedFilesList: We,
234
+ SingleFileContainer: Je,
235
+ SingleFileRow: Ye,
236
+ SingleFileActions: Ge,
237
+ SingleFileDeleteButton: M
238
+ });
153
239
  export {
154
- qe as default
240
+ I as default,
241
+ p as useFilePickerContext
155
242
  };