import type { Meta, StoryObj } from '@storybook/html'; import { RichTextEditor, type RichTextEditorOptions } from '@42/core/rich-text-editor'; import '@42/styles/rich-text-editor.css'; const snippet = `import { RichTextEditor } from '@42/core/rich-text-editor'; import '@42/styles/rich-text-editor.css'; const editor = new RichTextEditor(document.querySelector('[data-c42-rich-text-editor]')!, { value: '

Start typing…

', }); editor.on('richtexteditor:change', (e) => console.log(e.detail.html));`; const BUTTONS: Array<[string, string, string]> = [ ['bold', 'Bold', 'B'], ['italic', 'Italic', 'I'], ['underline', 'Underline', 'U'], ['insertUnorderedList', 'Bulleted list', '• List'], ['insertOrderedList', 'Numbered list', '1. List'], ['createLink', 'Insert link', 'Link'], ['removeFormat', 'Clear formatting', 'Clear'], ]; function build(): HTMLElement { const root = document.createElement('div'); root.dataset.c42RichTextEditor = ''; root.style.maxWidth = '36rem'; const toolbar = BUTTONS.map( ([command, label, inner]) => ``, ).join(''); root.innerHTML = `
${toolbar}
`; return root; } const meta: Meta = { title: 'Core/Inputs & Forms/Rich Text Editor', tags: ['autodocs'], parameters: { docs: { source: { code: snippet, language: 'ts' }, }, }, render: (args) => { const root = build(); new RichTextEditor(root, { ...args, getLinkUrl: () => 'https://example.com', }); return root; }, }; export default meta; type Story = StoryObj; export const Default: Story = {}; export const WithContent: Story = { args: { value: '

This editor ships behaviour, not opinions. Select text and use the toolbar.

', }, };