diff --git a/src/components/Table/ActionCell.tsx b/src/components/Table/ActionCell.tsx deleted file mode 100644 index 078262f..0000000 --- a/src/components/Table/ActionCell.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { SimpleText } from "../SimpleText/SimpleText"; - -type Props = { - action: string; - - onClick: (data: unknown) => unknown | Promise; -}; - -export const ActionCell = ({ action, onClick }: Props) => ( - - - {action} - - -); diff --git a/src/components/Table/BreakCell.css b/src/components/Table/BreakCell.css deleted file mode 100644 index b4aabfa..0000000 --- a/src/components/Table/BreakCell.css +++ /dev/null @@ -1,3 +0,0 @@ -.cell--break { - word-break: break-all; -} diff --git a/src/components/Table/BreakCell.tsx b/src/components/Table/BreakCell.tsx deleted file mode 100644 index 7e64104..0000000 --- a/src/components/Table/BreakCell.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import "./BreakCell.css"; - -type Props = { - value: string; -}; - -export const BreakCell = ({ value }: Props) => ( - {value || " "} -); diff --git a/src/components/Table/Cell.css b/src/components/Table/Cell.css deleted file mode 100644 index f2a67c1..0000000 --- a/src/components/Table/Cell.css +++ /dev/null @@ -1,8 +0,0 @@ -.cell--action { - text-decoration: none; - transition: text-shadow 0.35s; -} - -.cell--action:hover { - text-shadow: var(--codex-color-primary) 0px 0 20px; -} diff --git a/src/components/Table/Cell.tsx b/src/components/Table/Cell.tsx index 6ffc253..834889f 100644 --- a/src/components/Table/Cell.tsx +++ b/src/components/Table/Cell.tsx @@ -1,7 +1,15 @@ -import "./Cell.css"; +import { ReactNode } from "react"; +import "./cell.css"; -type Props = { - value: string; -}; +export type CellProps = { + children: ReactNode | string; +} & React.DetailedHTMLProps< + React.TdHTMLAttributes, + HTMLTableCellElement +>; -export const Cell = ({ value }: Props) => {value}; +export const Cell = ({ children, className = "", ...rest }: CellProps) => ( + + {children} + +); diff --git a/src/components/Table/Row.tsx b/src/components/Table/Row.tsx new file mode 100644 index 0000000..a42da0b --- /dev/null +++ b/src/components/Table/Row.tsx @@ -0,0 +1,18 @@ +import { Fragment, ReactElement } from "react"; +import { Cell, CellProps } from "./Cell"; +import "./row.css"; + +export type RowProps = { + cells: ReactElement[]; + className?: string; +}; + +export function Row({ cells, className = "" }: RowProps) { + return ( + + {cells.map((Cell, index) => ( + {Cell} + ))} + + ); +} diff --git a/src/components/Table/StateCell.css b/src/components/Table/StateCell.css deleted file mode 100644 index 9035093..0000000 --- a/src/components/Table/StateCell.css +++ /dev/null @@ -1,24 +0,0 @@ -.cell-state { - border-radius: var(--codex-border-radius); - padding: 0.5rem; -} - -.cell-state--error { - background-color: rgba(var(--codex-color-error), 0.2); - color: rgb(var(--codex-color-error)); -} - -.cell-state--success { - background-color: rgba(var(--codex-color-success), 0.2); - color: rgb(var(--codex-color-success)); -} - -.cell-state--warning { - background-color: rgba(var(--codex-color-warning), 0.2); - color: rgb(var(--codex-color-warning)); -} - -.cell-state--loading { - background-color: rgba(var(--codex-color-grey), 0.2); - color: rgb(var(--codex-color-grey)); -} diff --git a/src/components/Table/StateCell.tsx b/src/components/Table/StateCell.tsx deleted file mode 100644 index 3d10792..0000000 --- a/src/components/Table/StateCell.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import "./StateCell.css"; - -type Props = { - type: "success" | "warning" | "error" | "default"; - value: string; -}; - -export const StateCell = ({ type, value }: Props) => { - return {value}; -}; diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index 2272fd3..cea8fb0 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -1,6 +1,7 @@ -import "./Table.css"; -import { ReactNode } from "react"; +import "./table.css"; import { Search } from "lucide-react"; +import { Row, RowProps } from "./Row"; +import { Fragment, ReactElement } from "react"; type Props = { /** @@ -8,17 +9,12 @@ type Props = { */ headers: string[]; - /** - * The ReactNode cells in two dimensions array, - * one for the lines - * one for the data representation - */ - cells: ReactNode[][]; - className?: string; + + rows: ReactElement[]; }; -export function Table({ headers, cells, className = "" }: Props) { +export function Table({ headers, rows, className = "" }: Props) { return (
@@ -32,22 +28,16 @@ export function Table({ headers, cells, className = "" }: Props) { - {cells.map((row, index) => ( - - {headers.map((header, idx) => ( - - ))} - + {rows.map((Row, index) => ( + {Row} ))}
- {row[idx]} -
- {!cells.length && ( + {!rows.length && (
-

No search results.

+

No data.

)}
diff --git a/src/components/Table/cell.css b/src/components/Table/cell.css new file mode 100644 index 0000000..7ce41de --- /dev/null +++ b/src/components/Table/cell.css @@ -0,0 +1,4 @@ +.cell { + text-align: left; + padding: 1rem; +} diff --git a/src/components/Table/row.css b/src/components/Table/row.css new file mode 100644 index 0000000..842284e --- /dev/null +++ b/src/components/Table/row.css @@ -0,0 +1,8 @@ +.row { + border-bottom: 1px solid var(--codex-border-color); + transition: background-color 0.35s; +} + +.row:hover { + background-color: var(--codex-background-light); +} diff --git a/src/components/Table/Table.css b/src/components/Table/table.css similarity index 74% rename from src/components/Table/Table.css rename to src/components/Table/table.css index a423c87..493d149 100644 --- a/src/components/Table/Table.css +++ b/src/components/Table/table.css @@ -36,17 +36,3 @@ text-align: left; padding: 1rem; } - -.table-tbodyTr { - border-bottom: 1px solid var(--codex-border-color); - transition: background-color 0.35s; -} - -.table-tbodyTr:hover { - background-color: var(--codex-background-light); -} - -.table-tbodyTd { - text-align: left; - padding: 1rem; -} diff --git a/src/index.ts b/src/index.ts index 569f39c..13253d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ export { Upload } from "./components/Upload/Upload"; export { Card } from "./components/Card/Card"; export { Select } from "./components/Select/Select"; export { Toast } from "./components/Toast/Toast"; -export { SpaceAllocation } from "./components/SpaceAllocation/SpaceAllocation"; +export { SpaceAllocation, type SpaceAllocationItem } from "./components/SpaceAllocation/SpaceAllocation"; export { EmptyPlaceholder } from "./components/EmptyPlaceholder/EmptyPlaceholder"; export { Dropdown, type DropdownOption } from "./components/Dropdown/Dropdown"; export { Failure } from "./components/Failure/Failure"; @@ -16,11 +16,9 @@ export { Spinner } from "./components/Spinner/Spinner"; export { WebFileIcon } from "./components/WebFileIcon/WebFileIcon"; export { Stepper } from "./components/Stepper/Stepper"; export { Backdrop } from "./components/Backdrop/Backdrop"; -export { ActionCell } from "./components/Table/ActionCell"; -export { BreakCell } from "./components/Table/BreakCell"; -export { Cell } from "./components/Table/Cell"; -export { StateCell } from "./components/Table/StateCell"; +export { Cell, type CellProps } from "./components/Table/Cell"; export { Table } from "./components/Table/Table"; +export { Row, type RowProps } from "./components/Table/Row"; export { Menu, type MenuItem, diff --git a/stories/Table.stories.tsx b/stories/Table.stories.tsx index 116ade8..5d84236 100644 --- a/stories/Table.stories.tsx +++ b/stories/Table.stories.tsx @@ -1,9 +1,8 @@ import type { Meta, StoryObj } from "@storybook/react"; import { Table } from "../src/components/Table/Table"; import "./Table.stories.css"; -import { StateCell } from "../src/components/Table/StateCell"; -import { ActionCell } from "../src/components/Table/ActionCell"; -import { BreakCell } from "../src/components/Table/BreakCell"; +import { Row } from "../src/components/Table/Row"; +import { Cell } from "../src"; const meta = { title: "Components/Table", @@ -20,77 +19,40 @@ type Story = StoryObj; export const Default: Story = { args: { - cells: [ - [ - Ox45678FDGHJKLBSA21, - My file, - Some data, - console.info("Hello")} - >, - ], + rows: [ + Ox45678FDGHJKLBSA21, + My file, + Some data, + Some data, + ]} + >, ], - headers: ["id", "title", "other", "actions"], + headers: ["id", "title", "other"], }, }; export const Scroll: Story = { args: { className: "tableSmall", - cells: [ - [ - Ox45678FDGHJKLBSA21, - My file, - Some data, - console.info("Hello")} - >, - ], + rows: [ + Ox45678FDGHJKLBSA21, + My file, + Some data, + Some data, + ]} + >, ], headers: ["id", "title", "other", "actions"], }, }; -export const BreakableCell: Story = { - args: { - cells: [ - [ - , - My file, - Some data, - console.info("Hello")} - >, - ], - ], - headers: ["break", "title", "other", "actions"], - className: "tableSmall", - }, -}; - -export const State: Story = { - args: { - cells: [ - [ - , - My file, - , - console.info("Hello")} - >, - ], - ], - headers: ["id", "title", "state", "actions"], - }, -}; - export const Empty: Story = { args: { - cells: [], + rows: [], headers: ["id", "title", "state", "actions"], }, };