/
MarkdownEditor.jsx
56 lines (48 loc) · 1.12 KB
/
MarkdownEditor.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import ReactMde, { commands } from 'react-mde'
import { markdown, useIntl } from 'services'
import { emojiPickerCommand } from './EmojiPicker'
import 'react-mde/lib/styles/css/react-mde-all.css'
import '../Input.css'
const listCommands = [
...commands.getDefaultCommands(),
{
commands: [emojiPickerCommand]
}
]
const MarkdownEditor = ({ content, onChange }) => {
const intl = useIntl(MarkdownEditor)
const [tab, setTab] = useState('write')
return (
<ReactMde
className="markdown-editor"
value={content}
onTabChange={setTab}
selectedTab={tab}
generateMarkdownPreview={md => Promise.resolve(markdown.text(md))}
onChange={onChange}
commands={listCommands}
l18n={intl('l18n')}
/>
)
}
MarkdownEditor.propTypes = {
content: PropTypes.string,
onChange: PropTypes.func
}
MarkdownEditor.translations = {
en: {
l18n: {
write: 'Write',
preview: 'Preview'
}
},
fr: {
l18n: {
write: 'Ecrire',
preview: 'Prévisualiser'
}
}
}
export default MarkdownEditor