New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-cn-quill

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-cn-quill

react-native quill richtext editor

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1K
decreased by-76.59%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-cn-quill

react-native-cn-quill is a rich-text editor for react-native. We've developed this library on top of Quill Api.

Why Quill

Quill is a free, open source WYSIWYG editor built for the modern web. Completely customize it for any need with its modular architecture and expressive API. Read more here.

Prerequisite

This package is using react-native-webview. Please follow this document to install it.

Installation

Install using npm:
npm i react-native-cn-quill
Install using yarn:
yarn add react-native-cn-quill

Usage

Here is a simple overview of our components usage.

import React from 'react';
import { SafeAreaView, StyleSheet, StatusBar } from 'react-native';
import QuillEditor, { QuillToolbar } from 'react-native-cn-quill';
export default function App() {
  const _editor = React.createRef();

  return (
    <SafeAreaView style={styles.root}>
      <StatusBar style="auto" />
      <QuillEditor
          style={styles.editor}
          ref={_editor}
          initialHtml="<h1>Quill Editor for react-native</h1>"
        />
      <QuillToolbar editor={_editor} options="full" theme="light" />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  title: {
    fontWeight: 'bold',
    alignSelf: 'center',
    paddingVertical: 10,
  },
  root: {
    flex: 1,
    marginTop: StatusBar.currentHeight || 0,
    backgroundColor: '#eaeaea',
  },
  editor: {
    flex: 1,
    padding: 0,
    borderColor: 'gray',
    borderWidth: 1,
    marginHorizontal: 30,
    marginVertical: 5,
    backgroundColor: 'white',
  },
});

QuillEditor

QuillEditor is the main component of this library. You may easily add it to your application. It is also a wrapper for Quill and provides most of it's functionalities.

QuillEditor Props

style

TypeRequired
view.styleNo

initialHtml

The Initial html string to display in editor.

TypeRequired
stringNo

quill

You may pass serveral options to customize quill to suit your needs .

TypeRequireddescription
{ id, modules: { toolbar }, theme, placeholder }Nodescribed below
quill.id

HTML id of the container where the editor will be appended.

TypeRequired
stringNo
quill.placeholder

Placeholder text to show when editor is empty.

TypeRequired
stringNo
quill.modules

list of quill modules. (only toolbar is implemented) to enable quill's built in toolbar pass true or a simple array of format names to quill.modules.toolbar

TypeRequired
{toolbar: boolean | array }No
quill.theme

Specify Quill's officially suppoted themes. (custom theme hasn't implemented yet)

TypeRequired
'snow' | 'bubble'No

import3rdParties

We provide two ways to import required 3rd party scritps and styles like quill's script and styles.

TypeRequired
'local' | 'cdn'No

containerId

HTML element id of the container for the quill object.

TypeRequired
stringNo

loading

Custom text or component to display before webview loaded.

TypeRequired
string | React.ReactNodeNo

theme

You may easily make your editor look good with the help of themes. you can pass color for background, text and placeholder.

TypeRequired
{ background: string; color: string; placeholder: string }No

container

The container component of webview. you may pass false to remove container or pass a custom component. Defaults to true which will wrap the webview inside a view component.

TypeRequired
boolean | React.ComponentTypeNo

webview

You may specify custom props for webview component.

TypeRequired
WebViewPropsNo

onSelectionChange

Calls when quill's selection changes.

TypeRequired
(range: { index, lengthmber } , oldRange: { index, length }, source) => voidNo

onTextChange

Calls when when the contents of Quill have changed.

TypeRequired
(delta, oldContents, source) => voidNo

onEditorChange

Calls when when the contents of Quill have changed or quill's selection have changed.

TypeRequired
(name , args) => voidNo

QuillEditor Methods

Read about these methods and their functionality on Quill Api

NameParamsReturnstype
blur-voidEditor
focus-voidEditor
disable-voidEditor
enableenable?voidEditor
hasFocus-Promise<boolean>Editor
update-voidEditor
formatname: string, value: anyvoidFormating
deleteTextindex: number, length: numbervoidContent
getContentsindex?: number, length?: numberPromiseContent
getLength-PromiseContent
getHtml-PromiseContent
getTextindex?: number, length?: numberPromiseContent
insertEmbedindex: number, type: string, value: anyvoidContent
insertTextindex: number, text: string, formats?: Record<string, any>voidContent
setContentsdelta: anyvoidContent
setTexttext: stringvoidContent
updateContentsdelta: anyvoidContent
onevent, handler -Event
offevent, handler-Event

QuillToolbar

The QuillToolbar component allow users to easily format Quill’s contents. QuillToolbar controls can be specified by a simple array of format names like ['bold', 'italic', 'underline', 'strike'] or by just passing 'basic' or 'full' string to options prop. we've tried to develop it just like Quill Toolbar options. The QuillToolbar uses a series of icons to render controls. this controls by default applies and removes formatting, but you can easily extend or overwrite these with custom prop.
For example we may add the image and clock (user defined control that inserts current date to the editor) handlers just like this:

Custom Handlers Usage

...
  const clockIcon = require('../assets/icons/clock.png');

  customHandler = (name: string, value: any) => {
    if (name === 'image') {
      this._editor.current?.insertEmbed(
        0,
        'image',
        'https://picsum.photos/200/300'
      );
    } else if (name === 'clock') {
      this._editor.current?.insertText(0, `Today is ${this.getCurrentDate()}`, {
        bold: true,
        color: 'red',
      });
    } else {
      console.log(`${name} clicked with value: ${value}`);
    }
  };

  render() {
    ...
        <QuillToolbar
          editor={this._editor}
          options={['image', 'clock']}
          theme="light"
          custom={{
            handler: this.customHandler,
            actions: ['image', 'clock'],
            icons: {
              clock: clockIcon,
            },
          }}
        />
        ...
  }

To see an example of how to fully implement this please check this Link.

QuillToolbar Props

styles

custom styles to pass to the inner components.

TypeRequired
{ toolbar, toolset, tool }No

editor

Reference of QuillEditor component.

TypeRequired
React.RefObject<QuillEditor>Yes

theme

You may easily make your toolbar look good with the help of themes. you can pass dark, light values or custom theme object with size,color,background and overlay props. ex. { size: 30, color: 'white', background: 'gray', overlay: 'rgba(0,0,0,.5')})

TypeRequired
'dark' | 'light' | objectNo

options

QuillToolbar controls can be specified by a simple array of format names like ['bold', 'italic', 'underline', 'strike'] or by just passing basic or full.

TypeRequired
'full' | 'basic' | array Yes

custom

You can easily extend or overwrite functionality of QuillToolbar with custom prop.

TypeRequired
{ handler, actions, icons }No
custom.handler
TypeRequired
(name: string, value: any) => voidNo
custom.icons

You may pass a dictionary of icons to overwrite or extend the default icons of toolbar. for example: { video: require('../assets/icons/video.png') }

TypeRequired
Record<string, any>No
custom.actions

you may specify list of format names to be overwriten. for ex. ['video', 'image'].

TypeRequired
string[]No

container

The container component of QuillToolbar. you may pass false to remove container or pass a custom component. Defaults to avoiding-view which will wrap the webview inside a KeyboardAvoidingView component.

TypeRequired
false | 'avoiding-view' | React.ComponentTypeNo

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Keywords

FAQs

Package last updated on 26 Feb 2021

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