Home

Awesome

Editor JS Alignment Tune

A simple but very customizable text alignment block tune for Editor Js package. Uses official package icons for better UI and UX compatibility.

Features

Installation

Using npm

  npm i editor-js-alignment-tune

Using Yarn

  yarn add editor-js-alignment-tune

Configuration

FieldTypeDescription
defaultstring"left, "center", "right" or "justify". If not set, it will be "left".
blocksobjectBlocks settings.
blocks.defaultstringDefault alignment for the desired block, same rule as "default" property.
blocks.availableAlignmentsstringCustom available alignments for the desired block. If not set, all alignments will be available.

Usage/Examples

Default use, no customization:

import EditorJS from '@editorjs/editorjs';
import AlignmentTune from 'editor-js-alignment-tune';

new EditorJS({
  tools: {
      paragraph: {
          class: Paragraph,
          tunes: ['alignmentTune']
      },
      alignmentTune: {
          class: AlignmentTune
      },
  }
});

Custom default alignment for all blocks:

import EditorJS from '@editorjs/editorjs';
import Paragraph from '@editorjs/paragraph';
import Header from '@editorjs/header';
import AlignmentTune from 'editor-js-alignment-tune';

new EditorJS({
  tools: {
      paragraph: {
          class: Paragraph,
          tunes: ['alignmentTune']
      },
      header: {
          class: Header,
          tunes: ['alignmentTune']
      },
      alignmentTune: {
          class: AlignmentTune,
          config: {
              default: 'center'
          }
      },
  }
});

Custom available alignments for specific blocks:

import EditorJS from '@editorjs/editorjs';
import Paragraph from '@editorjs/paragraph';
import Header from '@editorjs/header';
import AlignmentTune from 'editor-js-alignment-tune';

new EditorJS({
  tools: {
      paragraph: {
          class: Paragraph,
          tunes: ['alignmentTune']
      },
      header: {
          class: Header,
          tunes: ['alignmentTune']
      },
      alignmentTune: {
          class: AlignmentTune,
          config: {
              default: 'center', // All blocks not specified below will have this alignment
              blocks: {
                  header: {
                      default: left,
                      availableAlignments: ['left', 'center', 'right']
                  },
              }
          }
      },
  }
});

Useful tip: Editor JS tunes can have any name you want, just be sure that the "class" property is correct and the same name you set is used on "tunes" array of each block. E.g:

import EditorJS from '@editorjs/editorjs';
import Paragraph from '@editorjs/paragraph';
import Header from '@editorjs/header';
import AlignmentTune from 'editor-js-alignment-tune';

new EditorJS({
  tools: {
      paragraph: {
          class: Paragraph,
          tunes: ['customAlignmentName']
      },
      header: {
          class: Header,
          tunes: ['customAlignmentName']
      },
      customAlignmentName: {
          class: AlignmentTune,
          config: {
              default: 'center',
              blocks: {
                  header: {
                      default: left
                  },
              }
          }
      },
  }
});

Feedback

If it helped you someway, please give it a star <3.