mui-component
Version:
some custom mui components
106 lines (105 loc) • 5 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { Alert, Button } from "@mui/material";
import { Download } from "@mui/icons-material";
import { generateFileDownload } from "@iimm/shared";
import { Modal } from "../../../../feedback";
import { PdfModalViewer } from "../../../PdfModalViewer";
import { VideoModalViewer } from "../../../VideoModalViewer";
import { ImageModalViewer } from "../../../ImageModalViewer";
import { jsx as _jsx } from "react/jsx-runtime";
// const ViewList = [ 'pdf', 'image', 'video' ];
var FallbackModalViewer = function FallbackModalViewer(props) {
var fileSrc = props.fileSrc,
fileName = props.fileName,
trigger = props.trigger,
showDownload = props.showDownload,
onFileDownload = props.onFileDownload,
onFileDownloadStart = props.onFileDownloadStart,
modalProps = props.modalProps;
return /*#__PURE__*/_jsx(Modal, _objectSpread(_objectSpread({
trigger: trigger,
title: fileName,
fullWidth: true,
responsive: true,
extraActions: showDownload ? /*#__PURE__*/_jsx(Button, {
variant: "outlined",
startIcon: /*#__PURE__*/_jsx(Download, {})
// @ts-ignore
,
onClick: function onClick() {
return generateFileDownload(fileSrc, fileName, undefined, {
onDownloadSuccess: onFileDownload,
onDownloadStart: onFileDownloadStart
});
},
children: "\u4E0B\u8F7D"
}) : undefined
}, modalProps), {}, {
children: /*#__PURE__*/_jsx(Alert, {
severity: "info",
children: "\u6B64\u6587\u4EF6\u683C\u5F0F\u6682\u4E0D\u652F\u6301\u9884\u89C8"
})
}));
};
export var FileViewRender = function FileViewRender(props) {
var fileSrc = props.fileSrc,
fileName = props.fileName,
view = props.view,
trigger = props.trigger,
type = props.type,
showDownload = props.showDownload,
onFileDownload = props.onFileDownload,
onFileDownloadStart = props.onFileDownloadStart,
modalProps = props.modalProps,
pdfViewerProps = props.pdfViewerProps;
if (!view) return null;
if (type === "pdf") {
return /*#__PURE__*/_jsx(PdfModalViewer, _objectSpread(_objectSpread({
file: fileSrc,
showDownload: showDownload,
trigger: trigger,
title: fileName
// @ts-ignore
,
onDownloadStart: onFileDownloadStart
// @ts-ignore
,
onDownloadSuccess: onFileDownload
}, modalProps || {}), pdfViewerProps || {}));
} else if (type === "image") {
return /*#__PURE__*/_jsx(ImageModalViewer, _objectSpread({
trigger: trigger,
showDownload: showDownload,
imgSrc: fileSrc
// @ts-ignore
,
title: fileName,
onFileDownload: onFileDownload,
onFileDownloadStart: onFileDownloadStart
}, modalProps || {}));
} else if (type === "video") {
return /*#__PURE__*/_jsx(VideoModalViewer, {
trigger: trigger,
showDownload: showDownload,
fileSrc: fileSrc,
fileName: fileName,
modalProps: modalProps,
onFileDownload: onFileDownload,
onFileDownloadStart: onFileDownloadStart
});
}
return /*#__PURE__*/_jsx(FallbackModalViewer, {
trigger: trigger,
showDownload: showDownload,
fileSrc: fileSrc,
fileName: fileName,
modalProps: modalProps,
onFileDownload: onFileDownload,
onFileDownloadStart: onFileDownloadStart
});
};