import * as React from 'react'; import classNames from 'classnames'; import { chunk } from 'lodash'; import Text, { TextSizes } from '../../uikit/Text'; import BrandDot from '../../uikit/icons/BrandDot'; import styles from './PropertyTable.module.css'; export type Entries = Record; type Entry = [string, string]; interface PropertyTableProps { className?: string; entries: Entries[]; columns?: number; renderKey?: (entry: Entry) => React.ReactNode; renderValue?: (entry: Entry) => React.ReactNode; shouldHighlightCell?: (entry: Entry) => boolean; shouldWrapText?: boolean; } const PropertyTable = ({ className, entries, columns = 3, renderKey, renderValue, shouldHighlightCell, shouldWrapText = false, }: PropertyTableProps) => { const entriesAsTuples = entries.map((entry) => Object.entries(entry)); let currentRowIndex = 0; const renderRow = (entryTuple: Entry[], index: number) => { return (
{entryTuple.map((entry) => { const [key, value] = entry; const highlightCell = shouldHighlightCell?.(entry); return (
{renderKey != null ? renderKey(entry) : key} {highlightCell ? : null}
{renderValue != null ? renderValue(entry) : value}
); })}
); }; const renderBlock = (entryBlock: Entry[]) => { return chunk(entryBlock, columns).map((block) => { const row = renderRow(block, currentRowIndex); currentRowIndex++; return row; }); }; return
{entriesAsTuples.map(renderBlock)}
; }; export default PropertyTable;