import type { Meta, StoryObj } from "@storybook/react" import { useState } from "react" import { TextEditor, type TextEditorProps } from "./TextEditor" /** * TextEditor is a powerful WYSIWYG editor built with TipTap that provides * rich text editing capabilities with formatting tools, resize functionality, * and extensive customization options. */ const meta = { title: "text-editor/TextEditor", component: TextEditor, parameters: { layout: "centered", }, tags: ["autodocs"], args: { className: "w-full", }, } satisfies Meta export default meta type Story = StoryObj const DefaultWrapper = (args: TextEditorProps) => { const [value, setValue] = useState("") return ( ) } /** * Default implementation of the TextEditor with basic configuration. */ export const Default: Story = { render: DefaultWrapper, } const WithContentWrapper = (args: TextEditorProps) => { const [value, setValue] = useState(`

Welcome to Text Editor

This is a bold text and this is italic text.

You can also add underlined text and strikethrough text.

  • Bullet point one
  • Bullet point two
  • Bullet point three

And even links to external content.

`) return ( ) } /** * TextEditor with pre-filled content to showcase formatting capabilities. */ export const WithContent: Story = { render: WithContentWrapper, } const DisabledWrapper = (args: TextEditorProps) => { const [value] = useState(`

Read-only Content

This editor is disabled and shows content in read-only mode.

All toolbar actions are disabled and content cannot be edited.

`) return ( ) } /** * TextEditor in disabled state to show read-only functionality. */ export const Disabled: Story = { render: DisabledWrapper, } const WithErrorWrapper = (args: TextEditorProps) => { const [value, setValue] = useState("") return (

Please enter valid content

) } /** * TextEditor with error state styling. */ export const WithError: Story = { render: WithErrorWrapper, } const CustomHeightWrapper = (args: TextEditorProps) => { const [value, setValue] = useState(`

This editor has a custom height of 600px.

You can resize it using the handle in the bottom-right corner.

Try adding more content to see how it behaves with scrolling:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

`) return ( ) } /** * TextEditor with custom height constraints. */ export const CustomHeight: Story = { render: CustomHeightWrapper, } const CompactWrapper = (args: TextEditorProps) => { const [value, setValue] = useState("") return ( ) } /** * Compact TextEditor with smaller height for inline usage. */ export const Compact: Story = { render: CompactWrapper, } const ControlledWrapper = (args: TextEditorProps) => { const [value, setValue] = useState("") const [wordCount, setWordCount] = useState(0) const handleChange = (newValue: string) => { setValue(newValue) // Calculate word count from plain text const text = newValue.replace(/<[^>]*>/g, "").trim() const count = text ? text.split(/\s+/).length : 0 setWordCount(count) } return (

Controlled Editor

Words: {wordCount}

Raw HTML Output:

          {value || "(empty)"}
        
) } /** * Controlled TextEditor demonstrating external state management. */ export const Controlled: Story = { render: ControlledWrapper, }