import {
Table,
TableBody,Table은 네이티브 HTML 테이블 요소 — <table>, <thead>, <tbody>, <th>, <td>, <caption> — 에 스타일을 입힙니다. 하위 프리미티브 라이브러리는 없으며 Radix와 Base 변형은 같은 파일을 씁니다. 네오브루탈리즘 공식: 테이블 전체에 두꺼운 테두리와 선명한 그림자, 헤더 셀은 제목 서체, 행 구분선은 2px입니다.
다음과 같은 경우에 사용합니다.
- 청구서와 주문 — 합계용
TableFooter행이 있는 품목 목록. - 관리자 목록 — 사용자, API 키, 구독, 행 동작 드롭다운.
- 가격·비교 그리드 — 열 헤더가 의미를 담는 기능 매트릭스.
설치#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/table.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/table.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/table.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/table.json
다음 코드를 복사하여 프로젝트에 붙여넣습니다.
"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
function Table({ className, ...props }: React.ComponentProps<"table">) {
return (
<div
data-slot="table-container"
className="relative w-full overflow-x-auto rounded border-2 shadow-md"
>
<table
data-slot="table"
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
)
}
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
return (
<thead
data-slot="table-header"
className={cn("[&_tr]:border-b-2", className)}
{...props}
/>
)
}
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
return (
<tbody
data-slot="table-body"
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
)
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
return (
<tfoot
data-slot="table-footer"
className={cn(
"border-t-2 bg-muted/50 font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
)
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
return (
<tr
data-slot="table-row"
className={cn(
"border-b-2 transition-colors hover:bg-accent has-aria-expanded:bg-accent data-[state=selected]:bg-accent",
className
)}
{...props}
/>
)
}
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
return (
<th
data-slot="table-head"
className={cn(
"h-10 bg-muted px-2 text-left align-middle font-head font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
)
}
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
return (
<td
data-slot="table-cell"
className={cn(
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
)
}
function TableCaption({
className,
...props
}: React.ComponentProps<"caption">) {
return (
<caption
data-slot="table-caption"
className={cn("mt-4 text-sm text-muted-foreground", className)}
{...props}
/>
)
}
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}
임포트 경로를 프로젝트 구성에 맞게 조정합니다.
사용법#
import {
Table,
TableBody,
TableCaption,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="w-[100px]">Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell className="font-medium">INV001</TableCell>
<TableCell>Paid</TableCell>
<TableCell>Credit Card</TableCell>
<TableCell className="text-right">$250.00</TableCell>
</TableRow>
</TableBody>
</Table>구성#
다음 구성을 사용하여 Table을 구축합니다.
Table
├── TableCaption
├── TableHeader
│ └── TableRow
│ ├── TableHead
│ ├── TableHead
│ ├── TableHead
│ └── TableHead
├── TableBody
│ ├── TableRow
│ │ ├── TableCell
│ │ ├── TableCell
│ │ ├── TableCell
│ │ └── TableCell
│ └── TableRow
│ ├── TableCell
│ ├── TableCell
│ ├── TableCell
│ └── TableCell
└── TableFooter예제#
푸터#
<TableFooter /> 컴포넌트를 사용하여 테이블에 푸터를 추가합니다.
import {
Table,
TableBody,액션#
<DropdownMenu /> 컴포넌트를 사용하여 각 행에 액션을 표시하는 테이블입니다.
import { MoreHorizontalIcon } from "lucide-react"
import { Button } from "@/components/ui/button"Data Table#
<Table /> 컴포넌트를 사용하여 더 복잡한 데이터 테이블을 구축할 수 있습니다. @tanstack/react-table과 결합하면 정렬, 필터링, 페이지네이션을 갖춘 테이블을 만들 수 있습니다.
자세한 내용은 Data Table 문서를 참고하세요.
Tasks 데모에서도 데이터 테이블 예제를 확인할 수 있습니다.
RTL#
Neobrutalism에서 RTL 지원을 활성화하는 방법은 RTL 설정 가이드를 참고하세요.
"use client"
import * as React from "react"접근성#
네이티브 테이블 요소를 렌더링하면 ARIA 배선 없이 스크린 리더의 테이블 안내, 행/열 탐색, 헤더 연결이 따라옵니다. 각 테이블에 TableCaption으로 이름을 달고, 진짜 헤더 셀에만 TableHead를 쓰세요. 스크롤 컨테이너는 포커스를 받지 않아 키보드 전용 사용자는 넘치는 테이블을 스크롤할 수 없습니다. 넓은 테이블이 예상되면 컴포넌트 복사본의 컨테이너 div에 tabIndex={0}, role="region", aria-label을 추가하세요.