Skip to content

Commit 9c5501b

Browse files
committed
feat: restore custom light theme for CodeMirror, keep githubDark
Restore the previous custom light theme with original color scheme while keeping the githubDark theme for dark mode. Light theme colors: - Background: #fff (white) - Text: #2e3440 (dark gray) - Gutters: #f7f7f7 (light gray) - Keywords/strings: #5e81ac (muted blue) - Variables: #008080 (teal) Dark theme: githubDark (pre-built from @uiw/codemirror-theme-github) Changes: - DevfileViewer: custom light theme as extensions, githubDark as theme prop - BasicViewer: custom light theme as extension, githubDark as theme prop - Use useMemo to optimize light theme creation - Conditionally apply themes based on isDarkTheme state Assisted-by: Claude Sonnet 4.5 Signed-off-by: Oleksii Orel <oorel@redhat.com>
1 parent 59c8712 commit 9c5501b

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

.image-tag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pr-1452-03
1+
pr-1452-04

packages/dashboard-frontend/src/components/BasicViewer/index.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
* Red Hat, Inc. - initial API and implementation
1111
*/
1212

13-
import { githubDark, githubLight } from '@uiw/codemirror-theme-github';
13+
import { EditorView } from '@codemirror/view';
14+
import { githubDark } from '@uiw/codemirror-theme-github';
1415
import CodeMirror from '@uiw/react-codemirror';
15-
import React from 'react';
16+
import React, { useMemo } from 'react';
1617

1718
import styles from '@/components/BasicViewer/index.module.css';
1819
import { useTheme } from '@/contexts/ThemeContext';
@@ -22,17 +23,42 @@ export type Props = {
2223
id: string;
2324
};
2425

26+
const createLightTheme = () => {
27+
return EditorView.theme(
28+
{
29+
'&': {
30+
color: '#2e3440',
31+
backgroundColor: '#fff',
32+
},
33+
'.cm-activeLine': {
34+
backgroundColor: 'inherit',
35+
},
36+
'.cm-gutters': {
37+
backgroundColor: '#f7f7f7',
38+
color: '#999',
39+
},
40+
'.cm-activeLineGutter': {
41+
backgroundColor: '#f7f7f7',
42+
},
43+
},
44+
{ dark: false },
45+
);
46+
};
47+
2548
export const BasicViewer: React.FC<Props> = ({ value, id }) => {
2649
const { isDarkTheme } = useTheme();
2750

51+
const lightTheme = useMemo(() => createLightTheme(), []);
52+
2853
return (
2954
<div className={styles.basicViewer}>
3055
<CodeMirror
3156
id={id}
3257
readOnly={true}
3358
basicSetup={false}
3459
value={value}
35-
theme={isDarkTheme ? githubDark : githubLight}
60+
theme={isDarkTheme ? githubDark : undefined}
61+
extensions={isDarkTheme ? [] : [lightTheme]}
3662
/>
3763
</div>
3864
);

packages/dashboard-frontend/src/components/DevfileViewer/index.tsx

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
*/
1212

1313
import { yaml } from '@codemirror/lang-yaml';
14-
import { githubDark, githubLight } from '@uiw/codemirror-theme-github';
14+
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
15+
import { EditorView } from '@codemirror/view';
16+
import { githubDark } from '@uiw/codemirror-theme-github';
17+
import { tags as t } from '@lezer/highlight';
1518
import CodeMirror from '@uiw/react-codemirror';
16-
import React from 'react';
19+
import React, { useMemo } from 'react';
1720

1821
import styles from '@/components/DevfileViewer/index.module.css';
1922
import { useTheme } from '@/contexts/ThemeContext';
@@ -25,18 +28,59 @@ export type Props = {
2528
id: string;
2629
};
2730

31+
const createLightTheme = () => {
32+
return EditorView.theme(
33+
{
34+
'&': {
35+
color: '#2e3440',
36+
backgroundColor: '#fff',
37+
},
38+
'.cm-activeLine': {
39+
backgroundColor: 'inherit',
40+
},
41+
'.cm-gutters': {
42+
backgroundColor: '#f7f7f7',
43+
color: '#999',
44+
},
45+
'.cm-activeLineGutter': {
46+
backgroundColor: '#f7f7f7',
47+
},
48+
},
49+
{ dark: false },
50+
);
51+
};
52+
53+
const createLightHighlightStyle = () => {
54+
return HighlightStyle.define([
55+
{ tag: t.keyword, color: '#5e81ac' },
56+
{ tag: [t.string], color: '#5e81ac' },
57+
{ tag: [t.variableName], color: '#008080' },
58+
{
59+
tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName],
60+
color: '#008080',
61+
},
62+
]);
63+
};
64+
2865
export const DevfileViewer: React.FC<Props> = ({ isActive, isExpanded, value, id }) => {
2966
const { isDarkTheme } = useTheme();
3067

68+
const lightTheme = useMemo(() => createLightTheme(), []);
69+
const lightHighlightStyle = useMemo(() => createLightHighlightStyle(), []);
70+
3171
return (
3272
<div className={styles.devfileViewer}>
3373
<CodeMirror
3474
className={styles.codeMirror}
3575
readOnly={true}
3676
id={id}
3777
value={value}
38-
theme={isDarkTheme ? githubDark : githubLight}
39-
extensions={[yaml()]}
78+
theme={isDarkTheme ? githubDark : undefined}
79+
extensions={
80+
isDarkTheme
81+
? [yaml()]
82+
: [lightTheme, syntaxHighlighting(lightHighlightStyle), yaml()]
83+
}
4084
/>
4185
</div>
4286
);

0 commit comments

Comments
 (0)