|
| 1 | +import type { Component, ComponentProps } from 'solid-js' |
| 2 | +import { splitProps } from 'solid-js' |
| 3 | + |
| 4 | +import { cn } from '~/lib/utils' |
| 5 | + |
| 6 | +const Table: Component<ComponentProps<'table'>> = (props) => { |
| 7 | + const [local, others] = splitProps(props, ['class']) |
| 8 | + return ( |
| 9 | + <div class="relative w-full overflow-auto"> |
| 10 | + <table class={cn('w-full caption-bottom text-sm', local.class)} {...others} /> |
| 11 | + </div> |
| 12 | + ) |
| 13 | +} |
| 14 | + |
| 15 | +const TableHeader: Component<ComponentProps<'thead'>> = (props) => { |
| 16 | + const [local, others] = splitProps(props, ['class']) |
| 17 | + return <thead class={cn('[&_tr]:border-b', local.class)} {...others} /> |
| 18 | +} |
| 19 | + |
| 20 | +const TableBody: Component<ComponentProps<'tbody'>> = (props) => { |
| 21 | + const [local, others] = splitProps(props, ['class']) |
| 22 | + return <tbody class={cn('[&_tr:last-child]:border-0', local.class)} {...others} /> |
| 23 | +} |
| 24 | + |
| 25 | +const TableFooter: Component<ComponentProps<'tfoot'>> = (props) => { |
| 26 | + const [local, others] = splitProps(props, ['class']) |
| 27 | + return <tfoot class={cn('bg-primary font-medium text-primary-foreground', local.class)} {...others} /> |
| 28 | +} |
| 29 | + |
| 30 | +const TableRow: Component<ComponentProps<'tr'>> = (props) => { |
| 31 | + const [local, others] = splitProps(props, ['class']) |
| 32 | + return ( |
| 33 | + <tr |
| 34 | + class={cn('border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted', local.class)} |
| 35 | + {...others} |
| 36 | + /> |
| 37 | + ) |
| 38 | +} |
| 39 | + |
| 40 | +const TableHead: Component<ComponentProps<'th'>> = (props) => { |
| 41 | + const [local, others] = splitProps(props, ['class']) |
| 42 | + return ( |
| 43 | + <th |
| 44 | + class={cn( |
| 45 | + 'h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0', |
| 46 | + local.class, |
| 47 | + )} |
| 48 | + {...others} |
| 49 | + /> |
| 50 | + ) |
| 51 | +} |
| 52 | + |
| 53 | +const TableCell: Component<ComponentProps<'td'>> = (props) => { |
| 54 | + const [local, others] = splitProps(props, ['class']) |
| 55 | + return <td class={cn('p-2 align-top [&:has([role=checkbox])]:pr-0', local.class)} {...others} /> |
| 56 | +} |
| 57 | + |
| 58 | +const TableCaption: Component<ComponentProps<'caption'>> = (props) => { |
| 59 | + const [local, others] = splitProps(props, ['class']) |
| 60 | + return <caption class={cn('mt-4 text-sm text-muted-foreground', local.class)} {...others} /> |
| 61 | +} |
| 62 | + |
| 63 | +export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption } |
0 commit comments