'use client'; import {mergeProps} from 'react-aria/mergeProps'; import { useTable, useTableCell, useTableColumnHeader, useTableHeaderRow, useTableRow, useTableRowGroup, type AriaTableProps } from 'react-aria/useTable'; import {useFocusRing} from 'react-aria/useFocusRing'; import { useTableState, Cell, Column, Row, TableBody, TableHeader, type TableState, type TableStateProps } from 'react-stately/useTableState'; import type {Node} from '@react-types/shared'; import {useRef} from 'react'; import type {ReactNode} from 'react'; import './Table.css'; export {Cell, Column, Row, TableBody, TableHeader}; export type TableProps = TableStateProps & AriaTableProps & {children?: ReactNode}; export function Table(props: TableProps) { let state = useTableState({...props, showSelectionCheckboxes: false}); let ref = useRef(null); let {collection} = state; let {gridProps} = useTable(props, state, ref); return ( {collection.headerRows.map(headerRow => ( {[...headerRow.childNodes].map(column => ( ))} ))} {[...collection.body.childNodes].map(row => ( {[...row.childNodes].map(cell => ( ))} ))}
); } function TableRowGroup({type: Element, children}: {type: 'thead' | 'tbody'; children: ReactNode}) { let {rowGroupProps} = useTableRowGroup(); return ( {children} ); } function TableHeaderRow({ item, state, children }: { item: Node; state: TableState; children: ReactNode; }) { let ref = useRef(null); /*- begin highlight -*/ let {rowProps} = useTableHeaderRow({node: item}, state, ref); /*- end highlight -*/ return ( {children} ); } function TableColumnHeader({column, state}: {column: Node; state: TableState}) { let ref = useRef(null); let {columnHeaderProps} = useTableColumnHeader({node: column}, state, ref); let {isFocusVisible, focusProps} = useFocusRing(); return ( {column.rendered} ); } function TableRow({ item, children, state }: { item: Node; children: ReactNode; state: TableState; }) { let ref = useRef(null); let {rowProps, isSelected, isDisabled, isPressed} = useTableRow({node: item}, state, ref); let {isFocusVisible, focusProps} = useFocusRing(); return ( {children} ); } function TableCell({cell, state}: {cell: Node; state: TableState}) { let ref = useRef(null); let {gridCellProps} = useTableCell({node: cell}, state, ref); let {isFocusVisible, focusProps} = useFocusRing(); return ( {cell.rendered} ); }