diff --git a/packages/editor/examples/src/examples/index.ts b/packages/editor/examples/src/examples/index.ts index ce92514240..4bed5056c0 100644 --- a/packages/editor/examples/src/examples/index.ts +++ b/packages/editor/examples/src/examples/index.ts @@ -8,6 +8,8 @@ import { EmailThemingExample } from './email-theming'; import { FullEmailBuilder } from './full-email-builder'; import { Buttons } from './images-and-buttons'; import { LinkEditing } from './link-editing'; +import { OneLineEditor } from './one-line-editor'; +import { OneLineEditorFull } from './one-line-editor-full'; import { SlashCommands } from './slash-commands'; export interface ExampleItem { @@ -22,6 +24,21 @@ export interface ExampleSection { } export const sections: ExampleSection[] = [ + { + title: 'One-Line Editor', + examples: [ + { + id: 'one-line-editor', + label: 'Minimal', + component: OneLineEditor, + }, + { + id: 'one-line-editor-full', + label: 'Full Features', + component: OneLineEditorFull, + }, + ], + }, { title: 'Getting Started', examples: [ diff --git a/packages/editor/examples/src/examples/one-line-editor-full.tsx b/packages/editor/examples/src/examples/one-line-editor-full.tsx new file mode 100644 index 0000000000..96232a97ec --- /dev/null +++ b/packages/editor/examples/src/examples/one-line-editor-full.tsx @@ -0,0 +1,81 @@ +import { EmailEditor, type EmailEditorRef } from '@react-email/editor'; +import { useRef, useState } from 'react'; +import { ExampleShell } from '../example-shell'; + +const content = { + type: 'doc', + content: [ + { + type: 'heading', + attrs: { level: 1 }, + content: [{ type: 'text', text: 'Welcome to the Newsletter' }], + }, + { + type: 'paragraph', + content: [ + { + type: 'text', + text: 'Edit this content, then use the buttons below to export or inspect the editor output. Try switching themes to see how the editor adapts.', + }, + ], + }, + ], +}; + +export function OneLineEditorFull() { + const editorRef = useRef(null); + const [theme, setTheme] = useState<'basic' | 'minimal'>('basic'); + const [output, setOutput] = useState(''); + + const handleExportHtml = async () => { + if (!editorRef.current) return; + const result = await editorRef.current.export(); + setOutput(result.html); + }; + + const handleGetJson = () => { + if (!editorRef.current) return; + setOutput(JSON.stringify(editorRef.current.getJSON(), null, 2)); + }; + + return ( + +
+ + + +
+ + + + {output && ( +