import React from "react";
/**
* Product data table using --table-* tokens.
* columns: [{key, label, width?, align?}], rows: array of objects
* (cell values may be React nodes).
*/
export function Table({ columns = [], rows = [], caption, rowHeaderKey, style }) {
const [hoverRow, setHoverRow] = React.useState(-1);
return (
{caption && {caption}}
{columns.map((c) => (
|
{c.label}
|
))}
{rows.map((r, i) => (
setHoverRow(i)}
onMouseLeave={() => setHoverRow(-1)}
style={{ background: hoverRow === i ? "hsl(var(--table-row-hover))" : "transparent", transition: "background var(--duration-fast)" }}
>
{columns.map((c) => {
const Cell = rowHeaderKey && c.key === rowHeaderKey ? "th" : "td";
return (
|
{r[c.key]}
|
);})}
))}
);
}