Skip to content

Commit 3a230f9

Browse files
committed
website: update example.
1 parent 2a764ff commit 3a230f9

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ ReactDOM.render(<Dome />, document.getElementById('app'));
6565

6666
```jsx
6767
import MarkdownEditor from '@uiw/react-markdown-editor';
68+
import { createRoot } from 'react-dom/client';
6869
import React, { useState } from 'react';
69-
import ReactDOM from 'react-dom';
7070

7171
function App() {
7272
const [markdown, setMarkdown] = useState("");
@@ -78,7 +78,7 @@ function App() {
7878
);
7979
}
8080

81-
ReactDOM.render(<App />, document.getElementById('app'));
81+
export default App;
8282
```
8383

8484
## Custom Toolbars
@@ -135,7 +135,7 @@ const Dome = () => (
135135
/>
136136
);
137137

138-
ReactDOM.render(<Dome />, document.getElementById('app'));
138+
export default Dome;
139139
```
140140

141141
## Support Nextjs

website/App.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import { useState } from 'react';
21
import BackToUp from '@uiw/react-back-to-top';
32
import GithubCorner from '@uiw/react-github-corners';
43
import MarkdownPreview from '@uiw/react-markdown-preview';
54
import '@wcj/dark-mode';
65
import DocumentStr from '../README.md';
7-
import MarkdownEditor from '../';
86
import styles from './App.module.less';
97
import Footer from './components/Footer';
108
import { ReactComponent as Logo } from './logo.svg';
9+
import { Example } from './Example';
1110

1211
const DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '').replace(/^\n*/g, '');
13-
let count = 1;
1412

1513
export default function App() {
16-
const [visible, setVisible] = useState(true);
17-
const [mdstr, setMdstr] = useState<string>(DocumentStrSource);
18-
const [hideToolbar, setHideToolbar] = useState(true);
1914
return (
2015
<div className={styles.warpper}>
2116
<BackToUp>Top</BackToUp>
@@ -24,25 +19,7 @@ export default function App() {
2419
<div className={styles.logo}>
2520
<Logo style={{ fill: 'currentColor' }} />
2621
</div>
27-
<div className={styles.editor}>
28-
<MarkdownEditor visible={visible} height="500px" value={mdstr} hideToolbar={hideToolbar} />
29-
<div style={{ marginTop: 10, display: 'flex', gap: '10px' }}>
30-
<button
31-
onClick={() => {
32-
count += 1;
33-
setMdstr(`String ${count}`);
34-
}}
35-
>
36-
Modify Markdown
37-
</button>
38-
<label>
39-
<input type="checkbox" checked={hideToolbar} onChange={(evn) => setHideToolbar(evn.target.checked)} />
40-
hideToolbar
41-
</label>
42-
<button onClick={() => setVisible(!visible)}>{visible ? 'Show' : 'Hide'}</button>
43-
<span>v{VERSION}</span>
44-
</div>
45-
</div>
22+
<Example />
4623
<MarkdownPreview source={DocumentStrSource} className={styles.doc} />
4724
<Footer
4825
name="Kenny Wong"

website/Example.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useState } from 'react';
2+
import MarkdownEditor from '../';
3+
import DocumentStr from '../README.md';
4+
import styles from './App.module.less';
5+
6+
const DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '').replace(/^\n*/g, '');
7+
let count = 1;
8+
9+
export function Example() {
10+
const [visible, setVisible] = useState(true);
11+
const [mdstr, setMdstr] = useState<string>(DocumentStrSource);
12+
const [hideToolbar, setHideToolbar] = useState(true);
13+
return (
14+
<div className={styles.editor}>
15+
<MarkdownEditor visible={visible} height="500px" value={mdstr} hideToolbar={hideToolbar} />
16+
<div style={{ marginTop: 10, display: 'flex', gap: '10px' }}>
17+
<button
18+
onClick={() => {
19+
count += 1;
20+
setMdstr(`String ${count}`);
21+
}}
22+
>
23+
Modify Markdown
24+
</button>
25+
<label>
26+
<input type="checkbox" checked={hideToolbar} onChange={(evn) => setHideToolbar(evn.target.checked)} />
27+
hideToolbar
28+
</label>
29+
<button onClick={() => setVisible(!visible)}>{visible ? 'Show' : 'Hide'}</button>
30+
<span>v{VERSION}</span>
31+
</div>
32+
</div>
33+
);
34+
}

0 commit comments

Comments
 (0)