import * as React from 'react'
import { cn } from '@/lib/utils'
/**
* Table primitives — shadcn-style atomic wrappers. Замена @nstart/ui Table*.
*
*
Per handoff: table cell text = text-cell (12.5/500). Применяется на
* <td/th> через CSS rule в `
` — но проще baked-in via TableCell
* className. Caller может override через className prop.
*
* TableEmpty — single full-width row для empty state.
*/
export const Table = React.forwardRef>(
function Table({ className, ...props }, ref) {
return (
)
},
)
export const TableHeader = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes
>(function TableHeader({ className, ...props }, ref) {
return (
)
})
// nstart-compat alias: nstart использовал как THEAD wrapper.
// shadcn по convention использует TableHead как TH cell — это конфликтовало
// (callsites писали `...` ожидая THEAD-семантику).
// Резолвим в пользу nstart-compat (callsites больше). Для TH cell — TableHeaderCell.
export const TableHead = TableHeader
export const TableBody = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes
>(function TableBody({ className, ...props }, ref) {
return (
)
})
export const TableFooter = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes
>(function TableFooter({ className, ...props }, ref) {
return (
tr]:last:border-b-0',
className,
)}
{...props}
/>
)
})
export const TableRow = React.forwardRef>(
function TableRow({ className, ...props }, ref) {
return (
)
},
)
export type TableHeaderCellProps = React.ThHTMLAttributes & {
align?: 'left' | 'center' | 'right'
/** Hide column на narrow viewports per handoff line 466:
* - 'sm' — hide <640px (table cells 6-7 columns secondary)
* - 'md' — hide <768px
* - 'lg' — hide <1024px
* Используется pair с same prop на соответствующих TableCell. */
hideBelow?: 'sm' | 'md' | 'lg'
sortable?: boolean
sortDirection?: 'asc' | 'desc' | 'none'
}
const HIDE_BELOW: Record, string> = {
sm: 'hidden sm:table-cell',
md: 'hidden md:table-cell',
lg: 'hidden lg:table-cell',
}
export const TableHeaderCell = React.forwardRef(
function TableHeaderCell(
{ className, align = 'left', hideBelow, sortable, sortDirection, ...props },
ref,
) {
const ariaSort =
sortDirection === 'asc'
? 'ascending'
: sortDirection === 'desc'
? 'descending'
: sortable
? 'none'
: undefined
return (
|
)
},
)
export type TableCellProps = React.TdHTMLAttributes & {
/** Pair с TableHeaderCell.hideBelow — column скрывается на narrow viewport. */
hideBelow?: 'sm' | 'md' | 'lg'
}
export const TableCell = React.forwardRef(
function TableCell({ className, hideBelow, ...props }, ref) {
return (
|
)
},
)
export const TableCaption = React.forwardRef<
HTMLTableCaptionElement,
React.HTMLAttributes
>(function TableCaption({ className, ...props }, ref) {
return (
)
})
/**
* TableEmpty — full-width row с заглушкой "ничего не найдено".
* Замена @nstart/ui TableEmptyRow API: {text}.
*/
export type TableEmptyProps = React.TdHTMLAttributes & {
colSpan: number
}
export function TableEmpty({ colSpan, className, children, ...props }: TableEmptyProps) {
return (
|
{children}
|
)
}