@idstory-idm/rich-text
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

@idstory-idm/rich-text

Install

npm:

npm i @idstory-idm/rich-text

Yarn:

yarn add @idstory-idm/rich-text

Use

import React from 'react'
import {
  RichTextEditor,
  getHtmlFromEditor,
  useRichTextEditorToolbar
} from '@idstory-idm/rich-text'

function Toolbar() {
  const {
    setTextFormat,
    setHeading,
    setList,
    setBlock,
    formats,
    blockType,
    isEditable,
    canRedo,
    canUndo,
    undo,
    redo
  } = useRichTextEditorToolbar();
  
  return (
    {/* ... toolbar component code */}
  )
}

interface MyComponentProps {
  htmlValue?: string
  placeholder?: string
  readOnly?: boolean
  className?: string
  children?: React.ReactNode
  style?: React.CSSProperties
}

export function MyComponent({ children, htmlValue, placeholder, readOnly, className, style }: MyComponentProps) {
  const handleChange = (editorState: EditorState, editor: LexicalEditor, tags: Set<string>) => {
    editorState.read(() => {
      const htmlValue = getHtmlFromEditor(editor);
      console.log({ htmlValue })
    });
  }
  
  return (
    <RichTextEditor
      htmlValue={htmlValue}
      className={className}
      placeholder={placeholder}
      readOnly={readOnly}
      onChange={handleChange}
      style={style}
    >
      <Toolbar />
      {children}
    </RichTextEditor>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i @idstory-idm/rich-text

Weekly Downloads

3

Version

0.0.5

License

none

Unpacked Size

18.6 kB

Total Files

9

Last publish

Collaborators

  • peterstrunc
  • boristb