Skip to content

Commit

Permalink
feat: updatable key row of data table
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurD1 committed Sep 19, 2024
1 parent ce76b01 commit b61be3c
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface DataTableProps<TRow extends BaseRow, TComputed extends BaseRow> extend
columns?: Array<keyof (TRow & TComputed) | Array<keyof (TRow & TComputed)>>
onRowClick?: (row: TRow) => unknown
selected?: TRow
rowKey?: keyof TRow
}

const StyledTable = styled.table<DataTableVariantsProps>(() => [tw`min-w-full divide-y divide-gray-300 text-left`])
Expand Down Expand Up @@ -60,6 +61,7 @@ export function DataTable<TRow extends BaseRow, TComputed extends BaseRow = Base
types,
variant = "default",
selected = undefined,
rowKey = "id",
}: DataTableProps<TRow, TComputed>) {
return (
<StyledTable variant={variant}>
Expand Down Expand Up @@ -91,7 +93,8 @@ export function DataTable<TRow extends BaseRow, TComputed extends BaseRow = Base
: undefined
}
className={
"hover:bg-slate-50 cursor-pointer" + (selected && selected.id === row.id ? " bg-slate-100" : "")
"hover:bg-slate-50 cursor-pointer" +
(selected && selected[rowKey] === row[rowKey] ? " bg-slate-100" : "")
}
>
{columns?.map((name, index) => {
Expand Down

0 comments on commit b61be3c

Please sign in to comment.