Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-texteditor-toolkit

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-texteditor-toolkit

A simple text editor component with formatting options using React.

  • 1.0.9
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
111
Maintainers
0
Weekly downloads
 
Created
Source

TextEditor Component

A fully customizable and easy-to-use rich text editor built with React. Includes support for formatting, alignment, lists, and more.

Features

  • Formatting: Bold, italic, underline, and capitalization toggle.
  • Alignment: Left, center, and right text alignment.
  • Lists: Ordered (numbered) and unordered (bulleted) lists.
  • Clear Formatting: Remove all applied styles.
  • Customizable Toolbar Actions.

Installation

Install the package via npm:

npm i react-texteditor-toolkit

Usage

Here's how to use the TextEditor in your project:

import React, { useState } from "react";
import TextEditor from "react-texteditor-toolkit";

const App = () => {
  const [content, setContent] = useState("");

  const handleContentChange = (e: { target: { value: string } }) => {
    setContent(e.target.value);
    console.log("Editor Content:", e.target.value);
  };

  return (
    <div>
      <h1>My Rich Text Editor</h1>
      <TextEditor
        placeholder="Start typing here..."
        onChange={handleContentChange}
        toolbarActions={["bold", "italic", "underline", "unorderedList", "clear"]}
        contentStyle={{ border: "1px solid #ddd", padding: "10px" }}
      />
      <p>Output:</p>
      <div dangerouslySetInnerHTML={{ __html: content }} />
    </div>
  );
};

export default App;

Customization

Styling the Editor

You can customize the editor's appearance using the contentStyle, iconStyle, and headerStyle props.

<TextEditor
  contentStyle={{ border: "2px solid #000", minHeight: "200px" }}
  iconStyle={{ color: "blue" }}
  headerStyle={{ backgroundColor: "#f4f4f4", padding: "10px" }}
/>
Read-Only Mode

To prevent edits, set readOnly to true:

<TextEditor readOnly={true} />

TextEditorProps

PropTypeDefaultDescription
iconStyleReact.CSSProperties{}Customize the style of toolbar icons.
contentStyleReact.CSSProperties{ border: '1px solid #ccc', padding: '10px' }Customize the editor's content area style.
headerStyleReact.CSSProperties{}Customize the style of the toolbar container.
placeholderstring"Type here..."Placeholder text shown in the editor when it's empty.
onChange(e: { target: { value: string } }) => voidundefinedCallback triggered when the editor's content changes.
readOnlybooleanfalseSets the editor to read-only mode.
toolbarActionsArray<string>See belowSpecify the available toolbar actions.

Available Toolbar Actions

You can customize the toolbarActions prop to include any of the following options:

  • "bold": Toggle bold formatting.
  • "italic": Toggle italic formatting.
  • "underline": Toggle underline formatting.
  • "unorderedList": Insert a bulleted list.
  • "orderedList": Insert a numbered list.
  • "alignLeft": Align text to the left.
  • "alignCenter": Align text to the center.
  • "alignRight": Align text to the right.
  • "capitalize": Toggle text capitalization.
  • "clear": Clear all formatting.

Keywords

FAQs

Package last updated on 24 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc