
Full TipTap editor with slash commands, bubble menu, floating menu, and tables.
@shadcnblocks
example/editor/editor-standard-1.tsx
"use client";
import * as React from "react";
import type { Editor, JSONContent } from "@/components/kibo-ui/editor";
import {
EditorBubbleMenu,
EditorCharacterCount,
EditorClearFormatting,
EditorFloatingMenu,
EditorFormatBold,
EditorFormatCode,
EditorFormatItalic,
EditorFormatStrike,
EditorFormatSubscript,
EditorFormatSuperscript,
EditorFormatUnderline,
EditorLinkSelector,
EditorNodeBulletList,
EditorNodeCode,
EditorNodeHeading1,
EditorNodeHeading2,
EditorNodeHeading3,
EditorNodeOrderedList,
EditorNodeQuote,
EditorNodeTable,
EditorNodeTaskList,
EditorNodeText,
EditorProvider,
EditorSelector,
EditorTableColumnAfter,
EditorTableColumnBefore,
EditorTableColumnDelete,
EditorTableColumnMenu,
EditorTableDelete,
EditorTableFix,
EditorTableGlobalMenu,
EditorTableHeaderColumnToggle,
EditorTableHeaderRowToggle,
EditorTableMenu,
EditorTableMergeCells,
EditorTableRowAfter,
EditorTableRowBefore,
EditorTableRowDelete,
EditorTableRowMenu,
EditorTableSplitCell,
} from "@/components/kibo-ui/editor";
export const title = "Rich text editor";
const initialContent: JSONContent = {
type: "doc",
content: [
{
type: "heading",
attrs: { level: 1 },
content: [{ type: "text", text: "Release notes" }],
},
{
type: "paragraph",
content: [
{ type: "text", text: "Write polished docs with " },
{ type: "text", marks: [{ type: "bold" }], text: "bold" },
{ type: "text", text: ", " },
{ type: "text", marks: [{ type: "italic" }], text: "italic" },
{ type: "text", text: ", and " },
{ type: "text", marks: [{ type: "code" }], text: "inline code" },
{ type: "text", text: ". Type " },
{ type: "text", marks: [{ type: "code" }], text: "/" },
{ type: "text", text: " for slash commands." },
],
},
{
type: "taskList",
content: [
{
type: "taskItem",
attrs: { checked: true },
content: [
{
type: "paragraph",
content: [{ type: "text", text: "Ship the changelog" }],
},
],
},
{
type: "taskItem",
attrs: { checked: false },
content: [
{
type: "paragraph",
content: [{ type: "text", text: "Record a demo clip" }],
},
],
},
],
},
{
type: "blockquote",
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: "Select text for the bubble menu, or leave a blank line for the floating menu.",
},
],
},
],
},
{
type: "codeBlock",
attrs: { language: "javascript" },
content: [
{
type: "text",
text: "export function greet(name) {\n return `Hello, ${name}`;\n}",
},
],
},
{
type: "table",
content: [
{
type: "tableRow",
content: ["Feature", "Status", "Owner"].map((text) => ({
type: "tableHeader",
attrs: { colspan: 1, rowspan: 1, colwidth: null },
content: [{ type: "paragraph", content: [{ type: "text", text }] }],
})),
},
{
type: "tableRow",
content: ["Slash commands", "Ready", "Design"].map((text) => ({
type: "tableCell",
attrs: { colspan: 1, rowspan: 1, colwidth: null },
content: [{ type: "paragraph", content: [{ type: "text", text }] }],
})),
},
{
type: "tableRow",
content: ["Tables", "Ready", "Editor"].map((text) => ({
type: "tableCell",
attrs: { colspan: 1, rowspan: 1, colwidth: null },
content: [{ type: "paragraph", content: [{ type: "text", text }] }],
})),
},
],
},
],
};
const Example = () => {
const [content, setContent] = React.useState<JSONContent>(initialContent);
return (
<EditorProvider
className="relative min-h-96 w-full max-w-2xl overflow-auto rounded-lg border bg-background p-4"
content={content}
onUpdate={({ editor }: { editor: Editor }) =>
setContent(editor.getJSON())
}
placeholder="Start typing, or press / for commands…"
>
<EditorFloatingMenu>
<EditorNodeHeading1 hideName />
<EditorNodeBulletList hideName />
<EditorNodeQuote hideName />
<EditorNodeCode hideName />
<EditorNodeTable hideName />
</EditorFloatingMenu>
<EditorBubbleMenu>
<EditorSelector title="Text">
<EditorNodeText />
<EditorNodeHeading1 />
<EditorNodeHeading2 />
<EditorNodeHeading3 />
<EditorNodeBulletList />
<EditorNodeOrderedList />
<EditorNodeTaskList />
<EditorNodeQuote />
<EditorNodeCode />
</EditorSelector>
<EditorSelector title="Format">
<EditorFormatBold />
<EditorFormatItalic />
<EditorFormatUnderline />
<EditorFormatStrike />
<EditorFormatCode />
<EditorFormatSuperscript />
<EditorFormatSubscript />
</EditorSelector>
<EditorLinkSelector />
<EditorClearFormatting />
</EditorBubbleMenu>
<EditorTableMenu>
<EditorTableColumnMenu>
<EditorTableColumnBefore />
<EditorTableColumnAfter />
<EditorTableColumnDelete />
</EditorTableColumnMenu>
<EditorTableRowMenu>
<EditorTableRowBefore />
<EditorTableRowAfter />
<EditorTableRowDelete />
</EditorTableRowMenu>
<EditorTableGlobalMenu>
<EditorTableHeaderColumnToggle />
<EditorTableHeaderRowToggle />
<EditorTableDelete />
<EditorTableMergeCells />
<EditorTableSplitCell />
<EditorTableFix />
</EditorTableGlobalMenu>
</EditorTableMenu>
<EditorCharacterCount.Words>Words: </EditorCharacterCount.Words>
</EditorProvider>
);
};
export default Example;




























