Menu

Change language

GitHub repo

Table

tableui

Plain HTML table primitives — `<Table>`, `<TableHeader>`, `<TableRow>`, `<TableCell>` — with the registry’s borders, padding, and tokens already applied. Use this when Data Table is too heavy.

Installation

$npx shadcn-svelte@latest add https://uipkge.dev/r/svelte/table.json
Manifest:https://uipkge.dev/r/svelte/table.jsonInstalls to:src/lib/components/ui/table/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
containerClass

Extra classes for the scroll container div (e.g. `min-h-0 flex-1` inside a flex column). A sticky TableHeader pins to THIS div -- an outer overflow wrapper around <Table> breaks stickiness, so size the scroller here.

string—optional
density'compact' | 'cozy' | 'comfortable'—optional
refHTMLTableElement | null—optional

Used by

Files installed (11)

  • src/lib/components/ui/table/Table.svelte1.3 kB
    <script lang="ts" module>
      import type { HTMLTableAttributes } from 'svelte/elements'
    
      export interface TableProps extends HTMLTableAttributes {
        /**
         * Extra classes for the scroll container div (e.g. `min-h-0 flex-1` inside a
         * flex column). A sticky TableHeader pins to THIS div -- an outer overflow
         * wrapper around <Table> breaks stickiness, so size the scroller here.
         */
        containerClass?: string
        density?: 'compact' | 'cozy' | 'comfortable'
        ref?: HTMLTableElement | null
      }
    </script>
    
    <script lang="ts">
      import { cn } from '$lib/utils'
    
      let { class: className, containerClass, density, children, ref = $bindable(null), ...restProps }: TableProps = $props()
    
      const densityClass = $derived.by(() => {
        if (density === 'compact') return '[&_td]:py-1.5 [&_td]:text-xs [&_th]:h-8 [&_th]:text-xs'
        if (density === 'comfortable') return '[&_td]:py-3 [&_th]:h-12'
        // cozy is the TableCell/TableHead baseline (py-2 / h-10) -- no override.
        return ''
      })
    </script>
    
    <div data-uipkge="" data-slot="table-container" class={cn('relative w-full overflow-auto', containerClass)}>
      <table bind:this={ref} data-uipkge="" data-slot="table" class={cn('w-full caption-bottom text-sm', densityClass, className)} {...restProps}>
        {@render children?.()}
      </table>
    </div>
    
  • src/lib/components/ui/table/TableBody.svelte0.5 kB
  • src/lib/components/ui/table/TableCaption.svelte0.5 kB
  • src/lib/components/ui/table/TableCell.svelte0.6 kB
  • src/lib/components/ui/table/TableEmpty.svelte0.7 kB
  • src/lib/components/ui/table/TableFooter.svelte0.6 kB
  • src/lib/components/ui/table/TableHead.svelte0.7 kB
  • src/lib/components/ui/table/TableHeader.svelte0.5 kB
  • src/lib/components/ui/table/TableRow.svelte0.6 kB
  • src/lib/components/ui/table/index.ts0.7 kB
  • src/lib/components/ui/table/utils.ts0.5 kB

Raw manifest:https://uipkge.dev/r/svelte/table.json