UNPKG

@anoki/fse-ui

Version:

FSE UI components library

143 lines (142 loc) 4.49 kB
import { j as e } from "./index.es237.js"; import { useState as R } from "react"; import { Button as u } from "./index.es32.js"; import { clsx as r } from "./index.es238.js"; import './components/ui/DocumentUploadComponent/DocumentUploadComponent.css';/* empty css */ import { Attachment as v } from "./index.es169.js"; import { Col as z } from "./index.es61.js"; import { Close as A } from "./index.es179.js"; const P = ({ onFileUpload: i, isLoading: d, title: p, description: f = "", titleTag: x = "h1", actionText: g = "Aggiungi", className: h = "", classNameTitle: b = "", classNameDescription: j = "", id: a = "fileInput", name: y = "fileInput", fileSizeLabel: N = "Dimensioni", removeLabel: w = "RIMUOVI", accept: C = ".pdf,.doc,.docx,.jpg,.jpeg,.png" }) => { const [l, m] = R(null), I = (t) => { if (t.target.files && t.target.files.length > 0) { const s = t.target.files[0]; m(s), i && s && B(s).then((o) => { i(o, s.name, s.type); }); } }, B = (t) => new Promise((s, o) => { const n = new FileReader(); n.readAsDataURL(t), n.onload = () => { if (typeof n.result == "string") { const c = n.result.split(",")[1]; s(c); } }, n.onerror = (c) => o(c); }), k = () => { m(null); const t = document.getElementById(a); t && (t.value = ""), i("", "", ""); }; return /* @__PURE__ */ e.jsxs( z, { br: "x4", gap: "x16", bg: "lightblue-a03", className: r(h, "ui-banner-upload shadow"), children: [ /* @__PURE__ */ e.jsx( x, { className: r( l ? "text-primary" : "text-slate-20", "ui-banner-title-upload ", b || "fs-4 fw-bold" ), children: l ? l.name : p } ), /* @__PURE__ */ e.jsxs( "main", { className: r( "ui-banner-content-upload fs-6 text-secondary w-100 ui-banner-content-layout1-upload text-secondary justify-content-between" ), children: [ /* @__PURE__ */ e.jsx( "div", { className: r(j, "ui-banner-description-upload"), children: l ? /* @__PURE__ */ e.jsxs("div", { children: [ N, ": ", (l.size / (1024 * 1024)).toFixed(2), " ", "MB" ] }) : f } ), /* @__PURE__ */ e.jsxs("div", { className: r("ui-banner-link-upload"), children: [ /* @__PURE__ */ e.jsx( "input", { type: "file", id: a, name: y, style: { display: "none" }, onChange: I, accept: C, className: "fs-7", required: !0 } ), l ? /* @__PURE__ */ e.jsxs( u, { size: "2", textColor: "primary", bg: "lightblue-a03", className: "w-full ", onClick: k, disabled: d, children: [ /* @__PURE__ */ e.jsx(A, {}), /* @__PURE__ */ e.jsx("p", { className: "fs-6 fw-bold px-x8", children: w }) ] } ) : /* @__PURE__ */ e.jsxs( u, { size: "2", textColor: "primary", bg: "lightblue-a03", border: "primary", className: "w-full", onClick: () => { var t; return (t = document.getElementById(a)) == null ? void 0 : t.click(); }, disabled: d, children: [ /* @__PURE__ */ e.jsx(v, { className: "mr-x8" }), /* @__PURE__ */ e.jsx("p", { className: "fs-6 fw-bold", children: g }) ] } ) ] }) ] } ) ] } ); }; export { P as DocumentUploadComponent }; //# sourceMappingURL=index.es78.js.map