-
Notifications
You must be signed in to change notification settings - Fork 936
chore: add Table component #16410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
chore: add Table component #16410
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "./Table"; | ||
|
||
const invoices = [ | ||
{ | ||
invoice: "INV001", | ||
paymentStatus: "Paid", | ||
totalAmount: "$250.00", | ||
paymentMethod: "Credit Card", | ||
}, | ||
{ | ||
invoice: "INV002", | ||
paymentStatus: "Pending", | ||
totalAmount: "$150.00", | ||
paymentMethod: "PayPal", | ||
}, | ||
{ | ||
invoice: "INV003", | ||
paymentStatus: "Unpaid", | ||
totalAmount: "$350.00", | ||
paymentMethod: "Bank Transfer", | ||
}, | ||
{ | ||
invoice: "INV004", | ||
paymentStatus: "Paid", | ||
totalAmount: "$450.00", | ||
paymentMethod: "Credit Card", | ||
}, | ||
{ | ||
invoice: "INV005", | ||
paymentStatus: "Paid", | ||
totalAmount: "$550.00", | ||
paymentMethod: "PayPal", | ||
}, | ||
{ | ||
invoice: "INV006", | ||
paymentStatus: "Pending", | ||
totalAmount: "$200.00", | ||
paymentMethod: "Bank Transfer", | ||
}, | ||
{ | ||
invoice: "INV007", | ||
paymentStatus: "Unpaid", | ||
totalAmount: "$300.00", | ||
paymentMethod: "Credit Card", | ||
}, | ||
]; | ||
|
||
const meta: Meta<typeof Table> = { | ||
title: "components/Table", | ||
component: Table, | ||
args: { | ||
children: ( | ||
<> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead className="w-[100px]">Invoice</TableHead> | ||
<TableHead>Status</TableHead> | ||
<TableHead>Method</TableHead> | ||
<TableHead className="text-right">Amount</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{invoices.map((invoice) => ( | ||
<TableRow key={invoice.invoice}> | ||
<TableCell className="font-medium">{invoice.invoice}</TableCell> | ||
<TableCell>{invoice.paymentStatus}</TableCell> | ||
<TableCell>{invoice.paymentMethod}</TableCell> | ||
<TableCell className="text-right"> | ||
{invoice.totalAmount} | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</> | ||
), | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Table>; | ||
|
||
export const Default: Story = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copied from shadc/ui on 02/03/2025 | ||
* @see {@link https://ui.shadcn.com/docs/components/table} | ||
*/ | ||
|
||
import * as React from "react"; | ||
import { cn } from "utils/cn"; | ||
|
||
export const Table = React.forwardRef< | ||
HTMLTableElement, | ||
React.HTMLAttributes<HTMLTableElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div className="relative w-full overflow-auto border border-border border-solid rounded-md"> | ||
<table | ||
ref={ref} | ||
className={cn( | ||
"w-full caption-bottom text-xs font-medium text-content-secondary border-collapse", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
</div> | ||
)); | ||
|
||
export const TableHeader = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} /> | ||
)); | ||
|
||
export const TableBody = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tbody | ||
ref={ref} | ||
className={cn("[&_tr:last-child]:border-0", className)} | ||
{...props} | ||
/> | ||
)); | ||
|
||
export const TableFooter = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tfoot | ||
ref={ref} | ||
className={cn( | ||
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
|
||
export const TableRow = React.forwardRef< | ||
HTMLTableRowElement, | ||
React.HTMLAttributes<HTMLTableRowElement> | ||
>(({ className, ...props }, ref) => ( | ||
<tr | ||
ref={ref} | ||
className={cn( | ||
"border-0 border-b border-solid border-border transition-colors", | ||
"hover:bg-muted/50 data-[state=selected]:bg-muted", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
|
||
export const TableHead = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.ThHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<th | ||
ref={ref} | ||
className={cn( | ||
"py-2 px-4 text-left align-middle font-semibold", | ||
"[&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
|
||
export const TableCell = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.TdHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<td | ||
ref={ref} | ||
className={cn( | ||
"py-2 px-4 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
|
||
export const TableCaption = React.forwardRef< | ||
HTMLTableCaptionElement, | ||
React.HTMLAttributes<HTMLTableCaptionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<caption | ||
ref={ref} | ||
className={cn("mt-4 text-sm text-muted-foreground", className)} | ||
{...props} | ||
/> | ||
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the shadcn Table component? I didn't see a comment at the top of the file.