Skip to content

Commit 048bc76

Browse files
authored
Merge pull request #307 from meliora/main
2 parents 17b33b8 + c3ef038 commit 048bc76

File tree

27 files changed

+81
-43
lines changed

27 files changed

+81
-43
lines changed

docs/guide/toolbar.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ Bold.configure({
3232
/>
3333
```
3434

35+
## Tooltips
36+
37+
The tooltips of the extension buttons registered to the toolbar can be customized with
38+
39+
### tooltipOptions
40+
41+
Type: `TooltipContentProps`\
42+
Default: `{}`
43+
3544
## ToolbarProps
3645

3746
```ts
@@ -51,5 +60,6 @@ export interface ToolbarRenderProps {
5160
}
5261
export interface ToolbarProps {
5362
render?: (props: ToolbarRenderProps, toolbarItems: ToolbarItemProps[], dom: JSX.Element[], containerDom: (innerContent: React.ReactNode) => React.ReactNode) => React.ReactNode
63+
tooltipSide?: 'top' | 'bottom';
5464
}
5565
```

src/components/ActionMenuButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Slot } from '@radix-ui/react-slot';
66
import { Button, Tooltip, TooltipContent, TooltipTrigger, icons } from '@/components';
77
import type { ButtonViewReturnComponentProps } from '@/types';
88
import { getShortcutKeys } from '@/utils/plateform';
9+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
910

1011
export interface ActionMenuButtonProps {
1112
/** Icon name to display */
@@ -14,6 +15,8 @@ export interface ActionMenuButtonProps {
1415
title?: string
1516
/** Tooltip text */
1617
tooltip?: string
18+
/** Tooltip options */
19+
tooltipOptions?: TooltipContentProps
1720
/** Whether the button is disabled */
1821
disabled?: boolean
1922
/** Keyboard shortcut keys */
@@ -55,7 +58,7 @@ const ActionMenuButton = React.forwardRef<HTMLButtonElement, ActionMenuButtonPro
5558
</Comp>
5659
</TooltipTrigger>
5760

58-
<TooltipContent>
61+
<TooltipContent {...props.tooltipOptions}>
5962
<div className="richtext-flex richtext-max-w-24 richtext-flex-col richtext-items-center richtext-text-center">
6063
{props?.tooltip && <div>
6164
{props?.tooltip}

src/components/Toolbar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ function Toolbar({ editor, disabled, toolbar }: ToolbarComponentProps) {
9191
<ButtonComponent
9292
{...item.button.componentProps}
9393
disabled={disabled || item?.button?.componentProps?.disabled}
94+
tooltipOptions={{
95+
...item?.button?.componentProps?.tooltipOptions,
96+
side: toolbar?.tooltipSide ?? 'top',
97+
}}
9498
/>
9599

96100
{item?.divider && <Separator orientation="vertical" className="!richtext-h-auto !richtext-mx-2" />}

src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import {
44
ActionButton,
55
} from '@/components';
66

7+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
8+
79
interface Props {
810
editor: any
911
disabled?: boolean
1012
color?: string
1113
shortcutKeys?: string[]
1214
maxHeight?: string | number
1315
tooltip?: string
16+
tooltipOptions?: TooltipContentProps
1417
action: (language: string) => void
1518
icon?: any
1619
}
@@ -23,6 +26,7 @@ function CodeBlockActiveButton({ action, ...props }: Props) {
2326
disabled={props?.disabled}
2427
icon={props?.icon}
2528
tooltip={props?.tooltip}
29+
tooltipOptions={props?.tooltipOptions}
2630
/>
2731
);
2832
}

src/extensions/Color/components/ColorActionButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { debounce } from 'lodash-es';
66
import { ActionButton, Button, ColorPicker } from '@/components';
77
import { IconComponent } from '@/components/icons';
88
import type { ButtonViewReturnComponentProps } from '@/types';
9+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
910

1011
interface ColorActionButtonProps {
1112
editor: Editor
1213
colors?: string[]
1314
defaultColor?: string
1415
icon?: React.ReactNode
1516
tooltip?: string
17+
tooltipOptions?: TooltipContentProps
1618
disabled?: boolean
1719
action?: ButtonViewReturnComponentProps['action']
1820
isActive?: ButtonViewReturnComponentProps['isActive']
@@ -80,7 +82,7 @@ function ColorActionButton(props: ColorActionButtonProps) {
8082

8183
return (
8284
<div className="richtext-flex richtext-items-center richtext-h-[32px]">
83-
<ActionButton tooltip={props?.tooltip} disabled={props?.disabled} action={toggleColor}>
85+
<ActionButton tooltip={props?.tooltip} disabled={props?.disabled} action={toggleColor} tooltipOptions={props?.tooltipOptions}>
8486
<span className="richtext-flex richtext-items-center richtext-justify-center richtext-text-sm">
8587
<IconC fill={selectedColor || props.initialDisplayedColor} />
8688
</span>

src/extensions/Drawer/components/DrawerActiveButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import { Dialog, DialogContent, DialogFooter, DialogTitle, DialogTrigger } from
1515
import ControlDrawer from '@/extensions/Drawer/components/ControlDrawer/ControlDrawer';
1616
import { dataURLtoFile } from '@/utils/file';
1717
import { shortId } from '@/utils/shortId';
18+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
1819

1920
interface IProps {
20-
editor: Editor, upload?: any
21+
editor: Editor, upload?: any, tooltipOptions?: TooltipContentProps
2122
}
2223

2324
let clear = false;
2425

25-
export const DrawerActiveButton: React.FC<IProps> = ({ editor, upload }) => {
26+
export const DrawerActiveButton: React.FC<IProps> = ({ editor, upload, tooltipOptions }) => {
2627
const [visible, toggleVisible] = useState(false);
2728
const refEditor = useRef<Editor4 | null>(null);
2829
const refWidget = useRef<any>(null);
@@ -195,6 +196,7 @@ export const DrawerActiveButton: React.FC<IProps> = ({ editor, upload }) => {
195196
action={() => toggleVisible(true)}
196197
icon="PencilRuler"
197198
tooltip="Drawer"
199+
tooltipOptions={tooltipOptions}
198200
/>
199201
</DialogTrigger>
200202

src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function EmojiPickerComponent({ editor, icon, ...props }: any) {
5252
<ActionButton
5353
icon={icon}
5454
tooltip={props?.tooltip}
55+
tooltipOptions={props?.tooltipOptions}
5556
/>
5657
</EmojiPickerWrap>
5758
);

src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import { ActionButton } from '@/components/ActionButton';
99
import { Button } from '@/components/ui';
1010
import { Dialog, DialogContent, DialogFooter, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
1111
import { OPEN_EXCALIDRAW_SETTING_MODAL, cancelSubject, subject } from '@/utils/_event';
12+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
1213

1314
interface IProps {
14-
editor: Editor
15+
editor: Editor, tooltipOptions?: TooltipContentProps
1516
}
1617

17-
export const ExcalidrawActiveButton: React.FC<IProps> = ({ editor }) => {
18+
export const ExcalidrawActiveButton: React.FC<IProps> = ({ editor, tooltipOptions }) => {
1819
const excalidrawOptions = useMemo(() => {
1920
return editor.extensionManager.extensions.find(
2021
(ext: any) => ext.name === 'excalidraw'
@@ -107,6 +108,7 @@ export const ExcalidrawActiveButton: React.FC<IProps> = ({ editor }) => {
107108
action={() => toggleVisible(true)}
108109
icon="Excalidraw"
109110
tooltip="Excalidraw"
111+
tooltipOptions={tooltipOptions}
110112
/>
111113
</DialogTrigger>
112114

src/extensions/FontFamily/components/FontFamilyButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@/components';
1111
import { useLocale } from '@/locales';
1212
import type { ButtonViewReturnComponentProps } from '@/types';
13+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
1314

1415
export interface Item {
1516
title: string
@@ -31,6 +32,7 @@ interface Props {
3132
shortcutKeys?: string[]
3233
maxHeight?: string | number
3334
tooltip?: string
35+
tooltipOptions?: TooltipContentProps
3436
items?: Item[]
3537
}
3638

@@ -65,6 +67,7 @@ function FontFamilyButton(props: Props) {
6567
icon="MenuDown"
6668
title={active?.font?.length > 7 ? `${active?.font?.slice(0, 6)}...` : active?.font}
6769
tooltip={props?.tooltip}
70+
tooltipOptions={props?.tooltipOptions}
6871
/>
6972
</DropdownMenuTrigger>
7073

src/extensions/FontSize/components/FontSizeMenuButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@/components';
1010
import { useLocale } from '@/locales';
1111
import type { ButtonViewReturnComponentProps } from '@/types';
12+
import type { TooltipContentProps } from '@radix-ui/react-tooltip';
1213

1314
export interface Item {
1415
title: string
@@ -27,6 +28,7 @@ interface IPropsFontSizeMenuButton {
2728
shortcutKeys?: string[]
2829
maxHeight?: string | number
2930
tooltip?: string
31+
tooltipOptions?: TooltipContentProps
3032
items?: Item[]
3133
}
3234

@@ -55,6 +57,7 @@ function FontSizeMenuButton(props: IPropsFontSizeMenuButton) {
5557
icon="MenuDown"
5658
title={active?.title}
5759
tooltip={`${props?.tooltip}`}
60+
tooltipOptions={props?.tooltipOptions}
5861
/>
5962
</DropdownMenuTrigger>
6063

0 commit comments

Comments
 (0)