UNPKG

@achs/webkit

Version:

Conjunto de componentes de UI con el estilo del Sistema de Diseño ACHS (Asociación Chilena de Seguridad), para reutilizar de forma transversal en las aplicaciones web de ACHS. Construido con **React 19**, **TypeScript** y **Vite**, con soporte para las

65 lines (64 loc) 2.35 kB
import { jsxs as g, jsx as a } from "react/jsx-runtime"; import x from "./Table.module.scss.mjs"; import { Checkbox as C } from "../../atoms/Checkbox/index.mjs"; function w({ columns: o, dataSource: r, rowKey: f, color: i = "primary", className: k, rowSelection: t }) { const y = (e, d) => f ? e[f] : d, c = r.map(y), m = new Set((t == null ? void 0 : t.selectedRowKeys) || []), p = c.length > 0 && c.every((e) => m.has(e)), u = c.some((e) => m.has(e)) && !p, R = (e) => { if (!t) return; const d = e ? c : [], n = e ? r : []; t.onChange(d, n); }, b = (e, d) => { if (!t) return; const n = new Set(t.selectedRowKeys); d ? n.add(e) : n.delete(e); const l = Array.from(n), s = r.filter( (h, A) => l.includes(y(h, A)) ); t.onChange(l, s); }; return /* @__PURE__ */ g("table", { className: `${x.table} ${k ?? ""}`, children: [ /* @__PURE__ */ a("thead", { "data-color": i, children: /* @__PURE__ */ g("tr", { children: [ t && /* @__PURE__ */ a("th", { scope: "col", style: { textAlign: "center", width: "50px" }, children: /* @__PURE__ */ a( C, { checked: p, size: "small", color: i === "secondary" ? "secondary" : "primary", ref: (e) => { e && (e.indeterminate = u); }, onChange: (e) => R(e.target.checked) } ) }), o.map((e) => /* @__PURE__ */ a("th", { scope: "col", style: { textAlign: e.align || "left", width: e.width }, children: e.title }, e.key)) ] }) }), /* @__PURE__ */ a("tbody", { children: r.map((e, d) => { const n = y(e, d), l = m.has(n); return /* @__PURE__ */ g("tr", { className: l ? x.selectedRow : "", children: [ t && /* @__PURE__ */ a("td", { style: { textAlign: "center" }, children: /* @__PURE__ */ a( C, { size: "small", color: i === "secondary" ? "secondary" : "primary", checked: l, onChange: (s) => b(n, s.target.checked) } ) }), o.map((s) => { const h = s.dataIndex ? e[s.dataIndex] : null; return /* @__PURE__ */ a("td", { style: { textAlign: s.align || "left" }, children: s.render ? s.render(h, e, d) : h }, s.key); }) ] }, n); }) }) ] }); } export { w as Table, w as default };