Files
sigpro-ui/components/discarted/table.js
natxocc 910c6ab3c7
All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 4s
Before repair nav components
2026-04-25 11:24:39 +02:00

31 lines
972 B
JavaScript

// components/Table.js
import { h, each } from "sigpro";
export const Table = (props, children) => {
children === undefined && (children = props, props = {});
return h("table", { ...props, class: `table ${props.class ?? ''}` }, children);
};
export const TableItems = (props) => {
const itemArray = typeof props.items === "function" ? props.items() : (props.items || []);
const thead = props.header !== false && props.columns?.some(col => col.label) ?
h("thead", {},
h("tr", {},
props.columns.map(col => h("th", { class: col.class }, col.label))
)
) : null;
const tbody = h("tbody", {}, [
each(itemArray, (item, idx) =>
h("tr", {},
props.columns.map(col => {
const content = col.render ? col.render(item, idx) : item[col.key];
return h("td", { class: col.class }, content);
})
)
, props.keyFn || ((item, idx) => item.id ?? idx))
]);
return [thead, tbody];
};