analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
108 lines (97 loc) • 4.62 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunk34ST3MKOjs = require('./chunk-34ST3MKO.js');
var _chunkANT66KVKjs = require('./chunk-ANT66KVK.js');
var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js');
// src/components/FileAttachment/FileAttachment.tsx
var _react = require('react');
var _Paperclip = require('@phosphor-icons/react/dist/csr/Paperclip');
var _FileText = require('@phosphor-icons/react/dist/csr/FileText');
var _X = require('@phosphor-icons/react/dist/csr/X');
var _jsxruntime = require('react/jsx-runtime');
var formatFileSize = (bytes) => {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
if (bytes < 1024 * 1024 * 1024)
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
};
var generateFileId = () => {
return crypto.randomUUID();
};
var FileAttachment = ({
files,
onFilesAdd,
onFileRemove,
readOnly = false,
buttonLabel = "Anexar",
multiple = true,
className,
hideButton = false
}) => {
const fileInputRef = _react.useRef.call(void 0, null);
const handleFileChange = (event) => {
const selectedFiles = event.target.files;
if (selectedFiles && selectedFiles.length > 0) {
const filesArray = Array.from(selectedFiles);
onFilesAdd(filesArray);
}
if (fileInputRef.current) {
fileInputRef.current.value = "";
}
};
const handleAttachClick = () => {
_optionalChain([fileInputRef, 'access', _ => _.current, 'optionalAccess', _2 => _2.click, 'call', _3 => _3()]);
};
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: _chunkTN3AYOMVjs.cn.call(void 0, "flex flex-col gap-2", className), children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"input",
{
type: "file",
ref: fileInputRef,
className: "hidden",
onChange: handleFileChange,
multiple,
"aria-label": "Selecionar arquivos"
}
),
!readOnly && !hideButton && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
_chunk34ST3MKOjs.Button_default,
{
type: "button",
variant: "outline",
size: "small",
onClick: handleAttachClick,
className: "self-start flex items-center gap-2",
children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _Paperclip.PaperclipIcon, { size: 16 }),
buttonLabel
]
}
),
files.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex flex-wrap gap-2", children: files.map((attachedFile) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
"div",
{
className: "flex items-center gap-2 bg-background-50 px-3 py-2 rounded-lg border border-border-100",
children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _FileText.FileTextIcon, { size: 16, className: "text-text-500 shrink-0" }),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { className: "text-sm text-text-700 truncate max-w-[200px]", children: attachedFile.file.name }),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { className: "text-xs text-text-400 shrink-0", children: formatFileSize(attachedFile.file.size) }),
!readOnly && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"button",
{
type: "button",
onClick: () => onFileRemove(attachedFile.id),
className: "text-text-400 hover:text-error-500 transition-colors shrink-0",
"aria-label": `Remover ${attachedFile.file.name}`,
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _X.XIcon, { size: 14 })
}
)
]
},
attachedFile.id
)) })
] });
};
var FileAttachment_default = FileAttachment;
exports.formatFileSize = formatFileSize; exports.generateFileId = generateFileId; exports.FileAttachment_default = FileAttachment_default;
//# sourceMappingURL=chunk-CMW67SFK.js.map