table
lyse/tableFreeComponent
lyse publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by lyse on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.getlyse.com/r/table.jsonSource
1import * as React from "react"2import { cva, type VariantProps } from "class-variance-authority"34import { cn } from "@/lib/utils"5import "./table.css"67/* ------------------------------------------------------------------ */8/* CVA */9/* ------------------------------------------------------------------ */1011const tableVariants = cva("table-base w-full caption-bottom")1213const tableHeaderVariants = cva("table-header")1415const tableBodyVariants = cva("table-body")1617const tableFooterVariants = cva("table-footer")1819const tableRowVariants = cva("table-row")2021const tableHeadVariants = cva(22 "table-head text-content-caption font-accent text-left"23)2425const tableCellVariants = cva("table-cell text-content-note text-left")2627const tableCaptionVariants = cva(28 "table-caption text-content-caption"29)3031/* ------------------------------------------------------------------ */32/* Table */33/* ------------------------------------------------------------------ */3435function Table({36 className,37 wrapperClassName,38 variant = "default",39 compact = false,40 children,41 ...props42}: React.ComponentProps<"table"> & {43 wrapperClassName?: string44 variant?: "default" | "striped"45 compact?: boolean46}) {47 const wrapperRef = React.useRef<HTMLDivElement>(null)48 const [overflows, setOverflows] = React.useState(false)4950 React.useEffect(() => {51 const el = wrapperRef.current52 if (!el) return5354 function check() {55 if (el) setOverflows(el.scrollWidth > el.clientWidth)56 }5758 check()5960 const ro = new ResizeObserver(check)61 ro.observe(el)62 return () => ro.disconnect()63 }, [])6465 return (66 <div67 ref={wrapperRef}68 data-slot="table-wrapper"69 role={overflows ? "region" : undefined}70 aria-label={overflows ? "Scrollable table" : undefined}71 tabIndex={overflows ? 0 : undefined}72 className={cn("table-wrapper w-full", wrapperClassName)}73 >74 <table75 data-slot="table"76 data-variant={variant}77 data-compact={compact || undefined}78 className={cn(tableVariants(), className)}79 {...props}80 >81 {children}82 </table>83 </div>84 )85}8687/* ------------------------------------------------------------------ */88/* TableHeader */89/* ------------------------------------------------------------------ */9091// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from lyse
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-cardaction-card | lyse | Components | Free | no deps · 2 files | |
| alertalert | lyse | Components | Free | 2 deps · 2 files | |
| alert-dialogalert-dialog | lyse | Components | Free | 2 deps · 2 files | |
| avataravatar | lyse | Components | Free | 3 deps · 2 files | |
| badgebadge | lyse | Components | Free | 1 dep · 2 files | |
| banner-infobanner-info | lyse | Components | Free | 2 deps · 2 files | |
| breadcrumbbreadcrumb | lyse | Components | Free | 2 deps · 2 files | |
| buttonbutton | lyse | Components | Free | 2 deps · 2 files |
