@adyen/adyen-platform-experience-web
Version:

54 lines (53 loc) • 2 kB
JavaScript
import { jsx as d } from "../../../../external/preact/jsx-runtime/dist/jsxRuntime.module.js";
import S from "../../../../core/Context/useCoreContext.js";
import { useState as y, useRef as M, useCallback as c, useMemo as T, useEffect as b } from "../../../../external/preact/hooks/dist/hooks.module.js";
import { UploadedFile as v } from "./components/UploadedFile.js";
import { Dropzone as w } from "./components/Dropzone.js";
import { validationErrors as l, BASE_CLASS as O } from "./constants.js";
/* empty css */
import { fixedForwardRef as Y } from "../../../../utils/preact/fixedForwardRef.js";
import { isFunction as g } from "../../../../utils/value/is.js";
const Q = Y(({ onChange: s, mapError: a, onDelete: u, ...f }, I) => {
const [r, p] = y([]), m = M(r), n = r[0], { i18n: i } = S(), { disabled: o } = f, L = c(
(e) => {
switch (e) {
case l.DISALLOWED_FILE_TYPE:
return i.get("inputError.disallowedFileType");
case l.FILE_REQUIRED:
return i.get("inputError.fileRequired");
case l.TOO_MANY_FILES:
return i.get("inputError.tooManyFiles");
case l.VERY_LARGE_FILE:
return i.get("inputError.veryLargeFile");
}
},
[i]
), _ = T(() => g(a) ? a : L, [a]), R = c(
(e) => {
o || (p((t) => {
const E = t.findIndex((A) => A === e);
if (E < 0)
return t;
const [...F] = t;
return F.splice(E, 1), F;
}), u == null || u());
},
[o, u]
), x = c(
(e) => {
o || p((t) => t.length === 0 && e.length === 0 ? t : e);
},
[o]
);
return b(() => {
m.current !== r && (m.current = r, s == null || s([...r]));
}, [r, s]), /* @__PURE__ */ d("div", {
className: O,
// prettier-ignore
children: n ? /* @__PURE__ */ d(v, { disabled: o, file: n, deleteFile: () => R(n) }) : /* @__PURE__ */ d(w, { ...f, ref: I, mapError: _, uploadFiles: x })
});
});
export {
Q as FileInput,
Q as default
};