Skip to content

Commit b047fa3

Browse files
authored
feat: allow themes to use any srgb color for definitions (#1756)
Themes were previously limited to HSL raw value colors such that transparency could be created using HSLA. This made theme creation somewhat annoying and limiting. This change adopts color-mix (requires chrome 111, firefox 113 -- both older than 6 months) to create any necessary transparency. - replaces hsl raw values with hex (allows skipping color normalization) - replace hsla usage with color-mix - fix miss-named legend-color - created utils that use color-mix for easier specification - move utils.scss to be auto-imported with custom.scss - re-wrote color normilzation and resolving to resolve color-mix based colors - changed iris grid theme context to not accept a paritial Style changes: - style console input to match other inputs, add hover state to border - fix input border hover color to use correct variable - darken water color in dark theme maps] - adjust disabled button color in light theme] - fix selection background and selection hover color to be more subtle. (No idea why I made it so opaque, it used to be 0.09 pre-spectrum) BREAKING CHANGE: - IrisGridThemeContext no longer accepts a paritial theme. By guaranteeing the provider is a full theme we can resolve the CSS variables and normailze the colors only once per theme load globally, rather than having to do it once per grid. - Themes must be defined using valid srgb CSS colors, and not hsl raw component values
1 parent 3194c4b commit b047fa3

60 files changed

Lines changed: 1181 additions & 1412 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

jest.setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ Object.defineProperty(document, 'getAnimations', {
6868
value: () => [],
6969
writable: true,
7070
});
71+
72+
Object.defineProperty(window.CSS, 'supports', {
73+
value: () => true,
74+
writable: true,
75+
});

packages/chart/src/ChartTheme.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
paper-bgcolor: var(--dh-color-chart-bg);
66
plot-bgcolor: var(--dh-color-chart-plot-bg);
77
title-color: var(--dh-color-chart-title);
8-
legend-color: var(--dh-color-chart-legend-color);
8+
legend-color: var(--dh-color-chart-legend-fg);
99
colorway: var(--dh-color-chart-colorway);
1010
gridcolor: var(--dh-color-chart-grid);
1111
linecolor: var(--dh-color-chart-axis-line);

packages/code-studio/src/settings/SettingsMenu.scss

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ $settings-menu-rule-border: $gray-400;
1414
$settings-menu-rule-focused-border: $primary;
1515

1616
$focus-over-primary-color: var(--dh-color-fg);
17-
$input-btn-focus-box-shadow-over-primary: 0 0 0 0.2rem
18-
hsla(var(--dh-color-fg-hsl), 0.35);
17+
$input-btn-focus-box-shadow-over-primary: 0 0 0 0.2rem fg-opacity(35);
18+
19+
$btn-focus-bg: fg-opacity($focus-bg-transparency);
20+
$btn-hover-bg: fg-opacity($hover-bg-transparency);
21+
$btn-active-bg: fg-opacity($active-bg-transparency);
1922

2023
$settings-menu-z-index: $zindex-modal;
2124

@@ -76,22 +79,22 @@ $settings-menu-z-index: $zindex-modal;
7679

7780
&:focus {
7881
&::after {
79-
background: hsla(var(--dh-color-fg-hsl), $focus-bg-transparency);
82+
background: $btn-focus-bg;
8083
border: 1px solid var(--dh-color-fg);
8184
box-shadow: $input-btn-focus-box-shadow-over-primary;
8285
}
8386
}
8487

8588
&:hover {
8689
&::after {
87-
background: hsla(var(--dh-color-fg-hsl), $hover-bg-transparency);
90+
background: $btn-hover-bg;
8891
}
8992
}
9093

9194
&:active {
9295
&::after {
9396
content: '';
94-
background: hsla(var(--dh-color-fg-hsl), $active-bg-transparency);
97+
background: $btn-active-bg;
9598
}
9699
}
97100
}
@@ -144,18 +147,18 @@ $settings-menu-z-index: $zindex-modal;
144147
height: 28px;
145148

146149
&:focus {
147-
background: hsla(var(--dh-color-fg-hsl), $focus-bg-transparency);
150+
background: $btn-focus-bg;
148151
border: 1px solid var(--dh-color-fg);
149152
box-shadow: $input-btn-focus-box-shadow-over-primary;
150153
}
151154

152155
&:hover {
153-
background: hsla(var(--dh-color-fg-hsl), $hover-bg-transparency);
156+
background: $btn-hover-bg;
154157
}
155158

156159
&:active {
157160
content: '';
158-
background: hsla(var(--dh-color-fg-hsl), $active-bg-transparency);
161+
background: $btn-active-bg;
159162
}
160163
}
161164
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { ReactNode, useMemo } from 'react';
22
import { Tooltip } from '@deephaven/components';
3-
import { ColorUtils } from '@deephaven/utils';
43
import { INVALID_COLOR_BORDER_STYLE } from './colorUtils';
54
import { useContrastFgColorRef, useDhColorFromPseudoContent } from './hooks';
65

@@ -24,7 +23,6 @@ export function Swatch({ className, children }: SwatchProps): JSX.Element {
2423
dhColor != null
2524
? {
2625
value: dhColor,
27-
normalized: ColorUtils.normalizeCssColor(dhColor, true),
2826
}
2927
: null,
3028
[dhColor]
@@ -43,7 +41,6 @@ export function Swatch({ className, children }: SwatchProps): JSX.Element {
4341
{hasValue && (
4442
<Tooltip interactive>
4543
<div>{tooltip.value}</div>
46-
<div>{tooltip.normalized}</div>
4744
</Tooltip>
4845
)}
4946
{children}

packages/code-studio/src/styleguide/ThemeColors.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
.swatch {
88
display: flex;
99
aspect-ratio: 4/3;
10-
align-items: start;
11-
justify-content: end;
10+
align-items: flex-start;
11+
justify-content: flex-end;
1212
}
1313
}
1414

packages/code-studio/src/styleguide/colorUtils.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getExpressionRanges } from '@deephaven/components';
12
import { ColorUtils } from '@deephaven/utils';
23

34
export const INVALID_COLOR_BORDER_STYLE = '2px solid var(--dh-color-notice-bg)';
@@ -136,11 +137,9 @@ export function extractColorVars(
136137
// values. We'll need to make this more robust if we ever change the
137138
// default themes to use non-hsl.
138139
if (varName === '--dh-color-chart-colorway') {
139-
const colorwayColors = value
140-
.split('hsl')
141-
.filter(Boolean)
142-
.map(v => `hsl${v.trim()}`);
143-
140+
const colorwayColors = getExpressionRanges(value ?? '').map(
141+
([start, end]) => value.substring(start, end + 1)
142+
);
144143
return colorwayColors.map((varExp, i) => ({
145144
name: `${varName}-${i}`,
146145
value: varExp,
@@ -170,8 +169,8 @@ export function buildColorGroups(
170169

171170
const groupData = swatchData.reduce(
172171
(acc, { name, value }) => {
173-
// Skip -hsl variables since they aren't actually colors yet
174-
if (/^--dh-color-(.*?)-hsl$/.test(name)) {
172+
// Skip true black/white
173+
if (/^--dh-color-true-(.*?)$/.test(name)) {
175174
return acc;
176175
}
177176

@@ -208,14 +207,7 @@ export function buildColorGroups(
208207
return acc;
209208
}
210209

211-
// It might be nice to make these dynamic, but for now just hardcode
212-
const note = {
213-
'--dh-color-gray-900': 'light',
214-
'--dh-color-gray-600': 'mid',
215-
'--dh-color-gray-300': 'dark',
216-
}[name];
217-
218-
acc[group].push({ name, value, note });
210+
acc[group].push({ name, value });
219211

220212
return acc;
221213
},

packages/components/scss/BaseStyleSheet.scss

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Import our custom variables and bootstrap
22
// Can be imported directly by Vite since it resolves bootstrap to node_modules/bootstrap
33
@import './custom.scss';
4-
@import './util.scss';
54
@import './bootstrap_imports.scss';
65

76
:root {
@@ -24,10 +23,10 @@ html {
2423

2524
// override
2625
.text-black-50 {
27-
color: background-opacity(50) !important;
26+
color: bg-opacity(50) !important;
2827
}
2928
.text-white-50 {
30-
color: foreground-opacity(50) !important;
29+
color: fg-opacity(50) !important;
3130
}
3231

3332
// deephaven-icons are designed on a 16px grid
@@ -46,7 +45,7 @@ body {
4645
padding: 0;
4746
overscroll-behavior: none;
4847
-ms-scroll-chaining: none;
49-
scrollbar-color: foreground-opacity(10) background-opacity(10); //applies to firefox only
48+
scrollbar-color: fg-opacity(10) bg-opacity(10); //applies to firefox only
5049
}
5150

5251
#root {
@@ -662,7 +661,7 @@ input[type='number']::-webkit-inner-spin-button {
662661

663662
// style the same as monaco scrollbar
664663
::-webkit-scrollbar-thumb {
665-
background: hsla(var(--dh-color-scrollbar-hsl), 0.18);
664+
background: color-mix(in srgb, var(--dh-color-scrollbar) 18%, transparent);
666665
border-radius: 0;
667666
}
668667

@@ -672,23 +671,25 @@ input[type='number']::-webkit-inner-spin-button {
672671
}
673672

674673
::-webkit-scrollbar-corner {
675-
background: background-opacity(10);
674+
background: bg-opacity(10);
676675
}
677676

678677
::-webkit-scrollbar-track:horizontal {
679-
border-top: 1px solid hsla(var(--dh-color-scrollbar-hsl), 0.15);
678+
border-top: 1px solid
679+
color-mix(in srgb, var(--dh-color-scrollbar) 15%, transparent);
680680
}
681681

682682
::-webkit-scrollbar-track:vertical {
683-
border-left: 1px solid hsla(var(--dh-color-scrollbar-hsl), 0.15);
683+
border-left: 1px solid
684+
color-mix(in srgb, var(--dh-color-scrollbar) 15%, transparent);
684685
}
685686

686687
::-webkit-scrollbar-thumb:hover {
687-
background: hsla(var(--dh-color-scrollbar-hsl), 0.25);
688+
background: color-mix(in srgb, var(--dh-color-scrollbar) 25%, transparent);
688689
}
689690

690691
::-webkit-scrollbar-thumb:active {
691-
background: hsla(var(--dh-color-scrollbar-hsl), 0.35);
692+
background: color-mix(in srgb, var(--dh-color-scrollbar) 35%, transparent);
692693
}
693694

694695
/********** Monaco Overides *********/

packages/components/scss/bootstrap_override_mixins_buttons.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
// DH Customization: Convert semantic value to css variables
1010
$background: var(--dh-color-#{$semantic-value}-bg);
1111
$border: var(--dh-color-#{$semantic-value}-bg);
12-
$boxshadow-color: hsla(var(--dh-color-#{$semantic-value}-hsl), 0.5);
12+
$boxshadow-color: color-mix(
13+
in srgb,
14+
var(--dh-color-#{$semantic-value}-bg) 50%,
15+
transparent
16+
);
1317
$hover-background: var(--dh-color-#{$semantic-value}-hover-bg);
1418
$hover-border: var(--dh-color-#{$semantic-value}-hover-bg);
1519
$active-background: var(--dh-color-#{$semantic-value}-down-bg);
@@ -76,7 +80,11 @@
7680
$semantic-value: map.get($bootstrap-dh-semantic-map, $bootstrap-value) or '';
7781

7882
$color: var(--dh-color-#{$semantic-value}-bg);
79-
$boxshadow-color: hsla(var(--dh-color-#{$semantic-value}-hsl), 0.5);
83+
$boxshadow-color: color-mix(
84+
in srgb,
85+
var(--dh-color-#{$semantic-value}-bg) 50%,
86+
transparent
87+
);
8088
$hover-color: color-yiq($semantic-value);
8189
$hover-background: var(--dh-color-#{$semantic-value}-hover-bg);
8290
$active-background: var(--dh-color-#{$semantic-value}-down-bg);

packages/components/scss/bootstrap_overrides.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ $input-placeholder-color: var(--dh-color-input-placeholder);
177177
$input-focus-border-color: var(--dh-color-input-focus-border);
178178

179179
$input-btn-focus-width: 0.2rem;
180-
$input-btn-focus-color: hsla(var(--dh-color-accent-hsl), 0.35);
180+
$input-btn-focus-color: color-mix(
181+
in srgb,
182+
var(--dh-color-accent) 35%,
183+
transparent
184+
);
181185
$input-btn-focus-box-shadow: 0 0 0 $input-btn-focus-width $input-btn-focus-color;
182186
$input-btn-line-height: 1.3;
183187
// Bootstrap uses a calc expression to determine the input height (calc(line-height + 2*padding-y + border)).

packages/components/scss/custom.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
//New variables come after imports
1515
@import './new_variables.scss';
16+
@import './util.scss';

0 commit comments

Comments
 (0)