npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-trix-rte

v1.0.16

Published

React wrapper for Trix rich text editor created by Basecamp

Downloads

6,257

Readme

React Trix RTE

NPM GitHub Workflow Status npm

React Trix rich text editor is react wrapper built for the Trix editor created by Basecamp. We have built this library because we were rewriting the same component in multiple project.

This wrapper uses React hooks and adds readable event listeners on the Trix editor. The library also adds two toolbar components which has the ability to customize the toolbar actions as per our need.

Demo

Please see the some live example on ReactTrixRTE-Storybook

ReactTrixRTE

Installation

To install the React Trix RTE, run the following command in the console.

npm install react-trix-rte
OR
yarn add react-trix-rte

Usage

import Trix from "trix";
import React, { useState } from "react";
import { ReactTrixRTEInput } from "react-trix-rte";

export default function TrixEditor(props) {
  const [value, setValue] = useState("");

  function handleChange(event, newValue) {
    setValue(newValue); // OR custom on change listener.
  }

  return (
    <ReactTrixRTEInput
      defaultValue="<div>React Trix Rich Text Editor</div>"
      onChange={handleChange}
    />
  )
}

Upgrading to 1.0.7 or higher

React Trix RTE version 1.0.7 removes the dependency import for Trix because using Trix outside directly causes problems. Read issue: 17 and 19.

Import import Trix from "trix"; to the component using React Trix RTE.

ReactTrixInput API

ReactTrixInput is the Trix editor input which by default comes with the toolbar. The ReactTrixInput comes with following properties that could be accepted.

| Name | Type | Description | | ------------------- | ---- | ----------- | | id | string | The HTML id attribute for the input field | name | string | The HTML name attribute for the input field | toolbarId | string | If a custom toolbar is used for the Trix Input, pass the toolbarId of the custom toolbar to the input. | | isRailsDirectUpload | boolean | React Trix editor support direct uploading of the files to the service if you are using Rails as a backend server. This defaults to false | | railsDirectUploadUrl| string | Custom URL for Rails direct upload (data-direct-upload-url) | | railsBlobUrl | string | Custom URL for Rails blob template (data-blob-url-template) | | placeholder | string | Adds a placeholder to the React Trix Input | | defaultValue | string | The default value of the React Trix Input | | autofocus | boolean | Autofocus in the trix input. This is defaults to false | | className | string | Apply a custom css class to the editor | | trixInputRef | function | Adds a custom ref to the React Trix Input to programmatically edit text. Read the documentation for manual things you can perform on Trix editor here | | onBeforeInitialize | function | Fires when the <trix-editor> element is attached to the DOM just before Trix installs its editor object. | | onInitialize | function | Fires when the <trix-editor> element is attached to the DOM and its editor object is ready for use. | | onChange | function | Fires whenever the editor’s contents have changed. | | onSelectionChange | function | Fires any time the selected range changes in the editor. | | onBlur | function | Fire when the editor loses focus. | | onFocus | function | Fire when the editor gains focus. | | onFileAccepted | function | Fires when a file is dropped or inserted into the editor. You can access the DOM File object through the file property on the event. Call preventDefault on the event to prevent attaching the file to the document. | | onAttachmentAdd | function | Fires after an attachment is added to the document. You can access the Trix attachment object through the attachment property on the event. If the attachment object has a file property, you should store this file remotely and set the attachment’s URL attribute. See the attachment example for detailed information. | | onAttachmentRemove | function | Fires when an attachment is removed from the document. You can access the Trix attachment object through the attachment property on the event. You may wish to use this event to clean up remotely stored files. |

ReactTrixRTEToolbar API

ReactTrixRTEToolbar is the custom Trix editor toolbar component. This component helps in customizing the toolbar options, classes and attributes in better way.

| Name | Type | Description | | ------------------- | ---- | ----------- | | toolbarId | string | The ReactTrixInput initialize the default toolbar if the toolbarId is missing or not matching. Make sure the toolbarId matches. | | disableGroupingAction | boolean | Defaults to false. If the disableGroupingAction is enabled the toolbar actions are not grouped for a type. Example: text tools won't be grouped | | toolbarActions | array | Allows customizing the list of toolbar actions. The available actions are ["bold", "italic", "strike", "link", "heading1", "quote", "code", "bullet", "number", "outdent", "indent", "attachFiles", "undo", "redo"]. | | customToolbarActions | object | Override the toolbar actions properties or add custom toolbar actions. You can refer to default toolbar actions options |

Custom Toolbar Usage

import React, { useState } from "react";
import Trix from "trix";
import { ReactTrixRTEInput, ReactTrixRTEToolbar } from "react-trix-rte";

export default function TrixEditor(props) {
  const [value, setValue] = useState("");

  function handleChange(event, newValue) {
    setValue(newValue); // OR custom on change listener.
  }

  return (
    <Fragment>
      <ReactTrixRTEToolbar toolbarId="react-trix-rte-editor" />
      <ReactTrixRTEInput
        toolbarId="react-trix-rte-editor"
        defaultValue="<div>React Trix Rich Text Editor</div>"
        onChange={handleChange}
      />
    </Fragment>
  )
}

Contributing

Read more about contributing to the ReactTrixRTE.

Author

Abhay Nikam

Contributor

CUnknown

License

This project is licensed under the MIT License