Skip to content

Commit 7aa833e

Browse files
committed
Finished formatting toolbar customization with old props
1 parent 1b7a745 commit 7aa833e

File tree

8 files changed

+325
-191
lines changed

8 files changed

+325
-191
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { formatKeyboardShortcut } from "../../../utils";
2+
import { RiIndentDecrease, RiIndentIncrease } from "react-icons/ri";
3+
import { ToolbarButton } from "../../../SharedComponents/Toolbar/components/ToolbarButton";
4+
5+
export type IncreaseBlockIndentButtonProps = {
6+
canIncreaseBlockIndent: boolean;
7+
increaseBlockIndent: () => void;
8+
};
9+
10+
export type DecreaseBlockIndentButtonProps = {
11+
canDecreaseBlockIndent: boolean;
12+
decreaseBlockIndent: () => void;
13+
};
14+
15+
export const IncreaseBlockIndentButton = (
16+
props: IncreaseBlockIndentButtonProps
17+
) => (
18+
<ToolbarButton
19+
onClick={props.increaseBlockIndent}
20+
isDisabled={!props.canIncreaseBlockIndent}
21+
mainTooltip="Indent"
22+
secondaryTooltip={formatKeyboardShortcut("Tab")}
23+
icon={RiIndentIncrease}
24+
/>
25+
);
26+
27+
export const DecreaseBlockIndentButton = (
28+
props: DecreaseBlockIndentButtonProps
29+
) => (
30+
<ToolbarButton
31+
onClick={props.decreaseBlockIndent}
32+
isDisabled={!props.canDecreaseBlockIndent}
33+
mainTooltip="Decrease Indent"
34+
secondaryTooltip={formatKeyboardShortcut("Shift+Tab")}
35+
icon={RiIndentDecrease}
36+
/>
37+
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { formatKeyboardShortcut } from "../../../utils";
2+
import { RiLink } from "react-icons/ri";
3+
import LinkToolbarButton from "../LinkToolbarButton";
4+
5+
export type CreateHyperlinkButtonProps = {
6+
hyperlinkIsActive: boolean;
7+
activeHyperlinkUrl: string;
8+
activeHyperlinkText: string;
9+
setHyperlink: (url: string, text?: string) => void;
10+
};
11+
12+
export const CreateHyperlinkButton = (props: CreateHyperlinkButtonProps) => (
13+
<LinkToolbarButton
14+
isSelected={props.hyperlinkIsActive}
15+
mainTooltip="Link"
16+
secondaryTooltip={formatKeyboardShortcut("Mod+K")}
17+
icon={RiLink}
18+
hyperlinkIsActive={props.hyperlinkIsActive}
19+
activeHyperlinkUrl={props.activeHyperlinkUrl}
20+
activeHyperlinkText={props.activeHyperlinkText}
21+
setHyperlink={props.setHyperlink}
22+
/>
23+
);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { ToolbarButton } from "../../../SharedComponents/Toolbar/components/ToolbarButton";
2+
import { formatKeyboardShortcut } from "../../../utils";
3+
import { RiBold, RiItalic, RiStrikethrough, RiUnderline } from "react-icons/ri";
4+
5+
export type ToggleBoldButtonProps = {
6+
boldIsActive: boolean;
7+
toggleBold: () => void;
8+
};
9+
10+
export type ToggleItalicButtonProps = {
11+
italicIsActive: boolean;
12+
toggleItalic: () => void;
13+
};
14+
15+
export type ToggleUnderlineButtonProps = {
16+
underlineIsActive: boolean;
17+
toggleUnderline: () => void;
18+
};
19+
20+
export type ToggleStrikeButtonProps = {
21+
strikeIsActive: boolean;
22+
toggleStrike: () => void;
23+
};
24+
25+
export const ToggleBoldButton = (props: ToggleBoldButtonProps) => (
26+
<ToolbarButton
27+
onClick={props.toggleBold}
28+
isSelected={props.boldIsActive}
29+
mainTooltip="Bold"
30+
secondaryTooltip={formatKeyboardShortcut("Mod+B")}
31+
icon={RiBold}
32+
/>
33+
);
34+
35+
export const ToggleItalicButton = (props: ToggleItalicButtonProps) => (
36+
<ToolbarButton
37+
onClick={props.toggleItalic}
38+
isSelected={props.italicIsActive}
39+
mainTooltip="Italic"
40+
secondaryTooltip={formatKeyboardShortcut("Mod+I")}
41+
icon={RiItalic}
42+
/>
43+
);
44+
45+
export const ToggleUnderlineButton = (props: ToggleUnderlineButtonProps) => (
46+
<ToolbarButton
47+
onClick={props.toggleUnderline}
48+
isSelected={props.underlineIsActive}
49+
mainTooltip="Underline"
50+
secondaryTooltip={formatKeyboardShortcut("Mod+U")}
51+
icon={RiUnderline}
52+
/>
53+
);
54+
55+
export const ToggleStrikethroughButton = (props: ToggleStrikeButtonProps) => (
56+
<ToolbarButton
57+
onClick={props.toggleStrike}
58+
isSelected={props.strikeIsActive}
59+
mainTooltip="Strikethrough"
60+
secondaryTooltip={formatKeyboardShortcut("Mod+Shift+X")}
61+
icon={RiStrikethrough}
62+
/>
63+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Menu } from "@mantine/core";
2+
import { ToolbarButton } from "../../../SharedComponents/Toolbar/components/ToolbarButton";
3+
import { ColorIcon } from "../../../SharedComponents/ColorPicker/components/ColorIcon";
4+
import { ColorPicker } from "../../../SharedComponents/ColorPicker/components/ColorPicker";
5+
6+
export type ColorsButtonProps = {
7+
textColor: string;
8+
setTextColor: (color: string) => void;
9+
backgroundColor: string;
10+
setBackgroundColor: (color: string) => void;
11+
};
12+
13+
export const SetColorsButton = (props: ColorsButtonProps) => (
14+
<Menu>
15+
<Menu.Target>
16+
<ToolbarButton
17+
mainTooltip={"Colors"}
18+
icon={() => (
19+
<ColorIcon
20+
textColor={props.textColor}
21+
backgroundColor={props.backgroundColor}
22+
size={20}
23+
/>
24+
)}
25+
/>
26+
</Menu.Target>
27+
<Menu.Dropdown>
28+
<ColorPicker
29+
textColor={props.textColor}
30+
setTextColor={props.setTextColor}
31+
backgroundColor={props.backgroundColor}
32+
setBackgroundColor={props.setBackgroundColor}
33+
/>
34+
</Menu.Dropdown>
35+
</Menu>
36+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { RiAlignCenter, RiAlignLeft, RiAlignRight } from "react-icons/ri";
2+
import { ToolbarButton } from "../../../SharedComponents/Toolbar/components/ToolbarButton";
3+
4+
export type TextAlignButtonProps = {
5+
textAlignment: "left" | "center" | "right" | "justify";
6+
setTextAlignment: (
7+
textAlignment: "left" | "center" | "right" | "justify"
8+
) => void;
9+
};
10+
11+
export const TextAlignLeftButton = (props: TextAlignButtonProps) => (
12+
<ToolbarButton
13+
onClick={() => props.setTextAlignment("left")}
14+
isSelected={props.textAlignment === "left"}
15+
mainTooltip={"Align Text Left"}
16+
icon={RiAlignLeft}
17+
/>
18+
);
19+
20+
export const TextAlignCenterButton = (props: TextAlignButtonProps) => (
21+
<ToolbarButton
22+
onClick={() => props.setTextAlignment("center")}
23+
isSelected={props.textAlignment === "center"}
24+
mainTooltip={"Align Text Center"}
25+
icon={RiAlignCenter}
26+
/>
27+
);
28+
29+
export const TextAlignRightButton = (props: TextAlignButtonProps) => (
30+
<ToolbarButton
31+
onClick={() => props.setTextAlignment("right")}
32+
isSelected={props.textAlignment === "right"}
33+
mainTooltip={"Align Text Right"}
34+
icon={RiAlignRight}
35+
/>
36+
);
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { Block, PartialBlock } from "@blocknote/core";
2+
import {
3+
RiH1,
4+
RiH2,
5+
RiH3,
6+
RiListOrdered,
7+
RiListUnordered,
8+
RiText,
9+
} from "react-icons/ri";
10+
import { ToolbarDropdown } from "../../../SharedComponents/Toolbar/components/ToolbarDropdown";
11+
12+
export type BlockTypeDropdownProps = {
13+
block: Block;
14+
updateBlock: (updatedBlock: PartialBlock) => void;
15+
};
16+
17+
export const BlockTypeDropdown = (props: BlockTypeDropdownProps) => (
18+
<ToolbarDropdown
19+
items={[
20+
{
21+
onClick: () =>
22+
props.updateBlock({
23+
type: "paragraph",
24+
props: {},
25+
}),
26+
text: "Paragraph",
27+
icon: RiText,
28+
isSelected: props.block.type === "paragraph",
29+
},
30+
{
31+
onClick: () =>
32+
props.updateBlock({
33+
type: "heading",
34+
props: { level: "1" },
35+
}),
36+
text: "Heading 1",
37+
icon: RiH1,
38+
isSelected:
39+
props.block.type === "heading" && props.block.props.level === "1",
40+
},
41+
{
42+
onClick: () =>
43+
props.updateBlock({
44+
type: "heading",
45+
props: { level: "2" },
46+
}),
47+
text: "Heading 2",
48+
icon: RiH2,
49+
isSelected:
50+
props.block.type === "heading" && props.block.props.level === "2",
51+
},
52+
{
53+
onClick: () =>
54+
props.updateBlock({
55+
type: "heading",
56+
props: { level: "3" },
57+
}),
58+
text: "Heading 3",
59+
icon: RiH3,
60+
isSelected:
61+
props.block.type === "heading" && props.block.props.level === "3",
62+
},
63+
{
64+
onClick: () =>
65+
props.updateBlock({
66+
type: "bulletListItem",
67+
props: {},
68+
}),
69+
text: "Bullet List",
70+
icon: RiListUnordered,
71+
isSelected: props.block.type === "bulletListItem",
72+
},
73+
{
74+
onClick: () =>
75+
props.updateBlock({
76+
type: "numberedListItem",
77+
props: {},
78+
}),
79+
text: "Numbered List",
80+
icon: RiListOrdered,
81+
isSelected: props.block.type === "numberedListItem",
82+
},
83+
]}
84+
/>
85+
);

0 commit comments

Comments
 (0)