Hey there,
with 0.16.0 the action bar can generally be customized, awesome!
Now I was wondering if this could be implemented on a component base.
For context: I am trying to recreate the RichTextEditor from tohuhono with TipTap, due to their easier UI.
So far I ripped this part from tohuhono to get the action bar.
export const getToolbarPortal = (id: string) => {
const base = document.querySelector("iframe")?.contentDocument || document
// Iframe selector
return base
?.querySelector(`[data-rfd-draggable-id="draggable-${id}"]`)
?.querySelector("button")?.parentElement
}
Now I can use a react portal, just like tohuhono did, this seems a bit sketchy, since the iframe selector might change anytime.
const RichTextToolbar = ({ id, editor }: Props) => {
const portalTarget = getToolbarPortal(id);
return (
<>
{portalTarget &&
createPortal(
<ActionBar.Group>
<ActionBar.Action
onClick={() => editor.chain().focus().toggleBold().run()}
>
<Bold size={16} />
</ActionBar.Action>
<ActionBar.Action
//active={editor.isActive("italic")}
onClick={() => editor.chain().focus().toggleItalic().run()}
>
<Italic size={16} />
</ActionBar.Action>
<ActionBar.Action
//active={editor.isActive("underline")}
onClick={() => editor.chain().focus().toggleUnderline().run()}
>
<Underline size={16} />
</ActionBar.Action>
</ActionBar.Group>,
portalTarget,
)}
</>
);
};
My idea here would be to have a actionBar property on the ComponentConfig similar to fields
Is this archievable?
Love this project!
Thanks a lot!