Skip to content

Commit 917bb0c

Browse files
committed
fix: toolbar buttons peaking out of frame on mobile
Close #589
1 parent 3b6dffc commit 917bb0c

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

packages/ui/src/blocks/rich-text-editor/format-buttons.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Editor } from '@tiptap/react';
22
import clsx from 'clsx';
33
import * as React from 'react';
44

5-
import { BaseButtonProps, BaseButton } from '../../components/button';
5+
import { BaseButton, BaseButtonProps } from '../../components/button';
66
import {
7+
Icon,
8+
IconBlockQuote,
79
IconBold,
810
IconCode,
9-
IconBlockQuote,
1011
IconItalic,
1112
IconList,
1213
IconUnderline,
13-
Icon,
1414
} from '../../components/icons';
1515
import { Select } from '../../components/select';
1616
import { listHoverableColor } from '../../styles/common';
@@ -29,7 +29,7 @@ export const BaseMarkButton = React.forwardRef(function BaseMarkButton(
2929
return (
3030
<BaseButton
3131
className={clsx(
32-
`rounded p-1.5 text-gray-1100`,
32+
`flex gap-1 rounded p-1.5 text-gray-1100`,
3333
listHoverableColor,
3434
isActive && `bg-primary-300 text-primary-1000`,
3535
className,
@@ -72,14 +72,19 @@ type BlockButtonFormat = 'bulletList' | 'blockquote';
7272
export type BlockButtonProps = {
7373
format: BlockButtonFormat;
7474
editor: Editor;
75+
children?: React.ReactNode;
7576
};
7677

7778
const blockMap: Record<BlockButtonFormat, [Icon, string]> = {
7879
bulletList: [IconList, 'toggleBulletList'],
7980
blockquote: [IconBlockQuote, 'toggleBlockquote'],
8081
};
8182

82-
export function BlockButton({ format, editor }: BlockButtonProps): JSX.Element {
83+
export function BlockButton({
84+
format,
85+
editor,
86+
children,
87+
}: BlockButtonProps): JSX.Element {
8388
const [Icon, methodName] = blockMap[format];
8489
return (
8590
<BaseMarkButton
@@ -89,6 +94,7 @@ export function BlockButton({ format, editor }: BlockButtonProps): JSX.Element {
8994
}}
9095
>
9196
<Icon size={20} />
97+
<span>{children}</span>
9298
</BaseMarkButton>
9399
);
94100
}

packages/ui/src/blocks/rich-text-editor/toolbar.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import clsx from 'clsx';
33
import * as React from 'react';
44

55
import { Divider } from '../../components/divider';
6-
import { IconImage, IconLink2 } from '../../components/icons';
6+
import {
7+
IconBlockQuote,
8+
IconImage,
9+
IconLink2,
10+
IconList,
11+
IconMoreVertical,
12+
} from '../../components/icons';
13+
import { Menu } from '../../components/menu';
714
import { BlockButton, MarkButton } from './format-buttons';
815
import { RTEPopoverButton } from './rte-popover-button';
916

@@ -32,7 +39,7 @@ export function Toolbar({
3239
<MarkButton editor={editor} format="italic" />
3340
<MarkButton editor={editor} format="underline" />
3441
<MarkButton editor={editor} format="code" />
35-
<div className="hidden flex-row gap-1 xs:flex">
42+
<div className="hidden flex-row items-center gap-1 [@media(min-width:470px)]:flex">
3643
<Divider vertical />
3744
<BlockButton editor={editor} format="bulletList" />
3845
<BlockButton editor={editor} format="blockquote" />
@@ -55,6 +62,35 @@ export function Toolbar({
5562
<IconImage size={20} />
5663
</RTEPopoverButton>
5764
</div>
65+
<div className="flex flex-row items-center [@media(min-width:470px)]:hidden">
66+
<Menu>
67+
<Menu.Button
68+
variant="text"
69+
shape="square"
70+
className="rounded p-1.5 text-gray-1100 hover:bg-gray-200"
71+
>
72+
<IconMoreVertical size={20} />
73+
</Menu.Button>
74+
<Menu.Items>
75+
<Menu.Item
76+
onClick={() => {
77+
editor.chain().focus().toggleBulletList().run();
78+
}}
79+
>
80+
<IconList className="size-5" />
81+
Bullet list
82+
</Menu.Item>
83+
<Menu.Item
84+
onClick={() => {
85+
editor.chain().focus().toggleBlockquote().run();
86+
}}
87+
>
88+
<IconBlockQuote className="size-5" />
89+
Blockquote
90+
</Menu.Item>
91+
</Menu.Items>
92+
</Menu>
93+
</div>
5894
</div>
5995
{children}
6096
</div>

packages/ui/src/components/menu/menu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as React from 'react';
55

66
import { bluredBg, listHoverable } from '../../styles/common';
77
import { Box, BoxProps } from '../box';
8-
import { Button, IconButton } from '../button';
8+
import { Button, IconButton, type ButtonProps } from '../button';
99
import { Divider } from '../divider';
1010
import styles from './menu.module.scss';
1111

@@ -50,6 +50,7 @@ export type MenuButtonProps = {
5050
ariaLabel?: string;
5151
open?: boolean;
5252
onClick?(open?: boolean): void;
53+
variant?: ButtonProps['variant'];
5354
};
5455

5556
function MenuButton({

0 commit comments

Comments
 (0)