तालिका
चालान, प्रशासक सूचियाँ और मूल्य निर्धारण ग्रिड के लिए एक सेमांटिक HTML तालिका — बॉर्डर वाली पंक्तियाँ, बोल्ड हेडर और एक कठोर नियोब्रुटलिस्ट छाया।
import {
Table,
TableBody,टेबल नेटिव 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 जोड़ें।