@@ -5,13 +5,15 @@ import DocumentStr from '@uiw/react-codemirror/README.md';
5
5
import { Extension } from '@codemirror/state' ;
6
6
import CodeMirror , { ReactCodeMirrorProps , BasicSetupOptions } from '@uiw/react-codemirror' ;
7
7
import styled from 'styled-components' ;
8
+ import * as alls from '@uiw/codemirror-themes-all' ;
8
9
import { langs } from '@uiw/codemirror-extensions-langs' ;
9
10
import { Select } from '../../Select' ;
10
11
import { Options } from '../extensions/basic-setup' ;
11
12
12
- const themeOptions = [ 'dark' , 'light' ] ;
13
+ const themeOptions = [ 'dark' , 'light' ]
14
+ . concat ( Object . keys ( alls ) )
15
+ . filter ( ( item ) => typeof alls [ item as keyof typeof alls ] !== 'function' ) ;
13
16
const heightOptions = [ 'auto' , '200px' , '300px' , '500px' ] ;
14
-
15
17
let count = 0 ;
16
18
17
19
const MarkdownDocument = styled . div `
@@ -92,7 +94,7 @@ export default function Example() {
92
94
< CodemirrorWarpper
93
95
value = { code }
94
96
height = { height }
95
- theme = { theme }
97
+ theme = { alls [ theme as keyof typeof alls ] || theme }
96
98
editable = { editable }
97
99
extensions = { extensions }
98
100
autoFocus = { autofocus }
@@ -115,14 +117,27 @@ export default function Example() {
115
117
onChange = { ( evn ) => handleLangChange ( evn . target . value as keyof typeof langs ) }
116
118
/>
117
119
< Select
118
- label = "Theme"
120
+ label = "Website Theme"
121
+ options = { [ 'dark' , 'light' ] }
122
+ value = { theme as string }
123
+ onChange = { ( evn ) => {
124
+ document . documentElement . setAttribute ( 'data-color-mode' , evn . target . value === 'dark' ? 'dark' : 'light' ) ;
125
+ setTheme ( evn . target . value as ReactCodeMirrorProps [ 'theme' ] ) ;
126
+ } }
127
+ />
128
+ < Select
129
+ label = "Themes"
119
130
options = { themeOptions }
120
131
value = { theme as string }
121
132
onChange = { ( evn ) => {
122
- document . documentElement . setAttribute ( 'data-color-mode' , evn . target . value ) ;
133
+ if ( / ^ ( d a r k | l i g h t ) $ / . test ( evn . target . value ) ) {
134
+ document . documentElement . setAttribute ( 'data-color-mode' , evn . target . value ) ;
135
+ }
123
136
setTheme ( evn . target . value as ReactCodeMirrorProps [ 'theme' ] ) ;
124
137
} }
125
138
/>
139
+ </ Tools >
140
+ < Tools >
126
141
< Select
127
142
label = "Height"
128
143
options = { heightOptions }
0 commit comments