Skip to content

Commit 9f4f3aa

Browse files
committed
Code review changes
#1660
1 parent 2fd804c commit 9f4f3aa

6 files changed

Lines changed: 17 additions & 25 deletions

File tree

packages/code-studio/src/styleguide/Grids.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
GridThemeType,
66
MockGridModel,
77
MockTreeGridModel,
8-
GridThemeContext,
8+
ThemeContext,
99
} from '@deephaven/grid';
1010
import { IrisGrid } from '@deephaven/iris-grid';
1111
import { useApi } from '@deephaven/jsapi-bootstrap';
@@ -38,7 +38,7 @@ function Grids(): ReactElement {
3838
});
3939
return (
4040
<div>
41-
<GridThemeContext.Provider value={contextTheme}>
41+
<ThemeContext.Provider value={contextTheme}>
4242
<h2 className="ui-title">Grid</h2>
4343
<Flex {...sampleSectionIdAndClassesSpectrum('grids-grid')}>
4444
<Grid model={model} theme={theme} />
@@ -81,7 +81,7 @@ function Grids(): ReactElement {
8181
<Flex {...sampleSectionIdAndClassesSpectrum('grids-iris')} height={500}>
8282
<IrisGrid model={irisGridModel} />
8383
</Flex>
84-
</GridThemeContext.Provider>
84+
</ThemeContext.Provider>
8585
</div>
8686
);
8787
}

packages/code-studio/src/styleguide/ThemeColors.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/jsx-props-no-spreading */
2-
import React, { useEffect, useState } from 'react';
2+
import React, { useMemo } from 'react';
33
import { Tooltip, useTheme } from '@deephaven/components';
44
import { ColorUtils } from '@deephaven/utils';
55
import palette from '@deephaven/components/src/theme/theme-dark/theme-dark-palette.css?inline';
@@ -28,16 +28,8 @@ function buildSwatchDataGroups() {
2828
}
2929

3030
export function ThemeColors(): JSX.Element {
31-
const [swatchDataGroups, setSwatchDataGroups] = useState(
32-
buildSwatchDataGroups
33-
);
34-
3531
const { selectedThemeKey } = useTheme();
36-
37-
useEffect(() => {
38-
// Rebuild swatches when themes change
39-
setSwatchDataGroups(buildSwatchDataGroups());
40-
}, [selectedThemeKey]);
32+
const swatchDataGroups = useMemo(buildSwatchDataGroups, [selectedThemeKey]);
4133

4234
return (
4335
<>

packages/grid/src/Grid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
} from './EditableGridModel';
5858
import { EventHandlerResultOptions } from './EventHandlerResult';
5959
import { assertIsDefined } from './errors';
60-
import GridThemeContext from './GridThemeContext';
60+
import ThemeContext from './ThemeContext';
6161
import { DraggingColumn } from './mouse-handlers/GridColumnMoveMouseHandler';
6262
import {
6363
EditingCell,
@@ -211,7 +211,7 @@ export type GridState = {
211211
* Can also add onClick and onContextMenu handlers to add custom functionality and menus.
212212
*/
213213
class Grid extends PureComponent<GridProps, GridState> {
214-
static contextType = GridThemeContext;
214+
static contextType = ThemeContext;
215215

216216
static defaultProps = {
217217
canvasOptions: { alpha: false } as CanvasRenderingContext2DSettings,

packages/grid/src/GridThemeContext.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/grid/src/ThemeContext.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { GridTheme as GridThemeType } from './GridTheme';
3+
4+
export type ThemeContextValue = Partial<GridThemeType>;
5+
6+
export const ThemeContext: React.Context<ThemeContextValue> =
7+
React.createContext({});
8+
9+
export default ThemeContext;

packages/grid/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export * from './key-handlers';
2525
export * from './mouse-handlers';
2626
export * from './errors';
2727
export * from './EventHandlerResult';
28-
export * from './GridThemeContext';
28+
export * from './ThemeContext';
2929
export type { default as CellRenderer, CellRenderType } from './CellRenderer';
3030
export { default as TextCellRenderer } from './TextCellRenderer';
3131
export { default as DataBarCellRenderer } from './DataBarCellRenderer';

0 commit comments

Comments
 (0)