Skip to content

Commit 7324728

Browse files
authored
Transition theme change (Comcast#3839)
1 parent adbee84 commit 7324728

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

website/Nav.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Link } from '@tanstack/react-router';
33
import { css } from '@linaria/core';
44

55
import type { Direction } from '../src/types';
6+
import { startViewTransition } from './utils';
67

78
const headerClassname = css`
89
border-inline-start: 4px solid light-dark(hsl(210deg 50% 80%), hsl(210deg 50% 40%));
@@ -62,13 +63,19 @@ export default function Nav({ direction, onDirectionChange }: Props) {
6263
const linksNavId = useId();
6364
const [theme, setTheme] = useState<Theme>('system');
6465

66+
function onThemeChange(theme: Theme) {
67+
startViewTransition(() => {
68+
setTheme(theme);
69+
});
70+
}
71+
6572
return (
6673
<header className={headerClassname}>
6774
<h1>react-data-grid</h1>
6875

6976
<label className={labelClassname}>
7077
Theme{' '}
71-
<select value={theme} onChange={(e) => setTheme(e.target.value as Theme)}>
78+
<select value={theme} onChange={(e) => onThemeChange(e.target.value as Theme)}>
7279
<option value="light">Light</option>
7380
<option value="dark">Dark</option>
7481
<option value="system">System</option>

website/routes/ColumnsReordering.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCallback, useMemo, useState } from 'react';
22

33
import { DataGrid } from '../../src';
44
import type { Column, ColumnWidths, SortColumn } from '../../src';
5+
import { startViewTransition } from '../utils';
56
import { useDirection } from '../directionContext';
67

78
export const Route = createFileRoute({
@@ -120,12 +121,7 @@ function ColumnsReordering() {
120121
});
121122
}
122123

123-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
124-
if (document.startViewTransition) {
125-
document.startViewTransition(reorderColumns);
126-
} else {
127-
reorderColumns();
128-
}
124+
startViewTransition(reorderColumns);
129125
}
130126

131127
function resetOrderAndWidths() {

website/routes/CommonFeatures.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
} from '../../src';
1515
import { textEditorClassname } from '../../src/editors/textEditor';
1616
import type { Direction } from '../../src/types';
17+
import { exportToCsv, exportToPdf } from '../utils';
1718
import { useDirection } from '../directionContext';
18-
import { exportToCsv, exportToPdf } from '../exportUtils';
1919

2020
export const Route = createFileRoute({
2121
component: CommonFeatures

website/routes/RowsReordering.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useState } from 'react';
33
import { DataGrid, textEditor } from '../../src';
44
import type { CellRendererProps, Column } from '../../src';
55
import { DraggableCellRenderer } from '../components';
6+
import { startViewTransition } from '../utils';
67
import { useDirection } from '../directionContext';
78

89
export const Route = createFileRoute({
@@ -73,12 +74,7 @@ function RowsReordering() {
7374
});
7475
}
7576

76-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
77-
if (document.startViewTransition) {
78-
document.startViewTransition(reorderRows);
79-
} else {
80-
reorderRows();
81-
}
77+
startViewTransition(reorderRows);
8278
}
8379

8480
return <DraggableCellRenderer key={key} {...props} onRowReorder={onRowReorder} />;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ function downloadFile(fileName: string, data: Blob) {
6161
downloadLink.click();
6262
URL.revokeObjectURL(url);
6363
}
64+
65+
export function startViewTransition(fn: ViewTransitionUpdateCallback) {
66+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
67+
if (document.startViewTransition) {
68+
document.startViewTransition(fn);
69+
} else {
70+
fn();
71+
}
72+
}

0 commit comments

Comments
 (0)