import React from 'react'; import {Table as MTable, TableProps as MTableProps} from '@mantine/core'; import {Icon} from './Icon'; /* * Tables. * * Borders do structural work here: full 1px cell borders, a `--head` header row, * and zebra striping. 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, });