forked from tdjsnelling/sqtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkdownInput.js
More file actions
61 lines (57 loc) · 1.64 KB
/
Copy pathMarkdownInput.js
File metadata and controls
61 lines (57 loc) · 1.64 KB
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
57
58
59
60
61
import React, { useContext, useState } from "react";
import Link from "next/link";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import Input from "./Input";
import Box from "./Box";
import Text from "./Text";
import Infobox from "./Infobox";
import MarkdownBody from "./MarkdownBody";
import LocaleContext from "../utils/LocaleContext";
const MarkdownInput = ({ defaultValue, mb, ...rest }) => {
const [bodyValue, setBodyValue] = useState(defaultValue);
const { getLocaleString } = useContext(LocaleContext);
return (
<Box mb={mb}>
<Input
value={bodyValue}
onChange={(e) => setBodyValue(e.target.value)}
mb={3}
{...rest}
/>
<Box as="details">
<Box as="summary">
<Text
as="span"
fontWeight={600}
fontSize={1}
_css={{ textTransform: "uppercase" }}
>
{getLocaleString("mdMarkdownPreview")}
</Text>
</Box>
<Infobox mt={3}>
<MarkdownBody>
<ReactMarkdown
remarkPlugins={[remarkGfm]}
components={{
a({ href, ...props }) {
return href.startsWith("http") ? (
<a href={href} target="_blank" {...props} />
) : (
<Link href={href} passHref>
<a {...props} />
</Link>
);
},
}}
>
{bodyValue}
</ReactMarkdown>
</MarkdownBody>
</Infobox>
</Box>
</Box>
);
};
export default MarkdownInput;