-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bootwindproject/feat/table
feat: table component
- Loading branch information
Showing
17 changed files
with
474 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@nx/react/babel", | ||
{ | ||
"runtime": "automatic", | ||
"useBuiltIns": "usage" | ||
} | ||
] | ||
], | ||
"plugins": [] | ||
} |
This file contains 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,18 @@ | ||
{ | ||
"extends": ["plugin:@nx/react", "../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains 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,7 @@ | ||
# table | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test table` to execute the unit tests via [Vitest](https://vitest.dev/). |
This file contains 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,12 @@ | ||
{ | ||
"name": "table", | ||
"version": "0.0.1", | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./index.mjs", | ||
"require": "./index.js" | ||
} | ||
} | ||
} |
This file contains 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,32 @@ | ||
{ | ||
"name": "table", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/table/src", | ||
"projectType": "library", | ||
"tags": [], | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/table/**/*.{ts,tsx,js,jsx}"] | ||
} | ||
}, | ||
"build": { | ||
"executor": "@nx/vite:build", | ||
"outputs": ["{options.outputPath}"], | ||
"defaultConfiguration": "production", | ||
"options": { | ||
"outputPath": "dist/packages/table" | ||
}, | ||
"configurations": { | ||
"development": { | ||
"mode": "development" | ||
}, | ||
"production": { | ||
"mode": "production" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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,6 @@ | ||
export * from './lib/Table'; | ||
export * from './lib/TableBody'; | ||
export * from './lib/TableHead'; | ||
export * from './lib/TableHeader'; | ||
export * from './lib/TableRow'; | ||
export * from './lib/TableCell'; |
This file contains 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,33 @@ | ||
import React from "react"; | ||
import { cn } from "@bootwind/common" | ||
|
||
interface TableProps extends React.ComponentPropsWithoutRef<'table'> { | ||
variant?: 'striped' | 'normal' | ||
borders?: 'all' | 'bottom' | "none" | ||
} | ||
|
||
export const Table = React.forwardRef< | ||
HTMLTableElement, | ||
TableProps | ||
>(({ className, ...props }, ref) => { | ||
const borderClasses = { | ||
bottom: '[&_td]:border-b [&_td]:border-[#e9eff6] [&_th]:border-b [&_th]:border-[#e9eff6]', | ||
all: '[&_td]:border [&_td]:border-[#e9eff6] [&_th]:border [&_th]:border-[#e9eff6]', | ||
none: '' | ||
} | ||
return ( | ||
<div className="relative w-full overflow-auto"> | ||
<table | ||
ref={ref} | ||
className={cn( | ||
"w-full caption-bottom text-sm ", | ||
className, | ||
props.variant == "striped" ? '[&_tr:nth-child(even)]:bg-[#f9fafb]' : '', | ||
borderClasses[props.borders ?? 'bottom'] | ||
) | ||
} | ||
{...props} | ||
/> | ||
</div> | ||
) | ||
}) |
This file contains 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,15 @@ | ||
import React from "react"; | ||
import { cn } from "@bootwind/common" | ||
|
||
export const TableBody = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<> | ||
<tbody | ||
ref={ref} | ||
className={cn("[&_tr:last-child]:border-0 ", className)} | ||
{...props} | ||
/> | ||
</> | ||
)) |
This file contains 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,14 @@ | ||
import React from "react"; | ||
import { cn } from "@bootwind/common" | ||
|
||
export const TableCell = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.TdHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<td | ||
ref={ref} | ||
className={cn("px-5 py-3.5 text-slate-500", className)} | ||
{...props} | ||
> | ||
</td> | ||
)) |
This file contains 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,15 @@ | ||
import React from "react"; | ||
import { cn } from "@bootwind/common" | ||
|
||
export const TableHead = React.forwardRef< | ||
HTMLTableCellElement, | ||
React.ThHTMLAttributes<HTMLTableCellElement> | ||
>(({ className, ...props }, ref) => ( | ||
<> | ||
<th | ||
ref={ref} | ||
className={cn("px-5 py-3.5 font-normal text-left", className)} | ||
{...props} | ||
/> | ||
</> | ||
)) |
This file contains 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,15 @@ | ||
import React from "react"; | ||
import { cn } from "@bootwind/common" | ||
|
||
export const TableHeader = React.forwardRef< | ||
HTMLTableSectionElement, | ||
React.HTMLAttributes<HTMLTableSectionElement> | ||
>(({ className, ...props }, ref) => ( | ||
<> | ||
<thead | ||
ref={ref} | ||
className={cn(className, "bg-gray-50 text-slate-400")} | ||
{...props} | ||
/> | ||
</> | ||
)) |
This file contains 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,17 @@ | ||
import React from "react"; | ||
import { cn } from "@bootwind/common" | ||
|
||
export const TableRow = React.forwardRef< | ||
HTMLTableRowElement, | ||
React.HTMLAttributes<HTMLTableRowElement> | ||
>(({ className, children, ...props }, ref) => ( | ||
<> | ||
<tr | ||
ref={ref} | ||
className={cn("transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", className)} | ||
{...props} | ||
> | ||
{children} | ||
</tr> | ||
</> | ||
)) |
Oops, something went wrong.