import "./components/ui/tidal.css"; import { useId, useState, type FormEvent, type SyntheticEvent } from "react"; import { TidalDataGrid, type TidalDataGridCell, type TidalDataGridColumn } from "./components/ui/data-grid"; import "./components/ui/data-grid.css"; const tidalExampleStyles = ".data-grid-demo {\n inline-size: 100%;\n max-inline-size: 860px;\n min-inline-size: 0;\n}\n.data-grid-demo-status {\n display: block;\n min-block-size: 20px;\n margin-block-start: 12px;\n color: var(--t-ink);\n font-size: 12px;\n line-height: 1.5;\n}\n.data-grid-demo-note {\n margin: 3px 0 0;\n color: var(--t-muted);\n font-size: 11px;\n line-height: 1.5;\n}"; interface ProjectRow { id: string; project: string; owner: string; seats: string; status: string; } const INITIAL_ROWS: ProjectRow[] = [ { id: "atlas", project: "Atlas onboarding", owner: "Mira Chen", seats: "18", status: "In review", }, { id: "relay", project: "Relay workspace", owner: "Owen Price", seats: "32", status: "Active", }, { id: "field", project: "Field notes", owner: "Sam Rivera", seats: "7", status: "Draft", }, ]; export function DataGridDemo() { const statusId = useId().replace(/:/g, ""); const [rows, setRows] = useState(INITIAL_ROWS); const [selected, setSelected] = useState>(new Set(["relay"])); const [activeCell, setActiveCell] = useState({ rowId: "atlas", columnId: "project", }); const [editingCell, setEditingCell] = useState( null, ); const [editValue, setEditValue] = useState(""); const [errors, setErrors] = useState>({}); const [status, setStatus] = useState("Select a cell or use the arrow keys."); const columns: readonly TidalDataGridColumn[] = [ { id: "project", header: "Project", accessibleLabel: "Project", renderCell: (row) => row.project, getEditValue: (row) => row.project, width: 220, error: (row) => errors[`${row.id}:project`], }, { id: "owner", header: "Owner", accessibleLabel: "Owner", renderCell: (row) => row.owner, getEditValue: (row) => row.owner, width: 180, error: (row) => errors[`${row.id}:owner`], }, { id: "seats", header: "Seats", accessibleLabel: "Seats", renderCell: (row) => row.seats, getEditValue: (row) => row.seats, inputType: "number", width: 110, align: "end", editorProps: () => ({ min: "0", inputMode: "numeric" }), error: (row) => errors[`${row.id}:seats`], }, { id: "status", header: "Status", accessibleLabel: "Status", renderCell: (row) => row.status, width: 140, }, ]; function beginEditing( cell: TidalDataGridCell | null, event: SyntheticEvent, ) { if (!cell) { setEditingCell(null); setStatus("Edit cancelled."); return; } const row = rows.find((item) => item.id === cell.rowId); const column = columns.find((item) => item.id === cell.columnId); if (!row || !column?.getEditValue) return; setEditValue(column.getEditValue(row)); setEditingCell(cell); setStatus( `Editing ${column.accessibleLabel.toLowerCase()} for ${row.project}.`, ); if (event.defaultPrevented) return; } function commit( cell: TidalDataGridCell, value: string, event: FormEvent, ) { event.preventDefault(); const next = value.trim(); const key = `${cell.rowId}:${cell.columnId}`; if ( !next || (cell.columnId === "seats" && (!/^\d+$/.test(next) || Number(next) > 999)) ) { setErrors((current) => ({ ...current, [key]: cell.columnId === "seats" ? "Enter 0 to 999 seats." : "Enter a value.", })); setStatus("Correct the highlighted cell."); return; } setRows((current) => current.map((row) => row.id === cell.rowId ? { ...row, [cell.columnId]: next } : row, ), ); setErrors((current) => { const copy = { ...current }; delete copy[key]; return copy; }); setEditingCell(null); setStatus("Local sample row updated."); } return (
row.id} getRowLabel={(row) => row.project} activeCell={activeCell} onActiveCellChange={(cell) => setActiveCell(cell)} editingCell={editingCell} editValue={editValue} onEditingCellChange={beginEditing} onEditValueChange={(value) => setEditValue(value)} onCellCommit={commit} selection={{ selectedRowIds: selected, onSelectionChange: (ids) => { setSelected(ids); setStatus( `${ids.size} ${ids.size === 1 ? "row" : "rows"} selected.`, ); }, getRowLabel: (row) => row.project, }} /> {status}

Sample records only. Changes stay in this preview.

); } export default function AgentExample() { return (
); }