From 7ab9216abae29bd5abb3aaf64b2e607575187267 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 14 Sep 2026 00:25:49 +0100 Subject: [PATCH] website: adopt `` in a couple places --- website/components/DraggableRowRenderer.tsx | 49 ++++++++++----------- website/root.css | 8 ++++ website/routes/ColumnsReordering.tsx | 45 +++++++++++-------- website/routes/RowsReordering.tsx | 21 ++++----- 4 files changed, 69 insertions(+), 54 deletions(-) diff --git a/website/components/DraggableRowRenderer.tsx b/website/components/DraggableRowRenderer.tsx index 283b216265..af710e0342 100644 --- a/website/components/DraggableRowRenderer.tsx +++ b/website/components/DraggableRowRenderer.tsx @@ -1,11 +1,13 @@ -import { useState } from 'react'; +import { startTransition, useState, ViewTransition } from 'react'; import { css } from 'ecij'; import clsx from 'clsx'; import { Row, type RenderRowProps } from '../../src'; -const rowDraggingClassname = css` - opacity: 0.5; +const draggableRowClassname = css` + :root:active-view-transition &:focus-within { + z-index: 1; + } `; const rowOverClassname = css` @@ -22,29 +24,25 @@ export function DraggableRowRenderer({ onRowReorder, ...props }: DraggableRowRenderProps) { - const [isDragging, setIsDragging] = useState(false); const [isOver, setIsOver] = useState(false); - className = clsx(className, { - [rowDraggingClassname]: isDragging, + className = clsx(className, draggableRowClassname, { [rowOverClassname]: isOver }); function onDragStart(event: React.DragEvent) { - setIsDragging(true); event.dataTransfer.setData('text/plain', String(rowIdx)); event.dataTransfer.dropEffect = 'move'; } - function onDragEnd() { - setIsDragging(false); - } - function onDrop(event: React.DragEvent) { - setIsOver(false); // prevent the browser from redirecting in some cases event.preventDefault(); - onRowReorder(Number(event.dataTransfer.getData('text/plain')), rowIdx); + setIsOver(false); + + startTransition(() => { + onRowReorder(Number(event.dataTransfer.getData('text/plain')), rowIdx); + }); } function onDragEnter(event: React.DragEvent) { @@ -60,18 +58,19 @@ export function DraggableRowRenderer({ } return ( - + + + ); } diff --git a/website/root.css b/website/root.css index 8b0e42b892..69d0c261a4 100644 --- a/website/root.css +++ b/website/root.css @@ -30,3 +30,11 @@ body { .fill-grid { block-size: 100%; } + +@media (prefers-reduced-motion: reduce) { + ::view-transition-group(*), + ::view-transition-old(*), + ::view-transition-new(*) { + animation: none !important; + } +} diff --git a/website/routes/ColumnsReordering.tsx b/website/routes/ColumnsReordering.tsx index 0f1bb4cc74..aa55a0400c 100644 --- a/website/routes/ColumnsReordering.tsx +++ b/website/routes/ColumnsReordering.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useState } from 'react'; +import { startTransition, useCallback, useMemo, useState, ViewTransition } from 'react'; import { createFileRoute } from '@tanstack/react-router'; import { DataGrid, type Column, type ColumnWidths, type SortColumn } from '../../src'; @@ -33,6 +33,10 @@ function createRows(): readonly Row[] { return rows; } +function rowKeyGetter(row: Row): number { + return row.id; +} + const columns: Column[] = [ { key: 'id', @@ -113,7 +117,7 @@ function ColumnsReordering() { }, [rows, sortColumns]); function onColumnsReorder(sourceKey: string, targetKey: string) { - function reorderColumns() { + startTransition(() => { setColumnsOrder((columnsOrder) => { const sourceColumnOrderIndex = columnsOrder.findIndex( (index) => columns[index].key === sourceKey @@ -126,14 +130,14 @@ function ColumnsReordering() { newColumnsOrder.splice(targetColumnOrderIndex, 0, sourceColumnOrder); return newColumnsOrder; }); - } - - document.startViewTransition(reorderColumns); + }); } function resetOrderAndWidths() { - setColumnsOrder(initialColumnsOrder); - setColumnWidths(new Map()); + startTransition(() => { + setColumnsOrder(initialColumnsOrder); + setColumnWidths(new Map()); + }); } return ( @@ -148,18 +152,21 @@ function ColumnsReordering() { > Reset Columns - + + + ); } diff --git a/website/routes/RowsReordering.tsx b/website/routes/RowsReordering.tsx index ebf27b36fc..e3b37e4d8a 100644 --- a/website/routes/RowsReordering.tsx +++ b/website/routes/RowsReordering.tsx @@ -33,6 +33,10 @@ function createRows(): readonly Row[] { return rows; } +function rowKeyGetter(row: Row): number { + return row.id; +} + const columns: readonly Column[] = [ { key: 'id', @@ -64,16 +68,12 @@ function RowsReordering() { const renderRow = useCallback((key: React.Key, props: RenderRowProps) => { function onRowReorder(fromIndex: number, toIndex: number) { - function reorderRows() { - setRows((rows) => { - const row = rows[fromIndex]; - const newRows = rows.toSpliced(fromIndex, 1); - newRows.splice(toIndex, 0, row); - return newRows; - }); - } - - document.startViewTransition(reorderRows); + setRows((rows) => { + const row = rows[fromIndex]; + const newRows = rows.toSpliced(fromIndex, 1); + newRows.splice(toIndex, 0, row); + return newRows; + }); } return key={key} {...props} onRowReorder={onRowReorder} />; @@ -85,6 +85,7 @@ function RowsReordering() { columns={columns} rows={rows} onRowsChange={setRows} + rowKeyGetter={rowKeyGetter} renderers={{ renderRow }} direction={direction} />