Skip to content

Commit a4411dc

Browse files
committedDec 6, 2022
website: update website example.
1 parent 82fbc0e commit a4411dc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed
 

‎www/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@uiw/codemirror-extensions-langs": "4.17.1",
4444
"@uiw/codemirror-extensions-mentions": "4.17.1",
4545
"@uiw/codemirror-extensions-zebra-stripes": "4.17.1",
46+
"@uiw/codemirror-themes-all": "4.17.1",
4647
"@uiw/codemirror-theme-abcdef": "4.17.1",
4748
"@uiw/codemirror-theme-androidstudio": "4.17.1",
4849
"@uiw/codemirror-theme-atomone": "4.17.1",

‎www/src/pages/home/Example.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import DocumentStr from '@uiw/react-codemirror/README.md';
55
import { Extension } from '@codemirror/state';
66
import CodeMirror, { ReactCodeMirrorProps, BasicSetupOptions } from '@uiw/react-codemirror';
77
import styled from 'styled-components';
8+
import * as alls from '@uiw/codemirror-themes-all';
89
import { langs } from '@uiw/codemirror-extensions-langs';
910
import { Select } from '../../Select';
1011
import { Options } from '../extensions/basic-setup';
1112

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');
1316
const heightOptions = ['auto', '200px', '300px', '500px'];
14-
1517
let count = 0;
1618

1719
const MarkdownDocument = styled.div`
@@ -92,7 +94,7 @@ export default function Example() {
9294
<CodemirrorWarpper
9395
value={code}
9496
height={height}
95-
theme={theme}
97+
theme={alls[theme as keyof typeof alls] || theme}
9698
editable={editable}
9799
extensions={extensions}
98100
autoFocus={autofocus}
@@ -115,14 +117,27 @@ export default function Example() {
115117
onChange={(evn) => handleLangChange(evn.target.value as keyof typeof langs)}
116118
/>
117119
<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"
119130
options={themeOptions}
120131
value={theme as string}
121132
onChange={(evn) => {
122-
document.documentElement.setAttribute('data-color-mode', evn.target.value);
133+
if (/^(dark|light)$/.test(evn.target.value)) {
134+
document.documentElement.setAttribute('data-color-mode', evn.target.value);
135+
}
123136
setTheme(evn.target.value as ReactCodeMirrorProps['theme']);
124137
}}
125138
/>
139+
</Tools>
140+
<Tools>
126141
<Select
127142
label="Height"
128143
options={heightOptions}

0 commit comments

Comments
 (0)
Please sign in to comment.