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.3.2
  • 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, Text, View, KeyboardAvoidingView, 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}>
      <Text style={styles.title}>Quill Editor</Text>
      <KeyboardAvoidingView style={styles.container}
        behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
        <View style={styles.editor}>
          <QuillEditor ref={_editor} />
        </View>
        <View>
          <QuillToolbar editor={_editor} options="full" theme="light" />
        </View>
        <StatusBar style="auto" />
      </KeyboardAvoidingView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  title: {
    fontWeight: 'bold',
    alignSelf: 'center',
    paddingVertical: 10,
  },
  root: {
    flex: 1,
    backgroundColor: '#eee',
  },
  container: {
    flex: 1,
  },
  editor: {
    flex: 1,
    marginHorizontal: 40,
    backgroundColor: '#fff',
    padding: 15,
  },
});

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

NameDescriptionRequired
styleStyles applied to the outermost component.No

Instance 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
on-event: EditorEventType, handler: FunctionEvent (under development)
off-event: EditorEventTypeEvent (under development)

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:

...
  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

NameDescriptionRequired
styles{ toolbar?, toolset?, tool? }No
editorReact.RefObject<QuillEditor>Yes
theme'dark' , 'light', ToolbarTheme (ex: { size: 30, color: 'white', background: 'gray', overlay: 'rgba(0,0,0,.5')})false
options'full' , 'basic', array (ex: [['bold', 'italic'], ['link', 'image']])Yes
custom{ handler?: (name: string, value: any) => void; actions?: Array<string>; icons?: Record<string, any>; }No

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 14 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