|
| 1 | +import green70 from '@patternfly/react-tokens/dist/esm/t_color_green_70'; |
| 2 | +import yellow70 from '@patternfly/react-tokens/dist/esm/t_color_yellow_70'; |
| 3 | +import blue70 from '@patternfly/react-tokens/dist/esm/t_color_blue_70'; |
| 4 | +import purple70 from '@patternfly/react-tokens/dist/esm/t_color_purple_70'; |
| 5 | +import green30 from '@patternfly/react-tokens/dist/esm/t_color_green_30'; |
| 6 | +import blue30 from '@patternfly/react-tokens/dist/esm/t_color_blue_30'; |
| 7 | +import yellow30 from '@patternfly/react-tokens/dist/esm/t_color_yellow_30'; |
| 8 | +import purple30 from '@patternfly/react-tokens/dist/esm/t_color_purple_30'; |
| 9 | +import white from '@patternfly/react-tokens/dist/esm/t_color_white'; |
| 10 | +import gray20 from '@patternfly/react-tokens/dist/esm/t_color_gray_20'; |
| 11 | +import gray60 from '@patternfly/react-tokens/dist/esm/t_color_gray_60'; |
| 12 | +import gray90 from '@patternfly/react-tokens/dist/esm/t_color_gray_90'; |
| 13 | +import black from '@patternfly/react-tokens/dist/esm/t_color_black'; |
| 14 | +import type { editor as monacoEditor } from 'monaco-editor/esm/vs/editor/editor.api'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Define the themes `pf-v6-code-editor-theme--light` and |
| 18 | + * `pf-v6-code-editor-theme--dark` for an instance of Monaco editor. |
| 19 | + * |
| 20 | + * Note that base tokens must be used as Monaco will throw a runtime |
| 21 | + * error for CSS variables. |
| 22 | + */ |
| 23 | +export const defineThemes = (editor: typeof monacoEditor) => { |
| 24 | + editor.defineTheme('pf-v6-theme-light', { |
| 25 | + base: 'vs', |
| 26 | + inherit: true, |
| 27 | + colors: { |
| 28 | + 'editor.background': white.value, |
| 29 | + 'editorLineNumber.activeForeground': black.value, |
| 30 | + 'editorLineNumber.foreground': gray60.value |
| 31 | + }, |
| 32 | + rules: [ |
| 33 | + { token: 'number', foreground: green70.value }, |
| 34 | + { token: 'type', foreground: yellow70.value }, |
| 35 | + { token: 'string', foreground: blue70.value }, |
| 36 | + { token: 'keyword', foreground: purple70.value } |
| 37 | + ] |
| 38 | + }); |
| 39 | + |
| 40 | + editor.defineTheme('pf-v6-theme-dark', { |
| 41 | + base: 'vs-dark', |
| 42 | + inherit: true, |
| 43 | + colors: { |
| 44 | + 'editor.background': gray90.value, |
| 45 | + 'editorLineNumber.activeForeground': white.value, |
| 46 | + 'editorLineNumber.foreground': gray20.value |
| 47 | + }, |
| 48 | + rules: [ |
| 49 | + { token: 'number', foreground: green30.value }, |
| 50 | + { token: 'type', foreground: blue30.value }, |
| 51 | + { token: 'string', foreground: yellow30.value }, |
| 52 | + { token: 'keyword', foreground: purple30.value } |
| 53 | + ] |
| 54 | + }); |
| 55 | +}; |
0 commit comments