-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added table for key-value pair columns
- Loading branch information
coderwelsch
committed
Nov 15, 2024
1 parent
1d36d67
commit 81efae6
Showing
9 changed files
with
241 additions
and
0 deletions.
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
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 @@ | ||
export { TableKeyValuePair } from "./table-key-value-pair"; |
25 changes: 25 additions & 0 deletions
25
src/components/table-key-value-pair/table-key-value-pair-body-key-cell.tsx
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,25 @@ | ||
import React from "react"; | ||
import { classNames } from "../../util/class-names"; | ||
|
||
type TableKeyValuePairBodyKeyProps = React.DetailedHTMLProps< | ||
React.TdHTMLAttributes<HTMLTableCellElement>, | ||
HTMLTableCellElement | ||
>; | ||
|
||
export const TableKeyValuePairBodyKeyCell = ({ | ||
children, | ||
className, | ||
...props | ||
}: TableKeyValuePairBodyKeyProps) => { | ||
return ( | ||
<td | ||
className={classNames( | ||
"headline-400 border-b border-r border-neutral-300 px-2.5 text-neutral-900 first:border-l", | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
</td> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
src/components/table-key-value-pair/table-key-value-pair-body-row.tsx
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,22 @@ | ||
import React from "react"; | ||
import { classNames } from "../../util/class-names"; | ||
|
||
type TableKeyValuePairBodyProps = React.TableHTMLAttributes<HTMLTableRowElement>; | ||
|
||
export const TableKeyValuePairBodyRow = ({ | ||
children, | ||
className, | ||
...props | ||
}: TableKeyValuePairBodyProps) => { | ||
return ( | ||
<tr | ||
className={classNames( | ||
"h-12 [&:last-child_>_td:first-child]:rounded-bl-md [&:last-child_>_td:first-child]:border-l [&:last-child_>_td:first-child]:border-neutral-300 [&:last-child_>_td:last-child]:rounded-br-md", | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
</tr> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
src/components/table-key-value-pair/table-key-value-pair-body-value-cell.tsx
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,25 @@ | ||
import React from "react"; | ||
import { classNames } from "../../util/class-names"; | ||
|
||
type TableKeyValuePairBodyValueProps = React.DetailedHTMLProps< | ||
React.TdHTMLAttributes<HTMLTableCellElement>, | ||
HTMLTableCellElement | ||
>; | ||
|
||
export const TableKeyValuePairBodyValueCell = ({ | ||
children, | ||
className, | ||
...props | ||
}: TableKeyValuePairBodyValueProps) => { | ||
return ( | ||
<td | ||
className={classNames( | ||
"border-b border-r border-neutral-300 px-2.5 text-neutral-900", | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
</td> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/components/table-key-value-pair/table-key-value-pair-body.tsx
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,16 @@ | ||
import React from "react"; | ||
import { TableKeyValuePairBodyRow } from "./table-key-value-pair-body-row"; | ||
import { TableKeyValuePairBodyValueCell } from "./table-key-value-pair-body-value-cell"; | ||
import { TableKeyValuePairBodyKeyCell } from "./table-key-value-pair-body-key-cell"; | ||
|
||
type TableKeyValuePairBodyProps = React.TableHTMLAttributes<HTMLTableSectionElement>; | ||
|
||
const TableKeyValuePairBody = ({ children, ...props }: TableKeyValuePairBodyProps) => { | ||
return <tbody {...props}>{children}</tbody>; | ||
}; | ||
|
||
TableKeyValuePairBody.Row = TableKeyValuePairBodyRow; | ||
TableKeyValuePairBody.Key = TableKeyValuePairBodyKeyCell; | ||
TableKeyValuePairBody.Value = TableKeyValuePairBodyValueCell; | ||
|
||
export { TableKeyValuePairBody }; |
26 changes: 26 additions & 0 deletions
26
src/components/table-key-value-pair/table-key-value-pair-header.tsx
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,26 @@ | ||
import React from "react"; | ||
import { classNames } from "../../util/class-names"; | ||
|
||
interface TableKeyValuePairHeaderProps extends React.HTMLAttributes<HTMLTableSectionElement> { | ||
colSpan?: number; | ||
} | ||
|
||
export const TableKeyValuePairHeader = ({ | ||
children, | ||
className, | ||
colSpan, | ||
...props | ||
}: TableKeyValuePairHeaderProps) => { | ||
return ( | ||
<thead className={classNames(className)} {...props}> | ||
<tr> | ||
<th | ||
className="headline-400 rounded-t-md border border-neutral-300 bg-neutral-50 px-2.5 py-4 text-left text-neutral-900" | ||
colSpan={colSpan} | ||
> | ||
{children} | ||
</th> | ||
</tr> | ||
</thead> | ||
); | ||
}; |
97 changes: 97 additions & 0 deletions
97
src/components/table-key-value-pair/table-key-value-pair.stories.tsx
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,97 @@ | ||
import React from "react"; | ||
import type { Meta } from "@storybook/react"; | ||
import { TableKeyValuePair } from "./table-key-value-pair"; | ||
import { FormField } from "../form-field"; | ||
|
||
const meta: Meta<typeof TableKeyValuePair> = { | ||
title: "Table / Key-Value Pairs", | ||
component: TableKeyValuePair, | ||
}; | ||
|
||
export default meta; | ||
|
||
interface Person { | ||
id: number; | ||
name: string; | ||
isDead?: boolean; | ||
} | ||
|
||
const people: Person[] = [ | ||
{ id: 1, name: "John Lennon", isDead: true }, | ||
{ id: 2, name: "Kenton Towne" }, | ||
{ id: 3, name: "Therese Wunsch" }, | ||
{ id: 4, name: "Benedict Kessler" }, | ||
{ id: 5, name: "Katelyn Rohan" }, | ||
]; | ||
|
||
const ExampleListbox = () => { | ||
const [selectedPerson, setSelectedPerson] = React.useState<null | Person>(null); | ||
|
||
return ( | ||
<FormField> | ||
<FormField.Listbox value={selectedPerson} onChange={setSelectedPerson}> | ||
<FormField.Listbox.Button> | ||
<FormField.Listbox.Button.TextValue | ||
value={selectedPerson?.name ?? null} | ||
placeholder="Select..." | ||
/> | ||
</FormField.Listbox.Button> | ||
|
||
<FormField.Listbox.Options> | ||
{people.map((person) => ( | ||
<FormField.Listbox.Option | ||
value={person} | ||
key={person.id} | ||
disabled={person.isDead} | ||
> | ||
<FormField.Listbox.Option.TextOption> | ||
{person.name} | ||
</FormField.Listbox.Option.TextOption> | ||
</FormField.Listbox.Option> | ||
))} | ||
</FormField.Listbox.Options> | ||
</FormField.Listbox> | ||
</FormField> | ||
); | ||
}; | ||
|
||
export const Default = () => { | ||
return ( | ||
<div className="min-h-[30rem]"> | ||
<TableKeyValuePair> | ||
<TableKeyValuePair.Header colSpan={4}>Details</TableKeyValuePair.Header> | ||
|
||
<TableKeyValuePair.Body> | ||
<TableKeyValuePair.Body.Row> | ||
<TableKeyValuePair.Body.Key>First Name</TableKeyValuePair.Body.Key> | ||
<TableKeyValuePair.Body.Value>John</TableKeyValuePair.Body.Value> | ||
|
||
<TableKeyValuePair.Body.Key>Age</TableKeyValuePair.Body.Key> | ||
<TableKeyValuePair.Body.Value>John</TableKeyValuePair.Body.Value> | ||
</TableKeyValuePair.Body.Row> | ||
|
||
<TableKeyValuePair.Body.Row> | ||
<TableKeyValuePair.Body.Key>Last Name</TableKeyValuePair.Body.Key> | ||
<TableKeyValuePair.Body.Value>Doe</TableKeyValuePair.Body.Value> | ||
|
||
<TableKeyValuePair.Body.Key>Birth</TableKeyValuePair.Body.Key> | ||
<TableKeyValuePair.Body.Value>01.01.1970</TableKeyValuePair.Body.Value> | ||
</TableKeyValuePair.Body.Row> | ||
|
||
<TableKeyValuePair.Body.Row> | ||
<TableKeyValuePair.Body.Key>Status</TableKeyValuePair.Body.Key> | ||
<TableKeyValuePair.Body.Value> | ||
<ExampleListbox /> | ||
</TableKeyValuePair.Body.Value> | ||
|
||
<TableKeyValuePair.Body.Value colSpan={2}> | ||
<a href="https://abusix.com" className="inline-link"> | ||
Open Comments | ||
</a> | ||
</TableKeyValuePair.Body.Value> | ||
</TableKeyValuePair.Body.Row> | ||
</TableKeyValuePair.Body> | ||
</TableKeyValuePair> | ||
</div> | ||
); | ||
}; |
28 changes: 28 additions & 0 deletions
28
src/components/table-key-value-pair/table-key-value-pair.tsx
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,28 @@ | ||
import React from "react"; | ||
import { classNames } from "../../util/class-names"; | ||
import { TableKeyValuePairHeader } from "./table-key-value-pair-header"; | ||
import { TableKeyValuePairBody } from "./table-key-value-pair-body"; | ||
|
||
type TableKeyValuePairProps = React.DetailedHTMLProps< | ||
React.TableHTMLAttributes<HTMLTableElement>, | ||
HTMLTableElement | ||
>; | ||
|
||
const TableKeyValuePair = ({ children, className, ...props }: TableKeyValuePairProps) => { | ||
Check failure on line 11 in src/components/table-key-value-pair/table-key-value-pair.tsx GitHub Actions / format-check
|
||
return ( | ||
<table | ||
className={classNames( | ||
"w-full table-fixed border-separate border-spacing-0 text-sm", | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
</table> | ||
); | ||
}; | ||
|
||
TableKeyValuePair.Header = TableKeyValuePairHeader; | ||
TableKeyValuePair.Body = TableKeyValuePairBody; | ||
|
||
export { TableKeyValuePair }; |