Skip to content

Commit f3bc1c1

Browse files
committed
feat: markdown preview in comment form
1 parent dd0a164 commit f3bc1c1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/components/viewer/comment/CommentForm.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, TextArea } from '@blueprintjs/core'
1+
import { Button, Card, Checkbox, TextArea } from '@blueprintjs/core'
22

33
import clsx from 'clsx'
44
import { useContext, useState } from 'react'
@@ -7,6 +7,7 @@ import { requestAddComment } from '../../../apis/comment'
77
import { MAX_COMMENT_LENGTH } from '../../../models/comment'
88
import { formatError } from '../../../utils/error'
99
import { wrapErrorMessage } from '../../../utils/wrapErrorMessage'
10+
import { Markdown } from '../../Markdown'
1011
import { AppToaster } from '../../Toaster'
1112
import { CommentAreaContext } from './CommentArea'
1213

@@ -26,6 +27,7 @@ export const CommentForm = ({
2627
const { operationId, replyTo, reload } = useContext(CommentAreaContext)
2728

2829
const [message, setMessage] = useState('')
30+
const [showMarkdownPreview, setShowMarkdownPreview] = useState(false)
2931
const [isSubmitting, setIsSubmitting] = useState(false)
3032

3133
const handleSubmit = async () => {
@@ -96,10 +98,26 @@ export const CommentForm = ({
9698
{primary ? '发表评论' : '回复'}
9799
</Button>
98100

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+
99111
<div className="ml-auto text-slate-500 text-sm">
100112
{message.length}/{MAX_COMMENT_LENGTH}
101113
</div>
102114
</div>
115+
116+
{showMarkdownPreview && (
117+
<Card className="mt-2 border-2">
118+
<Markdown>{message || '*没有内容*'}</Markdown>
119+
</Card>
120+
)}
103121
</form>
104122
)
105123
}

src/styles/blueprint.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,8 @@ body {
228228
.bp4-skeleton {
229229
@apply rounded-md;
230230
}
231+
232+
label.bp4-checkbox {
233+
@apply select-none;
234+
}
231235
}

0 commit comments

Comments
 (0)