Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide inapplicable plugins from bubble-menu #119

Closed
Closed
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
72 changes: 39 additions & 33 deletions ui/editor/components/bubble-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const EditorBubbleMenu: FC<EditorBubbleMenuProps> = (props) => {
const [isNodeSelectorOpen, setIsNodeSelectorOpen] = useState(false);
const [isColorSelectorOpen, setIsColorSelectorOpen] = useState(false);
const [isLinkSelectorOpen, setIsLinkSelectorOpen] = useState(false);
const isCodeActive = props.editor.isActive("code");
const isCodeBlockActive = props.editor.isActive("codeBlock");

return (
<BubbleMenu
Expand All @@ -93,39 +95,43 @@ export const EditorBubbleMenu: FC<EditorBubbleMenuProps> = (props) => {
setIsLinkSelectorOpen(false);
}}
/>
<LinkSelector
editor={props.editor}
isOpen={isLinkSelectorOpen}
setIsOpen={() => {
setIsLinkSelectorOpen(!isLinkSelectorOpen);
setIsColorSelectorOpen(false);
setIsNodeSelectorOpen(false);
}}
/>
<div className="flex">
{items.map((item, index) => (
<button
key={index}
onClick={item.command}
className="p-2 text-stone-600 hover:bg-stone-100 active:bg-stone-200"
>
<item.icon
className={cn("h-4 w-4", {
"text-blue-500": item.isActive(),
})}
/>
</button>
))}
</div>
<ColorSelector
editor={props.editor}
isOpen={isColorSelectorOpen}
setIsOpen={() => {
setIsColorSelectorOpen(!isColorSelectorOpen);
setIsNodeSelectorOpen(false);
setIsLinkSelectorOpen(false);
}}
/>
{!(isCodeActive || isCodeBlockActive) && (
<>
<LinkSelector
editor={props.editor}
isOpen={isLinkSelectorOpen}
setIsOpen={() => {
setIsLinkSelectorOpen(!isLinkSelectorOpen);
setIsColorSelectorOpen(false);
setIsNodeSelectorOpen(false);
}}
/>
<div className="flex">
{items.map((item, index) => (
<button
key={index}
onClick={item.command}
className="p-2 text-stone-600 hover:bg-stone-100 active:bg-stone-200"
>
<item.icon
className={cn("h-4 w-4", {
"text-blue-500": item.isActive(),
})}
/>
</button>
))}
</div>
<ColorSelector
editor={props.editor}
isOpen={isColorSelectorOpen}
setIsOpen={() => {
setIsColorSelectorOpen(!isColorSelectorOpen);
setIsNodeSelectorOpen(false);
setIsLinkSelectorOpen(false);
}}
/>
</>
)}
</BubbleMenu>
);
};
Loading