Skip to content

Commit

Permalink
🔨 refactor(bar.tsx): Replace EditorButton component with IconButton c…
Browse files Browse the repository at this point in the history
…omponent

🔥 chore(editorButton.tsx): Remove unused EditorButton component
  • Loading branch information
marcbon committed Jan 23, 2024
1 parent 9372fc6 commit 77aa9c4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 56 deletions.
68 changes: 63 additions & 5 deletions src/stories/chat/parts/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import styled from "styled-components";
import { Tooltip } from "../../tooltip";
import { ChatEditorArgs } from "../_types";
import { Editor } from "@tiptap/react";
import { EditorButton } from "./editorButton";
import { isMac } from "../../theme/utils";
import { ReactComponent as BoldIcon } from "../../../assets/icons/bold-fill.svg";
import { ReactComponent as ItalicIcon } from "../../../assets/icons/italic-fill.svg";
import { ReactComponent as MentionIcon } from "../../../assets/icons/at-fill.svg";
import { IconButton } from "../../buttons/icon-button";

const MenuContainer = styled.div`
padding: ${({ theme }) => theme.space.xs} 0;
Expand All @@ -30,32 +33,87 @@ const CommentBar = ({

if(!editor) return null;

const getIcon = (type: "bold" | "italic" | "mention") => {
switch (type) {
case "bold":
return <BoldIcon />;
case "italic":
return <ItalicIcon />;
case "mention":
return <MentionIcon />;
default:
return null;
}
};

const handleClick = (type: "bold" | "italic" | "mention") => {
switch (type) {
case "bold":
return editor.chain().focus().toggleBold().run();
case "italic":
return editor.chain().focus().toggleItalic().run();
case "mention":
const { from } = editor.state.selection;
const char = from > 1 ? " @" : "@";
return editor.commands.insertContent(char);
default:
return;
}
};

return (
<MenuContainer>
<MenuContainer id="menu-container">
<Tooltip
content={`${i18n?.menu?.bold ?? "Bold text"} ${isMac() ? "Cmd" : "Ctrl"} + B`}
placement="top"
type="light"
size="small"
hasArrow={false}
>
<EditorButton editor={editor} type="bold" />
<IconButton
size={"small"}
isBasic={!editor.isActive("bold")}
isPrimary={editor.isActive("bold")}
isPill={false}
onClick={() => handleClick("bold")}
>
{getIcon("bold")}
</IconButton>
</Tooltip>
<Tooltip
content={`${i18n?.menu?.italic ?? "Italic text"} ${isMac() ? "Cmd" : "Ctrl"} + I`}
placement="top"
type="light"
size="small"
hasArrow={false}
>
<EditorButton editor={editor} type="italic" />
<IconButton
size={"small"}
isBasic={!editor.isActive("italic")}
isPrimary={editor.isActive("italic")}
isPill={false}
onClick={() => handleClick("italic")}
>
{getIcon("italic")}
</IconButton>
</Tooltip>
<VerticalDivider />
<Tooltip
content={i18n?.menu?.mention ?? "Add a mention"}
placement="top"
type="light"
size="small"
hasArrow={false}
>
<EditorButton editor={editor} type="mention" />
<IconButton
size={"small"}
isBasic={!editor.isActive("mention")}
isPrimary={editor.isActive("mention")}
isPill={false}
onClick={() => handleClick("mention")}
>
{getIcon("mention")}
</IconButton>
</Tooltip>
</MenuContainer>
);
Expand Down
51 changes: 0 additions & 51 deletions src/stories/chat/parts/editorButton.tsx

This file was deleted.

0 comments on commit 77aa9c4

Please sign in to comment.