'use client'; import {ArrowUp, ChevronRight} from 'lucide-react'; import React from 'react'; import { Cell as AriaCell, Column as AriaColumn, Row as AriaRow, Table as AriaTable, TableHeader as AriaTableHeader, TableBody as AriaTableBody, Button, type CellProps, Collection, type ColumnProps, ColumnResizer, ResizableTableContainer, type RowProps, type TableHeaderProps, type TableProps as AriaTableProps, useTableOptions, type TableBodyProps, TableFooter as AriaTableFooter, type TableFooterProps } from 'react-aria-components/Table'; import {Group} from 'react-aria-components/Group'; import {composeRenderProps} from 'react-aria-components/composeRenderProps'; import {twMerge} from 'tailwind-merge'; import {tv} from 'tailwind-variants'; import {Checkbox} from './Checkbox'; import {composeTailwindRenderProps, focusRing} from './utils'; interface TableProps extends Omit { className?: string; } export function Table(props: TableProps) { return ( ); } const columnStyles = tv({ extend: focusRing, base: 'px-2 h-5 box-border flex-1 flex gap-1 items-center overflow-hidden' }); const resizerStyles = tv({ extend: focusRing, base: 'w-px px-[8px] translate-x-[8px] box-content py-1 h-5 bg-clip-content bg-neutral-400 dark:bg-neutral-500 forced-colors:bg-[ButtonBorder] cursor-col-resize rounded-xs resizing:bg-blue-600 forced-colors:resizing:bg-[Highlight] resizing:w-[2px] resizing:pl-[7px] -outline-offset-2' }); export function Column(props: ColumnProps) { return ( {composeRenderProps(props.children, (children, {allowsSorting, sortDirection}) => (
{children} {allowsSorting && ( {sortDirection && ( )} )} {!props.width && }
))}
); } export function TableHeader(props: TableHeaderProps) { let {selectionBehavior, selectionMode, allowsDragging} = useTableOptions(); return ( {/* Add extra columns for drag and drop and selection. */} {allowsDragging && } {selectionBehavior === 'toggle' && ( {selectionMode === 'multiple' && } )} {props.children} ); } export function TableBody(props: TableBodyProps) { return ; } export function TableFooter(props: TableFooterProps) { return ; } const rowStyles = tv({ extend: focusRing, base: 'group/row relative cursor-default select-none -outline-offset-2 text-neutral-900 disabled:text-neutral-300 dark:text-neutral-200 dark:disabled:text-neutral-600 text-sm hover:bg-neutral-100 pressed:bg-neutral-100 dark:hover:bg-neutral-800 dark:pressed:bg-neutral-800 selected:bg-blue-100 selected:hover:bg-blue-200 selected:pressed:bg-blue-200 dark:selected:bg-blue-700/30 dark:selected:hover:bg-blue-700/40 dark:selected:pressed:bg-blue-700/40 last:rounded-b-lg' }); const dragButtonStyles = "[&[draggable=true]]:cursor-grab [&[draggable=true]]:pressed:cursor-grabbing [&[draggable=true]]:[-webkit-user-drag:element] [&[draggable=true]]:[@media_not_((hover:hover)_and_(pointer:fine))]:before:content-[''] [&[draggable=true]]:[@media_not_((hover:hover)_and_(pointer:fine))]:before:absolute [&[draggable=true]]:[@media_not_((hover:hover)_and_(pointer:fine))]:before:inset-0"; export function Row({id, columns, children, ...otherProps}: RowProps) { let {selectionBehavior, allowsDragging} = useTableOptions(); return ( {allowsDragging && ( )} {selectionBehavior === 'toggle' && ( )} {children} ); } const cellStyles = tv({ extend: focusRing, base: 'relative box-border [-webkit-tap-highlight-color:transparent] border-b border-b-neutral-200 dark:border-b-neutral-700 group-last/row:border-b-0 [--selected-border:var(--color-blue-200)] dark:[--selected-border:var(--color-blue-900)] group-selected/row:border-(--selected-border) [:is(:has(+[data-selected])_*)]:border-(--selected-border) p-2 truncate -outline-offset-2 group-last/row:first:rounded-bl-lg group-last/row:last:rounded-br-lg' }); const expandButton = tv({ extend: focusRing, base: 'border-0 p-0 pr-1 bg-transparent shrink-0 align-middle cursor-default [-webkit-tap-highlight-color:transparent]', variants: { isDisabled: { true: 'text-neutral-300 dark:text-neutral-600 forced-colors:text-[GrayText]' } } }); const chevron = tv({ base: 'w-4.5 h-4.5 text-neutral-500 dark:text-neutral-400 transition-transform duration-200 ease-in-out', variants: { isExpanded: { true: 'transform rotate-90' }, isDisabled: { true: 'text-neutral-300 dark:text-neutral-600 forced-colors:text-[GrayText]' } } }); export function Cell(props: CellProps) { return ( ({ paddingInlineStart: isTreeColumn ? 4 + (hasChildItems ? 0 : 20) + (level - 1) * 16 : undefined })}> {composeRenderProps( props.children, (children, {hasChildItems, isTreeColumn, isExpanded, isDisabled}) => ( <> {hasChildItems && isTreeColumn && ( )} {children} ) )} ); }