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

react-quilljs

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-quilljs

React Hook Wrapper for Quill, powerful rich text editor

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
increased by3.01%
Maintainers
1
Weekly downloads
 
Created
Source

react-quilljs Build Status

Quill Logo

React Hook Wrapper for Quill.

Typescript support • Unopinionated • No dependencies • Tiny package size

Install

$ npm install react-quilljs quill
or
$ yarn add react-quilljs quill

Usage

Basic

import React from 'react';

import { useQuill } from 'react-quilljs';
// or const { useQuill } = require('react-quilljs');

import 'quill/dist/quill.snow.css'; // Add css for snow theme
// or import 'quill/dist/quill.bubble.css'; // Add css for bubble theme

export default () => {
  const { editorRef, editor } = useQuill();

  console.log(editorRef); // { current: undefined } > { current: Editor Reference }
  console.log(editor);    // undefined > Quill Object

  return (
    <div style={{ width: 500, height: 300 }}>
      <div ref={editorRef} />
    </div>
  );
};

With Initial Value

export default () => {
  const { editorRef, editor } = useQuill();

  React.useEffect(() => {
    if (editor) {
      editor.clipboard.dangerouslyPasteHTML('<h1>React Hook for Quill!</h1>');
    }
  }, [editor]);

  return (
    <div style={{ width: 500, height: 300 }}>
      <div ref={editorRef} />
    </div>
  );
};

With Custom Options

import 'quill/dist/quill.bubble.css'; // Add css for bubble theme
// or import 'quill/dist/quill.snow.css'; // Add css for snow theme

export default () => {

  const theme = 'bubble';

  const modules = {
    toolbar: [
      ['bold', 'italic', 'underline', 'strike'],
    ],
  };

  const placeholder = 'Compose an epic...';

  const formats = ['bold', 'italic', 'underline', 'strike'];

  const { editorRef } = useQuill({ theme, modules, formats, placeholder });

  return (
    <div style={{ width: 500, height: 300, border: '1px solid lightgray' }}>
      <div ref={editorRef} />
    </div>
  );
};

With Custom Attached Image Upload

import fetch from 'isomorphic-unfetch';

export default () => {
  const { editorRef, editor } = useQuill();

  // Insert Image(selected by user) to editor
  const insertToEditor = (url) => {
    const range = editor.getSelection();
    editor.insertEmbed(range.index, 'image', url);
  };

  // Upload Image to Image Server such as AWS S3, Cloudinary, Cloud Storage, etc..
  const saveToServer = async (file) => {
    const body = new FormData();
    body.append('file', file);

    const res = await fetch('Your Image Server URL', { method: 'POST', body });
    insertToEditor(res.uploadedImageUrl);
  };

  // Open Dialog to select Image File
  const selectLocalImage = () => {
    const input = document.createElement('input');
    input.setAttribute('type', 'file');
    input.setAttribute('accept', 'image/*');
    input.click();

    input.onchange = () => {
      const file = input.files[0];
      saveToServer(file);
    };
  };

  React.useEffect(() => {
    if (editor) {
      // Add custom handler for Image Upload
      editor.getModule('toolbar').addHandler('image', selectLocalImage);
    }
  }, [editor]);

  return (
    <div style={{ width: 500, height: 300, border: '1px solid lightgray' }}>
      <div ref={editorRef} />
    </div>
  );
};

Parameters

useQuill(options)

options

Options for Quill Configuration.
Type: Object

  • theme
    Quill Theme.
    Type: String
    Default: 'snow'

  • modules
    Quill Modules.
    Type: Object
    Default:

    {
      toolbar: [
        ['bold', 'italic', 'underline', 'strike'],
        [{ align: [] }],
    
        [{ list: 'ordered'}, { list: 'bullet' }],
        [{ indent: '-1'}, { indent: '+1' }],
    
        [{ size: ['small', false, 'large', 'huge'] }],
        [{ header: [1, 2, 3, 4, 5, 6, false] }],
        ['link', 'image', 'video'],
        [{ color: [] }, { background: [] }],
    
        ['clean'],
      ],
      clipboard: {
        matchVisual: false,
      },
    }
    
  • formats
    Quill Formats.
    Type: Array
    Default:

    [
      'bold', 'italic', 'underline', 'strike',
      'align', 'list', 'indent',
      'size', 'header',
      'link', 'image', 'video',
      'color', 'background',
      'clean',
    ]
    

Return

editorRef

Editor reference.
Type: RefObject

editor

Quill object.
Type: Object

Recommend Libraries

  • React Checklist - Make Checkbox List Easy and Simple with React Hooks.
  • React Store - React Hook Store with useContext and useReducer for State Management.

Maintainer

License

MIT

Keywords

FAQs

Package last updated on 30 Dec 2019

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