Table
docs/tableFreeComponent
table component for SolidJS
Live preview
live · rendered by the registry
Rendered by docs on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://solidcn.dev/r/table.jsonSource
1import type { Component, JSX } from "solid-js";2import { splitProps } from "solid-js";3import { cn } from "~/lib/utils";45const Table: Component<JSX.HTMLAttributes<HTMLTableElement>> = (props) => {6 const [local, rest] = splitProps(props, ["class"]);7 return (8 <div class="relative w-full overflow-auto">9 <table class={cn("w-full caption-bottom text-sm", local.class)} {...rest} />10 </div>11 );12};1314const TableHeader: Component<JSX.HTMLAttributes<HTMLTableSectionElement>> = (props) => {15 const [local, rest] = splitProps(props, ["class"]);16 return <thead class={cn("[&_tr]:border-b", local.class)} {...rest} />;17};1819const TableBody: Component<JSX.HTMLAttributes<HTMLTableSectionElement>> = (props) => {20 const [local, rest] = splitProps(props, ["class"]);21 return <tbody class={cn("[&_tr:last-child]:border-0", local.class)} {...rest} />;22};2324const TableFooter: Component<JSX.HTMLAttributes<HTMLTableSectionElement>> = (props) => {25 const [local, rest] = splitProps(props, ["class"]);26 return (27 <tfoot28 class={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", local.class)}29 {...rest}30 />31 );32};3334const TableRow: Component<JSX.HTMLAttributes<HTMLTableRowElement>> = (props) => {35 const [local, rest] = splitProps(props, ["class"]);36 return (37 <tr38 class={cn(39 "border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",40 local.class,41 )}42 {...rest}43 />44 );45};4647const TableHead: Component<JSX.ThHTMLAttributes<HTMLTableCellElement>> = (props) => {48 const [local, rest] = splitProps(props, ["class"]);49 return (50 <th51 class={cn(52 "h-12 px-4 text-left align-middle font-medium text-muted-foreground",53 "[&:has([role=checkbox])]:pr-0",54 local.class,55 )}56 {...rest}57 />58 );59};6061const TableCell: Component<JSX.TdHTMLAttributes<HTMLTableCellElement>> = (props) => {62 const [local, rest] = splitProps(props, ["class"]);63 return <td class={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", local.class)} {...rest} />;64};6566const TableCaption: Component<JSX.HTMLAttributes<HTMLTableCaptionElement>> = (props) => {67 const [local, rest] = splitProps(props, ["class"]);68 return (69 <caption70 class={cn("mt-4 text-sm text-muted-foreground", local.class)}71 {...(rest as JSX.HTMLAttributes<HTMLTableCaptionElement>)}72 />73 );74};7576export { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption };
More from docs
All 44 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | docs | Components | Free | no deps | |
| Alert Dialogalert-dialog | docs | Components | Free | no deps | |
| Avataravatar | docs | Components | Free | no deps | |
| Badgebadge | docs | Components | Free | no deps | |
| Breadcrumbbreadcrumb | docs | Components | Free | no deps | |
| Buttonbutton | docs | Components | Free | no deps | |
| Calendarcalendar | docs | Components | Free | no deps | |
| Cardcard | docs | Components | Free | no deps |
