@anoki/fse-marche-ui
Version:
FSE UI components library
142 lines (141 loc) • 4.47 kB
JavaScript
import { j as e } from "./index.es137.js";
import { useState as k } from "react";
import { Button as p } from "./index.es25.js";
import { clsx as r } from "./index.es139.js";
import './components/ui/DocumentUploadComponent/DocumentUploadComponent.css';/* empty css */
import { Col as R } from "./index.es10.js";
import { Close as v } from "./index.es79.js";
import { Attachment as z } from "./index.es112.js";
const O = ({
onFileUpload: a,
isLoading: d,
title: u,
description: f = "",
titleTag: x = "h3",
actionText: g = "Aggiungi",
className: h = "",
classNameTitle: b = "",
classNameDescription: j = "",
id: i = "fileInput",
name: y = "fileInput",
fileSizeLabel: N = "Dimensioni",
removeLabel: w = "RIMUOVI"
}) => {
const [l, m] = k(null), C = (t) => {
if (t.target.files && t.target.files.length > 0) {
const s = t.target.files[0];
m(s), a && s && I(s).then((o) => {
a(o, s.name, s.type);
});
}
}, I = (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);
}), B = () => {
m(null);
const t = document.getElementById(i);
t && (t.value = ""), a("", "", "");
};
return /* @__PURE__ */ e.jsxs(
R,
{
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 : u
}
),
/* @__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: i,
name: y,
style: { display: "none" },
onChange: C,
accept: ".pdf,.doc,.docx,.jpg,.jpeg,.png",
className: "fs-7",
required: !0
}
),
l ? /* @__PURE__ */ e.jsxs(
p,
{
size: "2",
textColor: "primary",
bg: "lightblue-a03",
className: "w-full ",
onClick: B,
disabled: d,
children: [
/* @__PURE__ */ e.jsx(v, {}),
/* @__PURE__ */ e.jsx("p", { className: "fs-6 fw-bold px-x8", children: w })
]
}
) : /* @__PURE__ */ e.jsxs(
p,
{
size: "2",
textColor: "primary",
bg: "lightblue-a03",
border: "primary",
className: "w-full",
onClick: () => {
var t;
return (t = document.getElementById(i)) == null ? void 0 : t.click();
},
disabled: d,
children: [
/* @__PURE__ */ e.jsx(z, { className: "mr-x8" }),
/* @__PURE__ */ e.jsx("p", { className: "fs-6 fw-bold", children: g })
]
}
)
] })
]
}
)
]
}
);
};
export {
O as DocumentUploadComponent
};
//# sourceMappingURL=index.es45.js.map