Getting Started
Editor Plugins
Start typing...
"use client"
import { useState } from "react"
import {
InitialConfigType,
LexicalComposer,
} from "@lexical/react/LexicalComposer"
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"
import { QuoteNode } from "@lexical/rich-text"
import { ContentEditable } from "@/registry/new-york-v4/editor/editor-ui/content-editable"
import { ComponentPickerMenuPlugin } from "@/registry/new-york-v4/editor/plugins/component-picker-menu-plugin"
import { AlignmentPickerPlugin } from "@/registry/new-york-v4/editor/plugins/picker/alignment-picker-plugin"
import { HeadingPickerPlugin } from "@/registry/new-york-v4/editor/plugins/picker/heading-picker-plugin"
import { ParagraphPickerPlugin } from "@/registry/new-york-v4/editor/plugins/picker/paragraph-picker-plugin"
import { QuotePickerPlugin } from "@/registry/new-york-v4/editor/plugins/picker/quote-picker-plugin"
import { editorTheme } from "@/registry/new-york-v4/editor/themes/editor-theme"
import { TooltipProvider } from "@/components/ui/tooltip"
const editorConfig: InitialConfigType = {
namespace: "Editor",
theme: editorTheme,
nodes: [QuoteNode],
onError: (error: Error) => {
console.error(error)
},
}
export function RichTextEditorDemo() {
return (
<div className="bg-background w-full overflow-hidden rounded-lg border">
<LexicalComposer
initialConfig={{
...editorConfig,
}}
>
<TooltipProvider>
<Plugins />
</TooltipProvider>
</LexicalComposer>
</div>
)
}
const placeholder = "Start typing..."
export function Plugins() {
const [floatingAnchorElem, setFloatingAnchorElem] =
useState<HTMLDivElement | null>(null)
const onRef = (_floatingAnchorElem: HTMLDivElement) => {
if (_floatingAnchorElem !== null) {
setFloatingAnchorElem(_floatingAnchorElem)
}
}
return (
<div className="relative">
{/* toolbar plugins */}
<div className="relative">
<RichTextPlugin
contentEditable={
<div className="">
<div className="" ref={onRef}>
<ContentEditable
placeholder={placeholder}
className="ContentEditable__root relative block h-72 min-h-72 min-h-full overflow-auto px-8 py-4 focus:outline-none"
/>
</div>
</div>
}
ErrorBoundary={LexicalErrorBoundary}
/>
<ComponentPickerMenuPlugin
baseOptions={[
ParagraphPickerPlugin(),
HeadingPickerPlugin({ n: 1 }),
HeadingPickerPlugin({ n: 2 }),
HeadingPickerPlugin({ n: 3 }),
QuotePickerPlugin(),
AlignmentPickerPlugin({ alignment: "left" }),
AlignmentPickerPlugin({ alignment: "right" }),
AlignmentPickerPlugin({ alignment: "center" }),
AlignmentPickerPlugin({ alignment: "justify" }),
]}
/>
{/* rest of the plugins */}
</div>
</div>
)
}
Installation
pnpm dlx shadcn@latest add https://shadcn-editor.vercel.app/r/component-picker-menu-plugin.json
On This Page
Installation