Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions packages/ui/src/editor/menus/toolbar-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EditorState } from '@tiptap/pm/state';
import { Editor, isNodeSelection, useEditorState } from '@tiptap/react';
import { BubbleMenu, type BubbleMenuProps } from '@tiptap/react/menus';
import { Bold, Code, Italic, Strikethrough, Underline } from 'lucide-react';
import { useState } from 'react';
import { useCallback, useMemo, useState } from 'react';

import { ColorButton } from '@colanode/ui/editor/menus/color-button';
import { HighlightButton } from '@colanode/ui/editor/menus/highlight-button';
Expand Down Expand Up @@ -35,9 +36,8 @@ export const ToolbarMenu = (props: ToolbarMenuProps) => {
},
});

const bubbleMenuProps: ToolbarMenuProps = {
...props,
shouldShow: ({ state, editor }) => {
const shouldShow = useCallback(
({ state, editor }: { state: EditorState; editor: Editor }) => {
const { selection } = state;
const { empty } = selection;

Expand All @@ -61,25 +61,32 @@ export const ToolbarMenu = (props: ToolbarMenuProps) => {

return true;
},
options: {
strategy: 'absolute',
placement: 'top',
[]
);

const options = useMemo(
() => ({
strategy: 'absolute' as const,
placement: 'top' as const,
offset: 8,
onHide: () => {
setIsColorButtonOpen(false);
setIsLinkButtonOpen(false);
setIsHighlightButtonOpen(false);
},
},
};
}),
[]
);

if (props.editor == null) {
return null;
}

return (
<BubbleMenu
{...bubbleMenuProps}
editor={props.editor}
shouldShow={shouldShow}
options={options}
className="flex flex-row items-center gap-1 rounded border border-border bg-muted p-0.5 shadow-xl transition-transform duration-150 ease-out"
>
<LinkButton
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/lib/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const editorColors: EditorColorOption[] = [
color: 'default',
textClass: 'text-foreground',
bgClass: '',
bgHoverClass: 'hover:bg-gray-100 dark:hover:bg-gray-800',
bgHoverClass: 'hover:bg-input',
},
{
name: 'Gray',
Expand Down