import type { Meta, StoryObj } from '@storybook/react-vite' import { EditorContent, useEditor } from '@tiptap/react' import StarterKit from '@tiptap/starter-kit' import { richTextClassName } from './RichText' import { KeptSelection, SelectionToolbar, type MarkId } from './SelectionToolbar' /** * Bold, italic, underline — and code or link where the editor has them — over * text you have already selected. It follows the selection by itself. */ const meta = { title: 'Primitives/SelectionToolbar', component: SelectionToolbar, parameters: { layout: 'padded' }, } satisfies Meta export default meta type Story = StoryObj /** * A real editor with a few words selected as it opens, so the strip is on * screen without a drag — it appears the way it always does, once the * selection has stood still. Select other words to move it. */ function WithAnEditor({ marks, link, html, select }: { marks?: readonly MarkId[]; link?: boolean; html: string; select: [number, number] }) { const editor = useEditor({ extensions: [StarterKit, KeptSelection], content: html, editorProps: { attributes: { class: richTextClassName('default', 'outline-none'), 'aria-label': 'Text' } }, onCreate: ({ editor: e }) => { e.commands.focus() e.commands.setTextSelection({ from: select[0], to: select[1] }) }, }) return (
Select a few words in this line, and the strip appears over them.
' /** The default strip: bold, italic, underline. */ export const Default: Story = { render: () =>