Skip to content

Commit 609c57e

Browse files
authored
feat(@deephaven/components): Custom React Spectrum Provider (#1211)
Custom React Spectrum Provider component. resolves #1210
1 parent e485c86 commit 609c57e

11 files changed

Lines changed: 215 additions & 1 deletion

__mocks__/spectrumThemeDarkMock.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'dh-spectrum-theme--dark': 'mock.dark',
3+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'dh-spectrum-theme--light': 'mock.light',
3+
};

jest.config.base.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ module.exports = {
55
'.(ts|tsx|js|jsx)': ['babel-jest', { rootMode: 'upward' }],
66
},
77
// Makes jest transform monaco, but continue ignoring other node_modules. Used for MonacoUtils test
8-
transformIgnorePatterns: ['node_modules/(?!(monaco-editor|d3-interpolate|d3-color)/)'],
8+
transformIgnorePatterns: [
9+
'node_modules/(?!(monaco-editor|d3-interpolate|d3-color)/)',
10+
],
911
moduleNameMapper: {
12+
'SpectrumTheme([^.]+)\\.module\\.scss$': path.join(
13+
__dirname,
14+
'./__mocks__/spectrumTheme$1Mock.js'
15+
),
1016
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
1117
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': path.join(
1218
__dirname,

package-lock.json

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@deephaven/utils": "file:../utils",
3030
"@fortawesome/fontawesome-svg-core": "^6.2.1",
3131
"@fortawesome/react-fontawesome": "^0.2.0",
32+
"@react-spectrum/theme-default": "^3.5.1",
3233
"bootstrap": "4.6.2",
3334
"classnames": "^2.3.1",
3435
"event-target-shim": "^6.0.2",

packages/components/scss/util.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// Utilty for increasing specificity by repeating a given selector n number of
2+
/// times.
3+
///
4+
/// It should work for selectors that can be concatenated without delimiters
5+
/// such as '.some-selector.some-selector', '#some-id#some-id', or '&&'. A
6+
/// case where it would not work would be with an element selector e.g. 'divdiv'.
7+
///
8+
/// Example usage:
9+
///
10+
/// #{multiply-specificity-n('.some-selector', 2)} {
11+
/// }
12+
///
13+
/// would produce
14+
///
15+
/// .some-selector.some-selector {
16+
/// }
17+
///
18+
/// @param {string} $selector the selector to duplicate
19+
/// @param {number} $n number of times to duplicate
20+
/// @return {string} duplicated selector
21+
@function multiply-specificity-n($selector, $n) {
22+
$result: $selector;
23+
@for $i from 2 through $n {
24+
$result: selector-append($result, $selector);
25+
}
26+
27+
@return $result;
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
This module contains overrides of React Spectrum css variables for the default
3+
`dark` Deephaven theme.
4+
*/
5+
@use '../scss/bootstrap_overrides' as bootstrap;
6+
@use '../scss/util' as *;
7+
8+
// Doubling specificity to ensure this takes precedence over default Spectrum
9+
// styles.
10+
#{multiply-specificity-n('.dh-spectrum-theme--dark', 2)} {
11+
--spectrum-alias-background-color-default: #{bootstrap.$interfaceblack};
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
This module contains overrides of React Spectrum css variables for the default
3+
`light` Deephaven theme.
4+
*/
5+
@use '../scss/bootstrap_overrides' as bootstrap;
6+
@use '../scss/util' as *;
7+
8+
// Doubling specificity to ensure this takes precedence over default Spectrum
9+
// styles.
10+
#{multiply-specificity-n('.dh-spectrum-theme--light', 2)} {
11+
--spectrum-alias-background-color-default: #{bootstrap.$interfacewhite};
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { theme } from '@react-spectrum/theme-default';
2+
import { themeDHDefault } from './SpectrumUtils';
3+
4+
describe('themeDHDefault', () => {
5+
it('should merge Spectrum default with DH custom styles', () => {
6+
const { global, light, dark, medium, large } = theme;
7+
8+
expect(themeDHDefault).toEqual({
9+
global,
10+
light: {
11+
...light,
12+
'dh-spectrum-theme--light': 'mock.light',
13+
},
14+
dark: {
15+
...dark,
16+
'dh-spectrum-theme--dark': 'mock.dark',
17+
},
18+
medium,
19+
large,
20+
});
21+
});
22+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { theme } from '@react-spectrum/theme-default';
2+
import darkDH from './SpectrumThemeDark.module.scss';
3+
import lightDH from './SpectrumThemeLight.module.scss';
4+
5+
const { global, light, dark, medium, large } = theme;
6+
7+
/**
8+
* Extend light + dark theme variables with DH defaults.
9+
*
10+
* A theme is just a mapped collection of css class names that are generated
11+
* from a collection of css modules.
12+
*
13+
* e.g.
14+
* {
15+
* global: {
16+
* spectrum: 'spectrum_9e130c',
17+
* 'spectrum--medium': 'spectrum--medium_9e130c',
18+
* 'spectrum--large': 'spectrum--large_9e130c',
19+
* 'spectrum--darkest': 'spectrum--darkest_9e130c',
20+
* 'spectrum--dark': 'spectrum--dark_9e130c',
21+
* 'spectrum--light': 'spectrum--light_9e130c',
22+
* 'spectrum--lightest': 'spectrum--lightest_9e130c',
23+
* },
24+
* light: {
25+
* 'spectrum--light': 'spectrum--light_a40724',
26+
* 'dh-spectrum-theme--light': '_dh-spectrum-theme--light_1hblg_22',
27+
* },
28+
* dark: {
29+
* 'spectrum--darkest': 'spectrum--darkest_256eeb',
30+
* 'dh-spectrum-theme--dark': '_dh-spectrum-theme--dark_f7kge_22',
31+
* },
32+
* medium: {
33+
* 'spectrum--medium': 'spectrum--medium_4b172c',
34+
* },
35+
* large: {
36+
* 'spectrum--large': 'spectrum--large_c40598',
37+
* },
38+
* }
39+
*/
40+
/* eslint-disable import/prefer-default-export */
41+
export const themeDHDefault = {
42+
global,
43+
light: {
44+
...light,
45+
...lightDH,
46+
},
47+
dark: {
48+
...dark,
49+
...darkDH,
50+
},
51+
// scales
52+
medium,
53+
large,
54+
};

0 commit comments

Comments
 (0)