1
- import { Button , TextArea } from '@blueprintjs/core'
1
+ import { Button , Card , Checkbox , TextArea } from '@blueprintjs/core'
2
2
3
3
import clsx from 'clsx'
4
4
import { useContext , useState } from 'react'
@@ -7,6 +7,7 @@ import { requestAddComment } from '../../../apis/comment'
7
7
import { MAX_COMMENT_LENGTH } from '../../../models/comment'
8
8
import { formatError } from '../../../utils/error'
9
9
import { wrapErrorMessage } from '../../../utils/wrapErrorMessage'
10
+ import { Markdown } from '../../Markdown'
10
11
import { AppToaster } from '../../Toaster'
11
12
import { CommentAreaContext } from './CommentArea'
12
13
@@ -26,6 +27,7 @@ export const CommentForm = ({
26
27
const { operationId, replyTo, reload } = useContext ( CommentAreaContext )
27
28
28
29
const [ message , setMessage ] = useState ( '' )
30
+ const [ showMarkdownPreview , setShowMarkdownPreview ] = useState ( false )
29
31
const [ isSubmitting , setIsSubmitting ] = useState ( false )
30
32
31
33
const handleSubmit = async ( ) => {
@@ -96,10 +98,26 @@ export const CommentForm = ({
96
98
{ primary ? '发表评论' : '回复' }
97
99
</ Button >
98
100
101
+ < Checkbox
102
+ className = "mb-0 ml-6"
103
+ checked = { showMarkdownPreview }
104
+ onChange = { ( e ) =>
105
+ setShowMarkdownPreview ( ( e . target as HTMLInputElement ) . checked )
106
+ }
107
+ >
108
+ 预览 Markdown
109
+ </ Checkbox >
110
+
99
111
< div className = "ml-auto text-slate-500 text-sm" >
100
112
{ message . length } /{ MAX_COMMENT_LENGTH }
101
113
</ div >
102
114
</ div >
115
+
116
+ { showMarkdownPreview && (
117
+ < Card className = "mt-2 border-2" >
118
+ < Markdown > { message || '*没有内容*' } </ Markdown >
119
+ </ Card >
120
+ ) }
103
121
</ form >
104
122
)
105
123
}
0 commit comments