Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

row style for todo status #488

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/actors/systems/kvSync/examples/todoMVC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ function TodoMVCInner(props: { client: Client; user: string }) {
<Table<Todo>
data={todos}
getKey={(row) => row.id}
getRowStyle={(todo) =>
todo.state.type === "Pending" && { color: "grey" }
}
columns={[
{
name: "Done",
Expand Down
47 changes: 27 additions & 20 deletions uiCommon/generic/table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { CSSProperties } from "react";

type ColumnSpec<T> = {
render: (row: T) => React.ReactNode;
Expand All @@ -10,6 +10,7 @@ export function Table<T>(props: {
data: T[];
columns: ColumnSpec<T>[];
getKey: (row: T, idx: number) => string;
getRowStyle?: (row: T) => CSSProperties;
}) {
return (
<table style={{ borderCollapse: "collapse", width: "100%" }}>
Expand Down Expand Up @@ -41,25 +42,31 @@ export function Table<T>(props: {
</td>
</tr>
) : null}
{props.data.map((row, rowIdx) => (
<tr key={props.getKey(row, rowIdx)} style={{ verticalAlign: "top" }}>
{props.columns.map((colSpec, colIdx) => (
<td
key={colSpec.name}
style={{
paddingLeft: 5,
paddingRight: 5,
borderRight:
colIdx === props.columns.length - 1
? "none"
: "1px solid lightgray",
}}
>
{colSpec.render(row)}
</td>
))}
</tr>
))}
{props.data.map((row, rowIdx) => {
const rowStyleRes = props.getRowStyle ? props.getRowStyle(row) : {};
return (
<tr
key={props.getKey(row, rowIdx)}
style={{ ...rowStyleRes, verticalAlign: "top" }}
>
{props.columns.map((colSpec, colIdx) => (
<td
key={colSpec.name}
style={{
paddingLeft: 5,
paddingRight: 5,
borderRight:
colIdx === props.columns.length - 1
? "none"
: "1px solid lightgray",
}}
>
{colSpec.render(row)}
</td>
))}
</tr>
);
})}
</tbody>
</table>
);
Expand Down
Loading