UNPKG

@lanaco/lnc-react-ui

Version:

React component library

170 lines (168 loc) 4.72 kB
import { jsxs as ee, jsx as C } from "react/jsx-runtime"; import { forwardRef as ne, useState as ce, useRef as le } from "react"; import { s as te } from "./emotion-styled.browser.esm-DfbrHHed.js"; import re from "./ActionsToolbar.js"; import ie from "./Pagination.js"; import { r as w, j as N } from "./utils-BUdHa0nB.js"; import oe from "./Table.js"; import { d as ae } from "./breakpoints-BubDitvo.js"; const me = te.div` & .table-view-pagination-lnc { padding: 0 0.625rem; } & .table-view-toolbar-lnc { margin: 0 0.625rem; } @media ${ae("S")} { & .table-view-pagination-lnc, & .table-view-toolbar-lnc { margin: 0 0.5rem; padding: 0 0.5rem; } } `, se = ne((y, T) => { const { tableProps: e = {}, paginationProps: n = {}, actionsToolbarProps: v = {}, rowsSingleSelect: S = !0, rowsMultiSelect: d = !1, showCreate: D = !0, enableCreate: E = !0, showEdit: f, enableEditOnSelection: A, showDelete: O = !0, enableDeleteOnSelection: k = !0, showCopy: x = !0, enableCopyOnSelection: I = !0, customActions: L, pagination: b = !0, readOnly: g = !1, actionsDropdownZIndex: j = null, actionsDropdownPlacement: B = null, actionDropdownProps: V, //---------------- onCreate: _ = () => { }, onEdit: G = () => { }, onDelete: M = () => { }, onDetails: W = () => { }, onCopy: Z = () => { }, onPageChange: $ = () => { }, //------------------ color: a = "primary", size: m = "small", children: s, onChangeRowsSelection: u = () => { }, ...q } = y, c = { ...v, showCreate: D, enableCreate: E, showCopy: x, enableCopyOnSelection: I, showEdit: f, enableEditOnSelection: A, showDelete: O, enableDeleteOnSelection: k, customActions: L, readOnly: g }, [i, h] = ce([]), l = le([]), F = (t, r) => { var o; r ? (d || S) && (l.current = d ? [...l.current, t] : [t], u(l == null ? void 0 : l.current), h(l == null ? void 0 : l.current)) : (l.current = d ? (o = l == null ? void 0 : l.current) == null ? void 0 : o.filter((z) => z != t) : [], u == null || u(l == null ? void 0 : l.current), h(l == null ? void 0 : l.current)); }, H = (t, r) => { var o, z; ((o = t.target) == null ? void 0 : o.type) !== "checkbox" && ((z = t.target) == null ? void 0 : z.className) !== "checkmark" && (e != null && e.onRowClick && e.onRowClick(t, r), J(r, t)); }, J = (t, r) => { W(t, r); }, K = (t) => { _(t); }, Q = (t) => { Z(i, t); }, U = (t) => { G(i, t), l.current = [], h([]), u([]); }, X = (t) => { M(i, t), l.current = [], h([]), u([]); }, Y = (t) => { $(t); }, R = () => w( N("ACTIONS_TOOLBAR", s), { ...c, size: c != null && c.size ? c.size : m, color: c != null && c.color ? c.color : a, className: "table-view-toolbar-lnc " + (c == null ? void 0 : c.className) }, s ) || /* @__PURE__ */ C( re, { ...c, className: "table-view-toolbar-lnc " + (c == null ? void 0 : c.className), size: c != null && c.size ? c.size : m, color: c != null && c.color ? c.color : a, selectedRowsLength: i != null && i.length ? i.length : 0, onCreate: K, onCopy: Q, onEdit: U, onDelete: X, actionsDropdownZIndex: j, actionDropdownProps: V, actionsDropdownPlacement: B, selectedRows: l == null ? void 0 : l.current } ), p = () => w( N("TABLE", s), { ...e, size: e != null && e.size ? e.size : m, color: e != null && e.color ? e.color : a, className: "table-view-pagination-lnc " + (e == null ? void 0 : e.className) }, s ) || /* @__PURE__ */ C( oe, { size: e != null && e.size ? e.size : m, color: e != null && e.color ? e.color : a, EnableSelection: (S || d) && g == !1, onSelectRow: (t, r, o) => F(r, !o), SelectedData: i, onRowClick: (t, r) => H(t, r), ...e } ), P = () => w( N("PAGINATION", s), { ...n, size: n != null && n.size ? n.size : m, color: n != null && n.color ? n.color : a, className: "table-view-pagination-lnc " + (n == null ? void 0 : n.className) }, s ) || /* @__PURE__ */ C( ie, { ...n, size: n != null && n.size ? n.size : m, color: n != null && n.color ? n.color : a, className: "table-view-pagination-lnc " + (n == null ? void 0 : n.className), onPageChange: Y } ); return /* @__PURE__ */ ee(me, { ref: T, ...q, children: [ R(), p(), b == !0 && P() ] }); }); se.displayName = "TABLE_VIEW"; export { se as default };