2022-04-09 20:48:19 -04:00
|
|
|
import Bold from "@geist-ui/icons/bold"
|
|
|
|
import Italic from "@geist-ui/icons/italic"
|
|
|
|
import Link from "@geist-ui/icons/link"
|
2022-04-22 18:42:54 -04:00
|
|
|
import Code from "@geist-ui/icons/code"
|
|
|
|
import List from "@geist-ui/icons/list"
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
import ImageIcon from "@geist-ui/icons/image"
|
2022-04-22 18:42:54 -04:00
|
|
|
import { RefObject, useMemo } from "react"
|
2022-04-09 20:48:19 -04:00
|
|
|
import styles from "../document.module.css"
|
2022-04-22 18:42:54 -04:00
|
|
|
import { Button, ButtonGroup, Tooltip } from "@geist-ui/core"
|
2022-04-12 01:39:35 -04:00
|
|
|
import { TextareaMarkdownRef } from "textarea-markdown-editor"
|
2022-03-08 03:37:18 -05:00
|
|
|
|
|
|
|
// TODO: clean up
|
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
const FormattingIcons = ({
|
2022-04-12 02:07:06 -04:00
|
|
|
textareaRef
|
2022-04-09 20:48:19 -04:00
|
|
|
}: {
|
2022-04-12 01:39:35 -04:00
|
|
|
textareaRef?: RefObject<TextareaMarkdownRef>
|
2022-04-09 20:48:19 -04:00
|
|
|
}) => {
|
2022-04-12 02:07:06 -04:00
|
|
|
const formattingActions = useMemo(() => {
|
|
|
|
const handleBoldClick = () => textareaRef?.current?.trigger("bold")
|
|
|
|
const handleItalicClick = () => textareaRef?.current?.trigger("italic")
|
|
|
|
const handleLinkClick = () => textareaRef?.current?.trigger("link")
|
|
|
|
const handleImageClick = () => textareaRef?.current?.trigger("image")
|
2022-04-22 18:42:54 -04:00
|
|
|
const handleCodeClick = () => textareaRef?.current?.trigger("code")
|
|
|
|
const handleListClick = () =>
|
|
|
|
textareaRef?.current?.trigger("unordered-list")
|
2022-04-12 02:07:06 -04:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
icon: <Bold />,
|
|
|
|
name: "bold",
|
|
|
|
action: handleBoldClick
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <Italic />,
|
|
|
|
name: "italic",
|
|
|
|
action: handleItalicClick
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <Link />,
|
|
|
|
name: "hyperlink",
|
|
|
|
action: handleLinkClick
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <ImageIcon />,
|
|
|
|
name: "image",
|
|
|
|
action: handleImageClick
|
2022-04-22 18:42:54 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <Code />,
|
|
|
|
name: "code",
|
|
|
|
action: handleCodeClick
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <List />,
|
|
|
|
name: "unordered-list",
|
|
|
|
action: handleListClick
|
2022-04-12 02:07:06 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}, [textareaRef])
|
2022-03-08 03:37:18 -05:00
|
|
|
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
|
|
|
<div className={styles.actionWrapper}>
|
|
|
|
<ButtonGroup className={styles.actions}>
|
|
|
|
{formattingActions.map(({ icon, name, action }) => (
|
2022-04-22 18:42:54 -04:00
|
|
|
<Tooltip
|
|
|
|
text={name[0].toUpperCase() + name.slice(1).replace("-", " ")}
|
2022-04-09 20:48:19 -04:00
|
|
|
key={name}
|
2022-04-22 18:42:54 -04:00
|
|
|
>
|
|
|
|
<Button
|
|
|
|
auto
|
|
|
|
scale={2 / 3}
|
|
|
|
px={0.6}
|
|
|
|
aria-label={name}
|
|
|
|
icon={icon}
|
|
|
|
onMouseDown={(e) => e.preventDefault()}
|
|
|
|
onClick={action}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
2022-04-09 20:48:19 -04:00
|
|
|
))}
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
)
|
2022-03-08 03:37:18 -05:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:20:20 -04:00
|
|
|
export default FormattingIcons
|