diff --git a/src/components/index.ts b/src/components/index.ts index 84d51102..ab1e1fad 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -25,6 +25,7 @@ export { SpinnerOverlay } from "./spinner-overlay"; export { Tab } from "./tab"; export { TableUnvirtualized } from "./table-unvirtualized"; export { TableVirtualized, TableVirtualizedProps } from "./table-virtualized"; +export { TableKeyValuePair } from "./table-key-value-pair"; export { Tag } from "./tag"; export { Toast } from "./toast"; export { Toggle } from "./toggle"; diff --git a/src/components/table-key-value-pair/index.ts b/src/components/table-key-value-pair/index.ts new file mode 100644 index 00000000..6b726d23 --- /dev/null +++ b/src/components/table-key-value-pair/index.ts @@ -0,0 +1 @@ +export { TableKeyValuePair } from "./table-key-value-pair"; diff --git a/src/components/table-key-value-pair/table-key-value-pair-body-key-cell.tsx b/src/components/table-key-value-pair/table-key-value-pair-body-key-cell.tsx new file mode 100644 index 00000000..01eedefa --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair-body-key-cell.tsx @@ -0,0 +1,25 @@ +import React from "react"; +import { classNames } from "../../util/class-names"; + +export type TableKeyValuePairBodyKeyProps = React.DetailedHTMLProps< + React.TdHTMLAttributes, + HTMLTableCellElement +>; + +export const TableKeyValuePairBodyKeyCell = ({ + children, + className, + ...props +}: TableKeyValuePairBodyKeyProps) => { + return ( + + {children} + + ); +}; diff --git a/src/components/table-key-value-pair/table-key-value-pair-body-row.tsx b/src/components/table-key-value-pair/table-key-value-pair-body-row.tsx new file mode 100644 index 00000000..ff68a9f7 --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair-body-row.tsx @@ -0,0 +1,22 @@ +import React from "react"; +import { classNames } from "../../util/class-names"; + +export type TableKeyValuePairBodyProps = React.TableHTMLAttributes; + +export const TableKeyValuePairBodyRow = ({ + children, + className, + ...props +}: TableKeyValuePairBodyProps) => { + return ( + _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} + + ); +}; diff --git a/src/components/table-key-value-pair/table-key-value-pair-body-value-cell.tsx b/src/components/table-key-value-pair/table-key-value-pair-body-value-cell.tsx new file mode 100644 index 00000000..5b79f3be --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair-body-value-cell.tsx @@ -0,0 +1,25 @@ +import React from "react"; +import { classNames } from "../../util/class-names"; + +export type TableKeyValuePairBodyValueProps = React.DetailedHTMLProps< + React.TdHTMLAttributes, + HTMLTableCellElement +>; + +export const TableKeyValuePairBodyValueCell = ({ + children, + className, + ...props +}: TableKeyValuePairBodyValueProps) => { + return ( + + {children} + + ); +}; diff --git a/src/components/table-key-value-pair/table-key-value-pair-body.tsx b/src/components/table-key-value-pair/table-key-value-pair-body.tsx new file mode 100644 index 00000000..f70c4e78 --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair-body.tsx @@ -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"; + +export type TableKeyValuePairBodyProps = React.TableHTMLAttributes; + +const TableKeyValuePairBody = ({ children, ...props }: TableKeyValuePairBodyProps) => { + return {children}; +}; + +TableKeyValuePairBody.Row = TableKeyValuePairBodyRow; +TableKeyValuePairBody.Key = TableKeyValuePairBodyKeyCell; +TableKeyValuePairBody.Value = TableKeyValuePairBodyValueCell; + +export { TableKeyValuePairBody }; diff --git a/src/components/table-key-value-pair/table-key-value-pair-header.tsx b/src/components/table-key-value-pair/table-key-value-pair-header.tsx new file mode 100644 index 00000000..8571bbec --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair-header.tsx @@ -0,0 +1,27 @@ +import React from "react"; +import { classNames } from "../../util/class-names"; + +export interface TableKeyValuePairHeaderProps + extends React.HTMLAttributes { + colSpan?: number; +} + +export const TableKeyValuePairHeader = ({ + children, + className, + colSpan, + ...props +}: TableKeyValuePairHeaderProps) => { + return ( + + + + {children} + + + + ); +}; diff --git a/src/components/table-key-value-pair/table-key-value-pair.stories.tsx b/src/components/table-key-value-pair/table-key-value-pair.stories.tsx new file mode 100644 index 00000000..0c83d310 --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair.stories.tsx @@ -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 = { + 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); + + return ( + + + + + + + + {people.map((person) => ( + + + {person.name} + + + ))} + + + + ); +}; + +export const Default = () => { + return ( +
+ + Details + + + + First Name + John + + Age + John + + + + Last Name + Doe + + Birth + 01.01.1970 + + + + Status + + + + + + + Open Comments + + + + + +
+ ); +}; diff --git a/src/components/table-key-value-pair/table-key-value-pair.tsx b/src/components/table-key-value-pair/table-key-value-pair.tsx new file mode 100644 index 00000000..c6637ef9 --- /dev/null +++ b/src/components/table-key-value-pair/table-key-value-pair.tsx @@ -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"; + +export type TableKeyValuePairProps = React.DetailedHTMLProps< + React.TableHTMLAttributes, + HTMLTableElement +>; + +const TableKeyValuePair = ({ children, className, ...props }: TableKeyValuePairProps) => { + return ( + + {children} +
+ ); +}; + +TableKeyValuePair.Header = TableKeyValuePairHeader; +TableKeyValuePair.Body = TableKeyValuePairBody; + +export { TableKeyValuePair };