|
| 1 | +import { Stack } from "@mui/material"; |
| 2 | +import MDEditor, { ICommand, commands } from "@uiw/react-md-editor"; |
| 3 | +import * as React from "react"; |
| 4 | + |
| 5 | +type MDEditorProps = { |
| 6 | + disabled?: boolean; |
| 7 | + defaultValue?: string; |
| 8 | + onChange?: (value?: string) => void; |
| 9 | + extraCommands?: ICommand[]; |
| 10 | +}; |
| 11 | + |
| 12 | +const TextEditorStyle: React.CSSProperties = { |
| 13 | + flexGrow: 1, |
| 14 | + width: "100%", |
| 15 | + maxWidth: "100%", |
| 16 | + |
| 17 | + wordBreak: "break-word", |
| 18 | + whiteSpace: "pre-wrap", |
| 19 | + overflowWrap: "break-word", |
| 20 | + |
| 21 | + fieldSizing: "content", |
| 22 | +} as React.CSSProperties; |
| 23 | + |
| 24 | +export const MarkdownEditor: React.FC<MDEditorProps> = ({ disabled, defaultValue, onChange, extraCommands }) => ( |
| 25 | + <Stack direction="column" spacing={2} sx={{ width: "100%", height: "100%", maxWidth: "100%" }}> |
| 26 | + <MDEditor |
| 27 | + data-color-mode="light" |
| 28 | + textareaProps={{ disabled }} |
| 29 | + preview="edit" |
| 30 | + highlightEnable={true} |
| 31 | + height="none" |
| 32 | + minHeight={100} |
| 33 | + value={defaultValue} |
| 34 | + onChange={onChange} |
| 35 | + commands={[ |
| 36 | + commands.group([commands.title1, commands.title2, commands.title3, commands.title4, commands.title5, commands.title6], { |
| 37 | + name: "title", |
| 38 | + groupName: "title", |
| 39 | + buttonProps: { "aria-label": "Insert title" }, |
| 40 | + }), |
| 41 | + commands.bold, |
| 42 | + commands.italic, |
| 43 | + commands.strikethrough, |
| 44 | + commands.code, |
| 45 | + commands.link, |
| 46 | + commands.divider, |
| 47 | + commands.quote, |
| 48 | + commands.codeBlock, |
| 49 | + commands.table, |
| 50 | + commands.hr, |
| 51 | + commands.image, |
| 52 | + commands.divider, |
| 53 | + commands.unorderedListCommand, |
| 54 | + commands.orderedListCommand, |
| 55 | + commands.checkedListCommand, |
| 56 | + commands.divider, |
| 57 | + commands.help, |
| 58 | + ]} |
| 59 | + extraCommands={extraCommands} |
| 60 | + style={TextEditorStyle} |
| 61 | + /> |
| 62 | + </Stack> |
| 63 | +); |
0 commit comments