UNPKG

denwa-react-shared

Version:
111 lines (110 loc) • 2.6 kB
import { jsx as e } from "react/jsx-runtime"; import { Button as t, Dropdown as n, Table as r } from "antd"; import { LoadingOutlined as i } from "@ant-design/icons"; //#region src/shared/ui/base-table/index.tsx var a = ({ viewText: a, actionsText: o, editText: s, deleteText: c, columns: l, serverPagination: u, scroll: d, loading: f, dataSource: p, isHiddenUpdate: m, isHiddenActions: h, isCanRead: g, isCanUpdate: _, isCanDelete: v, isFixedActions: y, renderActions: b, onView: x, onDropdownClick: S, onEdit: C, onDelete: w, onShowSizeChange: T, ...E }) => { let D = p?.map((e) => { let t = {}; return Object.entries(e).forEach(([e, n]) => { t[e] = n != null && n !== "" ? n : "-"; }), t; }), O = l ?? [], k = u ? { current: u.page ?? 1, pageSize: u.limit ?? 10, total: u.count ?? 0, pageSizeOptions: [ 10, 20, 50, 100, 200, 500 ], showSizeChanger: !0, showQuickJumper: !0, onShowSizeChange: T, showTotal: (e, t) => `${t[0]}-${t[1]} / ${e}` } : null, A = (e) => { if ("id" in e && (typeof e.id == "string" || typeof e.id == "number")) return String(e.id); }, j = (e) => { let t = A(e); t !== void 0 && x(t); }, M = (e) => { let t = A(e); t !== void 0 && S(t); }, N = h ? [...O] : [...O, { title: o, key: "action", width: 180, fixed: y ? "right" : !1, render: (r) => { let i = [ ...(b?.(r) ?? []).map((e) => ({ key: e.key, icon: e.icon, label: e.label, danger: e.danger, disabled: e.disabled, onClick: e.onClick })), ...!m && _ ? [{ key: "edit", label: /* @__PURE__ */ e(t, { type: "link", block: !0, onClick: () => { M(r), C(); }, children: s }) }] : [], ...v && w ? [{ key: "delete", label: /* @__PURE__ */ e(t, { type: "link", block: !0, danger: !0, onClick: () => { M(r), w(); }, children: c }) }] : [] ]; return i?.length ? /* @__PURE__ */ e(n.Button, { disabled: !g, menu: { items: i, onClick: () => M(r) }, onClick: () => j(r), children: a }) : /* @__PURE__ */ e(t, { disabled: !g, onClick: () => j(r), children: a }); } }]; return /* @__PURE__ */ e(r, { ...E, className: "baseTable", dataSource: D, columns: N, pagination: k ? { ...k, size: "small" } : !1, scroll: { y: "50vh", ...d, scrollToFirstRowOnChange: !0 }, loading: { spinning: !!f, indicator: /* @__PURE__ */ e(i, { style: { fontSize: 36 } }) } }); }; //#endregion export { a as BaseTable };