analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
144 lines (126 loc) • 5.64 kB
JavaScript
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunkNEDUOGWUjs = require('./chunk-NEDUOGWU.js');
var _chunkTCLRDUMFjs = require('./chunk-TCLRDUMF.js');
var _chunk34ST3MKOjs = require('./chunk-34ST3MKO.js');
var _chunkANT66KVKjs = require('./chunk-ANT66KVK.js');
// src/components/DownloadModal/DownloadModal.tsx
var _react = require('react');
var _react3 = require('@phosphor-icons/react');
// src/enums/DownloadFormat.ts
var DOWNLOAD_FORMAT = /* @__PURE__ */ ((DOWNLOAD_FORMAT2) => {
DOWNLOAD_FORMAT2["PDF"] = "pdf";
DOWNLOAD_FORMAT2["EXCEL"] = "excel";
return DOWNLOAD_FORMAT2;
})(DOWNLOAD_FORMAT || {});
// src/components/DownloadModal/DownloadModal.tsx
var _jsxruntime = require('react/jsx-runtime');
var DownloadModal = ({
isOpen,
onClose,
isDownloading,
error,
onDownloadPdf,
onDownloadExcel
}) => {
const [selectedFormat, setSelectedFormat] = _react.useState.call(void 0,
null
);
const handleClose = _react.useCallback.call(void 0, () => {
setSelectedFormat(null);
onClose();
}, [onClose]);
const wasDownloadingRef = _react.useRef.call(void 0, false);
_react.useEffect.call(void 0, () => {
if (!isOpen) {
wasDownloadingRef.current = isDownloading;
return;
}
if (wasDownloadingRef.current && !isDownloading && !error) {
handleClose();
}
wasDownloadingRef.current = isDownloading;
}, [isOpen, isDownloading, error, handleClose]);
const handleDownload = _react.useCallback.call(void 0, () => {
if (selectedFormat === "pdf" /* PDF */) {
onDownloadPdf();
handleClose();
} else if (selectedFormat === "excel" /* EXCEL */) {
onDownloadExcel();
}
}, [selectedFormat, onDownloadPdf, onDownloadExcel, handleClose]);
const cardBase = "flex flex-1 items-center justify-center h-20 rounded-xl border bg-background shadow-soft-shadow-1 cursor-pointer transition-colors";
const cardDefault = "border-border-100 hover:border-primary-300";
const cardSelected = "border-primary-300 bg-primary-50";
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunkTCLRDUMFjs.Modal_default,
{
isOpen,
onClose: handleClose,
title: "Como deseja baixar o relat\xF3rio?",
size: "lg",
footer: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex justify-end gap-2", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunk34ST3MKOjs.Button_default,
{
variant: "outline",
action: "primary",
size: "small",
onClick: handleClose,
"data-testid": "download-cancel-btn",
children: "Cancelar"
}
),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunk34ST3MKOjs.Button_default,
{
variant: "solid",
action: "primary",
size: "small",
disabled: !selectedFormat || isDownloading,
iconLeft: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.DownloadSimpleIcon, { size: 16 }),
onClick: handleDownload,
"data-testid": "download-confirm-btn",
children: "Baixar"
}
)
] }),
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col gap-3", children: [
error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "sm", className: "text-indicator-error", children: error }),
isDownloading ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-row gap-4", "data-testid": "download-skeleton", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.Skeleton, { variant: "rounded", width: "100%", height: 80 }),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.Skeleton, { variant: "rounded", width: "100%", height: 80 })
] }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-row gap-4", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunk34ST3MKOjs.Button_default,
{
"data-testid": "download-pdf-option",
"aria-label": "PDF",
"aria-pressed": selectedFormat === "pdf" /* PDF */,
variant: "outline",
action: "secondary",
className: `${cardBase} ${selectedFormat === "pdf" /* PDF */ ? cardSelected : cardDefault}`,
onClick: () => setSelectedFormat("pdf" /* PDF */),
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.FilePdfIcon, { size: 24, className: "text-text-700" })
}
),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
_chunk34ST3MKOjs.Button_default,
{
"data-testid": "download-excel-option",
"aria-label": "Excel",
"aria-pressed": selectedFormat === "excel" /* EXCEL */,
variant: "outline",
action: "secondary",
className: `${cardBase} ${selectedFormat === "excel" /* EXCEL */ ? cardSelected : cardDefault}`,
onClick: () => setSelectedFormat("excel" /* EXCEL */),
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.FileXlsIcon, { size: 24, className: "text-text-700" })
}
)
] })
] })
}
);
};
var DownloadModal_default = DownloadModal;
exports.DOWNLOAD_FORMAT = DOWNLOAD_FORMAT; exports.DownloadModal_default = DownloadModal_default;
//# sourceMappingURL=chunk-DGZJUNUT.js.map