0.8.0-alpha.6 • Published 2 days ago

@mercuriya/slate-gallery v0.8.0-alpha.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

Slate gallery

An image gallery for slate editor

Installation

yarn add @mercuriya/slate-gallery
npm install @mercuriya/slate-gallery --save

Peer dependencies

It uses react-dropzone, react-sortable-hoc, array-move so, please, install them, if you don't have them yet:

yarn add react-dropzone react-sortable-hoc array-move
npm install react-dropzone react-sortable-hoc array-move --save

Configuration

In your file with Slate component:

import React from 'react';
import { createEditor } from 'slate';
import { Slate, Editable, withReact } from 'slate-react';
import { withGallery, } from '@mercuriya/slate-gallery';

const initialValue = Value.fromJSON({ ... });
const plugins = [galleryPlugin({ ...options })];

export default function EditorComponent(props) {
  const [value, setValue] = useState([ /* some initial state here */ ]);
  const editor = useMemo(
    () =>
      withGallery(withReact(createEditor()), {
        // slate-gallery options        
      }),
    [],
  );   
  const renderElement = useCallback(({ attributes, children, element }) => {
    switch (element.type) {
      case 'gallery':
        return editor.galleryElementType({
          attributes,
          children,
          element,
          // ❗️ we use this prop internally, so you must provide it here
          readOnly: false, // or true
        });
      default:
        return <p {...attributes}>{children}</p>;
    }
  }, []);

  return (
    <Slate editor={editor} value={value} onChange={value => setValue(value)}>
      <Editable renderElement={renderElement} />
    </Slate>
  );
}

Description

This plugin adds a void block which can show images as an image grid. It allows to cover each image in something like image lightbox if you want.

Each image can have a description, which is not related with image tag alt props. It is stored as data of this gallery block.

readOnly: false mode:

readOnly: false

readOnly: true mode:

readOnly: true

Please, see stories for more usage examples.

Options

NameTypeDescription
size? (default: 9)numberMin: 1, max: 9. It represents a grid size. A number of images which will be visible within readOnly: true mode. The remaining images will be hidden, but user will see them in the images lightbox if you will implement this.
dropzoneProps?objectAn object of react-dropzone props which is applies to Dropzone component
sortableContainerProps?objectAn object of react-sortable-hoc props which is applies to SortableContainer's component
renderControls?args => React.ReactNodeA render function that allows you to customize controls block. See types definitions for more example
renderEditModal?args => React.ReactNodeA render function that allows you to use custom modal while editing images descriptions
renderExtra?args => React.ReactNodeA render function that allows you to place additional component near image gallery. It could be handy to build image-lightbox functionality
renderImage?args => React.ReactNodeA render function that allows you to customize and image component
gridClassName?stringGrid component custom class name
imageClassName?stringImage component custom class name
imageWrapperClassName?stringImage wrapper custom class name
leftClassName?stringNumber of left images (+x) custom className
0.8.0-alpha.6

2 days ago

0.8.0-alpha.4

5 months ago

0.8.0-alpha.3

5 months ago

0.8.0-alpha.2

5 months ago

0.8.0-alpha.1

12 months ago

1.0.0-alpha.0

12 months ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago