如何在鹅毛笔工具栏中添加自定义图标

问题描述 投票:0回答:2
react-native quill react-quill
2个回答
6
投票

我找到了解决方案。

quill.html

<html>
<head>
  <script src="https://cdn.quilljs.com/1.3.7/quill.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdn.quilljs.com/1.3.7/quill.bubble.css"></link>
  <link rel="stylesheet" type="text/css" href="https://cdn.quilljs.com/1.3.7/quill.snow.css"></link>
  <script src="https://cdn.jsdelivr.net/gh/T-vK/DynamicQuillTools@master/DynamicQuillTools.js"></script>
</head>
<body>
  <div id="editor"></div>
  <script>
    // Create a Quill Editor instance with some built-in toolbar tools
    const quill = new Quill('#editor', {
        theme: 'snow',
        modules: {
            toolbar: {
                container: [
                    ['bold', 'italic', 'underline', 'strike'],
                    ['blockquote', 'code-block'],

                    [{ 'header': 1 }, { 'header': 2 }],
                    [{ 'list': 'ordered' }, { 'list': 'bullet' }],
                    [{ 'script': 'sub' }, { 'script': 'super' }],
                    [{ 'indent': '-1' }, { 'indent': '+1' }],
                    [{ 'direction': 'rtl' }],

                    [{ 'size': ['small', false, 'large', 'huge'] }],
                    [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

                    [{ 'color': [] }, { 'background': [] }],
                    [{ 'font': [] }],
                    [{ 'align': [] }],
                    ['clean'],
                ]
            }
        }
    })

    // Add a custom Button to the Quill Editor's toolbar:
    const myButton = new QuillToolbarButton({
    icon: `<svg viewBox="0 0 18 18"> <path class="ql-stroke" d="M5,3V9a4.012,4.012,0,0,0,4,4H9a4.012,4.012,0,0,0,4-4V3"></path></svg>`
    })
   
    myButton.onClick = function(quill) {
        const { index, length } = quill.selection.savedRange
        const selectedText = quill.getText(index, length)
        const newText = selectedText.toUpperCase()
        quill.deleteText(index, length)
        quill.insertText(index, newText)
        quill.setSelection(index, newText.length)
    }
    myButton.attach(quill)

 </script>
</body>
</html>

2
投票

经过验证的答案似乎使用以下库

https://github.com/T-vK/DynamicQuillTools

自述文件提供了清晰的示例

© www.soinside.com 2019 - 2024. All rights reserved.