-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bubble menu for link / text editing (#17550)
- Loading branch information
Showing
8 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { LemonButton, LemonInput } from '@posthog/lemon-ui' | ||
import { Editor } from '@tiptap/core' | ||
import { BubbleMenu } from '@tiptap/react' | ||
import { IconBold, IconDelete, IconItalic, IconLink, IconOpenInNew } from 'lib/lemon-ui/icons' | ||
|
||
export const InlineMenu = ({ editor }: { editor: Editor }): JSX.Element => { | ||
const { href, target } = editor.getAttributes('link') | ||
|
||
const setLink = (href: string): void => { | ||
editor.commands.setMark('link', { href: href }) | ||
} | ||
|
||
const openLink = (): void => { | ||
window.open(href, target) | ||
} | ||
|
||
return ( | ||
<BubbleMenu editor={editor} tippyOptions={{}}> | ||
<div className="NotebookInlineMenu flex bg-white rounded border items-center text-muted-alt p-1 space-x-1"> | ||
{editor.isActive('link') ? ( | ||
<> | ||
<LemonInput | ||
size="small" | ||
placeholder="https://posthog.com" | ||
onChange={setLink} | ||
value={href} | ||
className="border-0" | ||
autoFocus | ||
/> | ||
<LemonButton onClick={openLink} icon={<IconOpenInNew />} status="primary" size="small" /> | ||
<LemonButton | ||
onClick={() => editor.chain().focus().unsetMark('link').run()} | ||
icon={<IconDelete />} | ||
status="danger" | ||
size="small" | ||
/> | ||
</> | ||
) : ( | ||
<> | ||
<LemonButton | ||
onClick={() => editor.chain().focus().toggleMark('bold').run()} | ||
active={editor.isActive('bold')} | ||
icon={<IconBold />} | ||
size="small" | ||
status={editor.isActive('bold') ? 'primary' : 'stealth'} | ||
/> | ||
<LemonButton | ||
onClick={() => editor.chain().focus().toggleMark('italic').run()} | ||
active={editor.isActive('italic')} | ||
icon={<IconItalic />} | ||
status={editor.isActive('italic') ? 'primary' : 'stealth'} | ||
size="small" | ||
/> | ||
<LemonButton | ||
onClick={() => editor.chain().focus().setMark('link').run()} | ||
icon={<IconLink />} | ||
status="stealth" | ||
size="small" | ||
/> | ||
</> | ||
)} | ||
</div> | ||
</BubbleMenu> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.