Socket
Socket
Sign inDemoInstall

ra-input-rich-text

Package Overview
Dependencies
13
Maintainers
3
Versions
200
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ra-input-rich-text

<RichTextInput> component for react-admin, useful for editing HTML code in admin GUIs.


Version published
Weekly downloads
6.9K
decreased by-26.6%
Maintainers
3
Created
Weekly downloads
 

Changelog

Source

v4.16.16

  • Fix <Admin requireAuth> forbids access to custom routes with no layout (#9786) (fzaninotto)
  • [Doc] Add Soul data provider (#9776) (fzaninotto)
  • [Doc] Update third-party Inputs to add link to Google Places AutocompleteInput (#9771) (quentin-decre)
  • [Doc] Update <Search> and <SearchWithResult> to introduce queryOptions (#9779) (erwanMarmelab)
  • [Doc] Update RBAC to better explain the difference between the built-in actions (#9766) (slax57)
  • [Doc] Fix <SimpleForm> has wrong import for <RichTextInput> (#9775) (anthonycmain)
  • [Doc] Fix <RichTextInput> typo on TipTap (#9759) (adguernier)
  • [Doc] Update <JsonSchemaForm> to add details about available widgets (#9758) (adguernier)
  • [TypeScript] Fix warning in create-react-admin (#9728) (hbendev)

Readme

Source

ra-input-rich-text

A rich text editor for React Admin, based on TipTap.

Installation

npm install ra-input-rich-text
# or
yarn add ra-input-rich-text

Usage

Use it as you would any react-admin input:

import { Edit, SimpleForm, TextInput } from 'react-admin';
import { RichTextInput } from 'ra-input-rich-text';

export const PostEdit = () => (
  <Edit>
    <SimpleForm>
      <TextInput source="title" />
      <RichTextInput source="body" />
    </SimpleForm>
  </Edit>
);

Customizing the Toolbar

The <RichTextInput> component has a toolbar prop that accepts a ReactNode.

You can leverage this to change the buttons size:

import { Edit, SimpleForm, TextInput } from 'react-admin';
import { RichTextInput, RichTextInputToolbar } from 'ra-input-rich-text';

export const PostEdit = () => (
  <Edit>
    <SimpleForm>
      <TextInput source="title" />
      <RichTextInput source="body" toolbar={<RichTextInputToolbar size="large" />} />
    </SimpleForm>
  </Edit>
);

Or to remove some prebuilt components like the <AlignmentButtons>:

import {
  RichTextInput,
  RichTextInputToolbar,
  LevelSelect,
  FormatButtons,
  ListButtons,
  LinkButtons,
  QuoteButtons,
  ClearButtons,
} from 'ra-input-rich-text';

const MyRichTextInput = ({ size, ...props }) => (
  <RichTextInput
    toolbar={
      <RichTextInputToolbar>
        <LevelSelect size={size} />
        <FormatButtons size={size} />
        <ListButtons size={size} />
        <LinkButtons size={size} />
        <QuoteButtons size={size} />
        <ClearButtons size={size} />
      </RichTextInputToolbar>
    }
    label="Body"
    source="body"
    {...props}
  />
);

Customizing the editor

You might want to add more TipTap extensions. The <RichTextInput> component accepts an editorOptions prop, which is the object passed to the TipTap Editor.

If you just want to add extensions, don't forget to include those needed by default for our implementation. Here's an example to add the HorizontalRule node:

import {
  DefaultEditorOptions,
  RichTextInput,
  RichTextInputToolbar,
  LevelSelect,
  FormatButtons,
  AlignmentButtons,
  ListButtons,
  LinkButtons,
  QuoteButtons,
  ClearButtons,
} from 'ra-input-rich-text';
import HorizontalRule from '@tiptap/extension-horizontal-rule';
import Remove from '@mui/icons-material/Remove';

const MyRichTextInput = ({ size, ...props }) => (
  <RichTextInput
    editorOptions={MyEditorOptions}
    toolbar={
      <RichTextInputToolbar>
        <LevelSelect size={size} />
        <FormatButtons size={size} />
        <AlignmentButtons {size} />
        <ListButtons size={size} />
        <LinkButtons size={size} />
        <QuoteButtons size={size} />
        <ClearButtons size={size} />
        <ToggleButton
          aria-label="Add an horizontal rule"
          title="Add an horizontal rule"
          onClick={() => editor.chain().focus().setHorizontalRule().run()}
          selected={editor && editor.isActive('horizontalRule')}
        >
          <Remove fontSize="inherit" />
      </ToggleButton>
      </RichTextInputToolbar>
    }
    label="Body"
    source="body"
    {...props}
  />
);

export const MyEditorOptions = {
  ...DefaultEditorOptions,
  extensions: [
    ...DefaultEditorOptions.extensions,
        HorizontalRule,
  ],
};

License

This data provider is licensed under the MIT License, and sponsored by Marmelab.

FAQs

Last updated on 23 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc