Skip to content

Commit 4eda17c

Browse files
authored
feat: Monaco theming (#1560)
- Base color palette now uses hsl colors with a single `--dh-color-xxx-hue` variable defining each of the base colors (see not in testing section below) - Updated Monaco theme to consume --dh-color variables - Refined default dark theme a bit with more semantic variables mostly in support of Monaco. - Utils for normalizing colors + deriving css variables **Methodology for Resolving Css Variables and Normalizing Colors** ThemeUtils.resolveCssVariablesInRecord(record, targetEl) - Add tmp div to target element for resolving variables - Extract distinct `var` expressions from values in given record - For each distinct `var` expression, create a tmp css variable on the temp div - Call getComputedStyle() on the tmp div - For each value on the given record - Replace `var` expressions with resolved values. Values are resolved using `getPropertyValue()` on the result of `getComputedStyle()` in previous step. - Normalize any color values to 8 character hex - Convert to rgb/a - ColorUtils.asRgbOrRgbaString() - create a non-attached div element, set its background color then read the background color - Parse rgb/a and convert to hex with math **Testing** The MonacoTheme object now gets passed through a normalization function. You can see the before and after in the debug logs "Monaco theme:" and "Monaco theme derived:". The inputs are various `var(--dh-` expressions`, and the outputs should all be 8 character hex values. > Note: The new base color palette is hsl based derived from original hex colors Don created in his theming work. A mapping of the original hex to the new hsl version can be found here: > https://bmingles.github.io/deephaven-theming-spike/ > resolves #1542 BREAKING CHANGE: Theme variables have to be present on body to avoid Monaco init failing
1 parent 645277f commit 4eda17c

21 files changed

Lines changed: 1279 additions & 133 deletions

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import React, { Suspense } from 'react';
22
import ReactDOM from 'react-dom';
33
import '@deephaven/components/scss/BaseStyleSheet.scss';
4-
import { LoadingOverlay } from '@deephaven/components';
4+
import {
5+
LoadingOverlay,
6+
preloadTheme,
7+
ThemeData,
8+
ThemeProvider,
9+
} from '@deephaven/components';
510
import { ApiBootstrap } from '@deephaven/jsapi-bootstrap';
611
import logInit from '../log/LogInit';
712

813
logInit();
914

15+
preloadTheme();
16+
17+
// Provide a non-null array to ThemeProvider to tell it to initialize
18+
const customThemes: ThemeData[] = [];
19+
1020
// eslint-disable-next-line react-refresh/only-export-components
1121
const StyleGuideRoot = React.lazy(() => import('./StyleGuideRoot'));
1222

@@ -24,9 +34,11 @@ const apiURL = new URL(
2434
ReactDOM.render(
2535
<ApiBootstrap apiUrl={apiURL.href} setGlobally>
2636
<Suspense fallback={<LoadingOverlay />}>
27-
<FontBootstrap>
28-
<StyleGuideRoot />
29-
</FontBootstrap>
37+
<ThemeProvider themes={customThemes}>
38+
<FontBootstrap>
39+
<StyleGuideRoot />
40+
</FontBootstrap>
41+
</ThemeProvider>
3042
</Suspense>
3143
</ApiBootstrap>,
3244
document.getElementById('root')

packages/components/scss/BaseStyleSheet.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ html {
2020

2121
body {
2222
min-height: 100%;
23-
background-color: var(--dh-background-color, $background);
23+
background-color: var(--dh-color-background, $background);
2424
color: $foreground;
2525
margin: 0;
2626
padding: 0;
@@ -30,7 +30,7 @@ body {
3030
}
3131

3232
#root {
33-
background-color: var(--dh-background-color, $background);
33+
background-color: var(--dh-color-background, $background);
3434

3535
.app {
3636
height: 100vh;

packages/components/src/LoadingSpinner.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.loading-spinner {
33
--primary-color: var(
44
--dh-loading-spinner-primary-color,
5-
var(--dh-accent-color, #4c7dee)
5+
var(--dh-color-accent, #4c7dee)
66
);
77
--secondary-color: var(
88
--dh-loading-spinner-secondary-color,

packages/components/src/theme/ThemeModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const DEFAULT_LIGHT_THEME_KEY = 'default-light' satisfies BaseThemeKey;
77

88
// Css properties that are used in preload data with default values.
99
export const DEFAULT_PRELOAD_DATA_VARIABLES = {
10-
'--dh-accent-color': '#4c7dee', // dark theme --dh-color-blue-700
11-
'--dh-background-color': '#1a171a', // dark theme --dh-color-gray-50
10+
'--dh-color-accent': '#4c7dee', // dark theme --dh-color-blue-700
11+
'--dh-color-background': '#1a171a', // dark theme --dh-color-gray-50
1212
} satisfies Record<`--dh-${string}`, string>;
1313

1414
export const THEME_CACHE_LOCAL_STORAGE_KEY = 'deephaven.themeCache';

packages/components/src/theme/ThemeProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function ThemeProvider({
3636

3737
const activeThemes = useMemo(
3838
() =>
39-
// Themes remain inactive until a non-null themes value is provided. This
39+
// Themes remain inactive until a non-null themes array is provided. This
4040
// avoids the default base theme overriding the preload if we are waiting
4141
// on additional themes to be available.
4242
themes == null

0 commit comments

Comments
 (0)