UNPKG

@schema-render/search-table-react

Version:
38 lines (37 loc) 1.37 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { Button, Modal } from "antd"; import { useState } from "react"; import useRootContext from "../hooks/useRootContext"; import { isEmpty } from "../utils/common"; const LongTextModal = ({ value, options = {} })=>{ const text = isEmpty(value) ? '-' : String(value); const { maxLength = 10, ...modalProps } = options; const [isOpen, setIsOpen] = useState(false); const rootCtx = useRootContext(); return text.length > maxLength ? /*#__PURE__*/ _jsxs(_Fragment, { children: [ text.slice(0, maxLength - 3), "...", /*#__PURE__*/ _jsx(Button, { type: "link", style: { padding: 0 }, onClick: ()=>setIsOpen(true), children: rootCtx.locale.SearchTable.longTextModalLabel }), /*#__PURE__*/ _jsx(Modal, { width: 600, title: rootCtx.locale.SearchTable.longTextModalTitle, footer: null, ...modalProps, open: isOpen, onCancel: ()=>setIsOpen(false), children: text }) ] }) : /*#__PURE__*/ _jsx(_Fragment, { children: text }); }; export default LongTextModal;