Skip to content

Commit

Permalink
Added dropdown button for header levels
Browse files Browse the repository at this point in the history
  • Loading branch information
stiansolli committed Aug 17, 2024
1 parent 680d313 commit 84f8f14
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions src/components/atoms/markdown/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import React, {
} from 'react';
import ReactMarkdown from 'react-markdown';
import styles from './markdown.module.scss';
import { Button, Stack } from '@chakra-ui/react';
import {
Button,
Stack,
Menu,
MenuButton,
MenuList,
MenuItem,
} from '@chakra-ui/react';
import { MdInsertLink } from 'react-icons/md';
import EmojiPicker, { EmojiClickData } from 'emoji-picker-react';

Expand Down Expand Up @@ -91,8 +98,8 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({
insertText(text, 1);
};

const insertHeader = () => {
const text = '### ';
const insertHeader = (level: number) => {
const text = '#'.repeat(level) + ' ';
insertText(text, 0);
};

Expand Down Expand Up @@ -151,13 +158,41 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({
onClick={() => handleButtonClick(insertItalic)}>
Italic
</Button>
<Button
size="xs"
colorScheme="purple"
variant="outline"
onClick={() => handleButtonClick(insertHeader)}>
H
</Button>
<Menu>
<MenuButton
as={Button}
colorScheme="purple"
size="xs"
variant="outline">
H
</MenuButton>
<MenuList>
<MenuItem
onClick={() => handleButtonClick(() => insertHeader(1))}>
H1
</MenuItem>
<MenuItem
onClick={() => handleButtonClick(() => insertHeader(2))}>
H2
</MenuItem>
<MenuItem
onClick={() => handleButtonClick(() => insertHeader(3))}>
H3
</MenuItem>
<MenuItem
onClick={() => handleButtonClick(() => insertHeader(4))}>
H4
</MenuItem>
<MenuItem
onClick={() => handleButtonClick(() => insertHeader(5))}>
H5
</MenuItem>
<MenuItem
onClick={() => handleButtonClick(() => insertHeader(6))}>
H6
</MenuItem>
</MenuList>
</Menu>
<Button
size="xs"
colorScheme="purple"
Expand Down

0 comments on commit 84f8f14

Please sign in to comment.