diff --git a/src/components/Table/ActionCell.tsx b/src/components/Table/ActionCell.tsx new file mode 100644 index 0000000..c25ec9a --- /dev/null +++ b/src/components/Table/ActionCell.tsx @@ -0,0 +1,14 @@ +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/ActionCellRender.tsx b/src/components/Table/ActionCellRender.tsx deleted file mode 100644 index 6e91913..0000000 --- a/src/components/Table/ActionCellRender.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { SimpleText } from "../SimpleText/SimpleText"; - -export const ActionCellRender = - (action: string, onClick: (row: string[]) => void) => - (_: string, row: string[]) => { - return ( - { - e.preventDefault(); - onClick(row); - }} - className="cell--action" - > - - {action} - - - ); - }; diff --git a/src/components/Table/BreakCell.css b/src/components/Table/BreakCell.css new file mode 100644 index 0000000..b4aabfa --- /dev/null +++ b/src/components/Table/BreakCell.css @@ -0,0 +1,3 @@ +.cell--break { + word-break: break-all; +} diff --git a/src/components/Table/BreakCell.tsx b/src/components/Table/BreakCell.tsx new file mode 100644 index 0000000..7e64104 --- /dev/null +++ b/src/components/Table/BreakCell.tsx @@ -0,0 +1,9 @@ +import "./BreakCell.css"; + +type Props = { + value: string; +}; + +export const BreakCell = ({ value }: Props) => ( + {value || " "} +); diff --git a/src/components/Table/BreakCellRender.tsx b/src/components/Table/BreakCellRender.tsx deleted file mode 100644 index f0e2cd8..0000000 --- a/src/components/Table/BreakCellRender.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export const BreakCellRender = (val: string) => ( - {val || " "} -); diff --git a/src/components/Table/Cell.css b/src/components/Table/Cell.css new file mode 100644 index 0000000..f2a67c1 --- /dev/null +++ b/src/components/Table/Cell.css @@ -0,0 +1,8 @@ +.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 new file mode 100644 index 0000000..6ffc253 --- /dev/null +++ b/src/components/Table/Cell.tsx @@ -0,0 +1,7 @@ +import "./Cell.css"; + +type Props = { + value: string; +}; + +export const Cell = ({ value }: Props) => {value}; diff --git a/src/components/Table/CellRender.css b/src/components/Table/CellRender.css deleted file mode 100644 index c490888..0000000 --- a/src/components/Table/CellRender.css +++ /dev/null @@ -1,22 +0,0 @@ -.cell--break { - word-break: break-all; -} - -.cell--action { - text-decoration: none; - transition: text-shadow 0.35s; -} - -.cell--action:hover { - text-shadow: var(--codex-color-primary) 0px 0 20px; -} - -.cell-state { - border-radius: var(--codex-border-radius); - padding: 0.5rem 0.75rem; -} - -.cell-state--error { - background-color: var(--codex-color-error); - mix-blend-mode: difference; -} diff --git a/src/components/Table/CellRender.tsx b/src/components/Table/CellRender.tsx deleted file mode 100644 index c8809d2..0000000 --- a/src/components/Table/CellRender.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { ReactNode } from "react"; -import "./CellRender.css"; - -export type CellRender = ( - value: string, - row: string[], - index: number -) => ReactNode; - -export const DefaultCellRender = (val: string) => val; diff --git a/src/components/Table/DefaultCellRender.tsx b/src/components/Table/DefaultCellRender.tsx deleted file mode 100644 index 5ec8c84..0000000 --- a/src/components/Table/DefaultCellRender.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import "./CellRender.css"; - -export const DefaultCellRender = (val: string) => val; diff --git a/src/components/Table/DurationCellRender.tsx b/src/components/Table/DurationCellRender.tsx deleted file mode 100644 index a010b27..0000000 --- a/src/components/Table/DurationCellRender.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import prettyMilliseconds from "pretty-ms"; - -export function DurationCellRender(value: string) { - const ms = parseInt(value, 10); - if (isNaN(ms)) { - return "Nan"; - } - - return prettyMilliseconds(ms, { compact: true }); -} diff --git a/src/components/Table/StateCell.css b/src/components/Table/StateCell.css new file mode 100644 index 0000000..2aaf6da --- /dev/null +++ b/src/components/Table/StateCell.css @@ -0,0 +1,24 @@ +.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-blue), 0.2); + color: rgb(var(--codex-color-blue)); +} diff --git a/src/components/Table/StateCell.tsx b/src/components/Table/StateCell.tsx new file mode 100644 index 0000000..3d10792 --- /dev/null +++ b/src/components/Table/StateCell.tsx @@ -0,0 +1,10 @@ +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/StateCellRender.tsx b/src/components/Table/StateCellRender.tsx deleted file mode 100644 index 653bbcf..0000000 --- a/src/components/Table/StateCellRender.tsx +++ /dev/null @@ -1,11 +0,0 @@ -type Mapping = { [k: string]: "success" | "warning" | "error" | "default" }; - -export const StateCellRender = (mapping: Mapping) => (value: string) => { - return ( -

- - {value} - -

- ); -}; diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index ac93d52..87a3265 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -1,5 +1,5 @@ import "./Table.css"; -import { CellRender } from "./CellRender"; +import { ReactNode } from "react"; type Props = { /** @@ -7,21 +7,12 @@ type Props = { */ headers: string[]; - /** - * The data are represented by a 2 dimensions array. - * Each row contains a dataset whose data structure is a string array. - */ - data: string[][]; - - /** - * The cell render is an array of function that returns the cell data. - */ - cells: CellRender[]; + cells: ReactNode[][]; className?: string; }; -export function Table({ data, headers, cells, className }: Props) { +export function Table({ headers, cells, className }: Props) { return (
@@ -35,14 +26,14 @@ export function Table({ data, headers, cells, className }: Props) { - {data.map((row, index) => ( + {cells.map((row, index) => ( {headers.map((header, idx) => { - const render = cells[idx]; + const cell = row[idx]; return ( ); })}
- {render(row[idx], row, index)} + {cell}