import styles from '@system/Table.module.scss'; import * as React from 'react'; import * as Utilities from '@common/utilities'; import Checkbox from '@system/Checkbox'; function generateAutoString(count: number): string { if (count <= 0) { return ''; } const autoArray = new Array(count).fill('auto'); return autoArray.join(' '); } export default function Table(props) { let gridTemplateColumns = props.isInteractive ? `40px ${generateAutoString(props.headings.length - 1)} repeat(1, 1fr)` : `${generateAutoString(props.headings.length - 1)} repeat(1, 1fr)`; if (!Utilities.isEmpty(props.customWidth)) { gridTemplateColumns = props.customWidth; } let headings = props.headings && props.headings.length ? props.headings : ['Empty']; return (
{props.isInteractive ?
: null} {headings.map((each, index) => { return (
{each}
); })}
{props.data && props.data.length ? ( props.data.map((each, index) => { const value = props.value ? !!props.value.includes(`${each.id}`) : false; const backgroundColor = value ? `var(--theme-foreground)` : undefined; return (
{props.isInteractive ? (
{ if (props.onChange) { props.onChange({ [e.target.name]: e.target.value }); } }} value={value} />
) : null} {each.data.map((col, index) => { return (
{col}
); })}
); }) ) : (
{props.isInteractive ?
: null}
This table is empty
)}
); }