import React from 'react'; import {Table as MTable, TableProps as MTableProps} from '@mantine/core'; import {Icon} from './Icon'; /* * Tables. * * Rows are separated by a horizontal rule and nothing else. There are no column * borders: a full grid draws a line around every cell, which is a lot of ink to * say something the column headings already say, and it made the header row -- * which had no surface of its own -- read as one more cell in the grid. The * header now carries `--head` and a full-strength rule under it, and the rules * between body rows are `--table-line`, deliberately fainter. See ui.css. * * Wide tables scroll in their own container so the page body never scrolls * sideways. * * The compound names mirror Semantic's (Header/Body/Row/Cell/HeaderCell/Footer) * so migrating a call site is a rename, not a rewrite. */ export interface TableProps extends MTableProps { /** Wrap in a horizontally scrollable container. On by default. */ scrollable?: boolean; } function TableBase({scrollable = true, ...props}: TableProps) { const table = ; return scrollable ?
{table}
: table; } export interface RowProps extends React.ComponentPropsWithoutRef<'tr'> { /** A failed row: takes the dashed danger border, in every theme. */ failed?: boolean; } function Row({failed, className, ...props}: RowProps) { return } export interface CellProps extends React.ComponentPropsWithoutRef<'td'> { /** Right-align and use tabular figures, so digits line up in the column. */ numeric?: boolean; } function Cell({numeric, style, ...props}: CellProps) { return } export type SortDirection = 'ascending' | 'descending'; export interface HeaderCellProps extends React.ComponentPropsWithoutRef<'th'> { /** This column's current sort, or null/undefined when it is not the sorted one. */ sorted?: SortDirection | null; /** Makes the header a sort control. Receives nothing; the caller knows its column. */ onSort?: () => void; } /** * A header cell, optionally a sort control. * * When `onSort` is given the label becomes a real ` } export const Table = Object.assign(TableBase, { Header: MTable.Thead, Body: MTable.Tbody, Footer: MTable.Tfoot, Row, Cell, HeaderCell, // Mantine's own names, for new code. Thead: MTable.Thead, Tbody: MTable.Tbody, Tfoot: MTable.Tfoot, Tr: Row, Td: Cell, Th: HeaderCell, ScrollContainer: MTable.ScrollContainer, });