All checks were successful
Deploy Docs to Synology / deploy (push) Successful in 4s
31 lines
986 B
JavaScript
31 lines
986 B
JavaScript
// components/Table.js
|
|
import { Tag, For } from "sigpro";
|
|
|
|
export const Table = (props, children) => {
|
|
children === undefined && (children = props, props = {});
|
|
return Tag("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) ?
|
|
Tag("thead", {},
|
|
Tag("tr", {},
|
|
props.columns.map(col => Tag("th", { class: col.class }, col.label))
|
|
)
|
|
) : null;
|
|
|
|
const tbody = Tag("tbody", {}, [
|
|
For(itemArray, (item, idx) =>
|
|
Tag("tr", {},
|
|
props.columns.map(col => {
|
|
const content = col.render ? col.render(item, idx) : item[col.key];
|
|
return Tag("td", { class: col.class }, content);
|
|
})
|
|
)
|
|
, props.keyFn || ((item, idx) => item.id ?? idx))
|
|
]);
|
|
|
|
return [thead, tbody];
|
|
}; |