Home

Awesome

volto-subblocks

A widget for Volto to have a block with subblocks

To be used with mrs-developer, see Volto docs for further usage informations.

If you are using Volto < 16, then use v1.2.3.

Usage

This is meant to edit blocks with sub-blocks, where the sub-blocks are all of the same type.

SubblocksEdit

The edit component of the parent block must extend the class SubblocksEdit. If you want to enable drag&drop to reorder subblocks, you have to use the HOC 'withDNDContext'.

export default withDNDContext(Edit);

In the render() function of this component, you have to:

<SubblocksWrapper node={this.node}>...</SubblocksWrapper>

Usage

Example

import React from 'react';
import {
  withDNDContext,
  SubblocksEdit,
  SubblocksWrapper,
} from 'volto-subblocks';
import EditBlock from './EditBlock';

class Edit extends SubblocksEdit {
  render() {
    if (__SERVER__) {
      return <div />;
    }

    return (
      <SubblocksWrapper node={this.node}>
        ...
        {this.state.subblocks.map((subblock, subindex) => (
          <EditBlock
            data={subblock}
            index={subindex}
            selected={this.isSubblockSelected(subindex)}
            {...this.subblockProps}
            openObjectBrowser={this.props.openObjectBrowser}
          />
        ))}
        {this.props.selected && this.renderAddBlockButton()}
        ...
      </SubblocksWrapper>
    );
  }
}

export default React.memo(withDNDContext(Edit));

SubblockEdit

The edit component of the subblock must extend the class SubblockEdit

If you want to enable drag&drop to reorder subblocks, you have to compose with injectDNDSubblocks.

export default compose(injectDNDSubblocks)(EditBlock);

In the render() function of this component, you have to:

<Subblock subblock={this}>...</Subblock>

Example

import React from 'react';
import { compose } from 'redux';
import { injectDNDSubblocks, SubblockEdit, Subblock } from 'volto-subblocks';

class EditBlock extends SubblockEdit {
  render() {
    if (__SERVER__) {
      return <div />;
    }

    return <Subblock subblock={this}>...</Subblock>;
  }
}

export default React.memo(compose(injectDNDSubblocks)(EditBlock));

SubblocksWrapper

It's the wrapper to use in parent component. Properties:

Example

<SubblocksWrapper node={this.node} className="additional_class">
  ....
</SubblocksWrapper>

Subblock

It's the wrapper for each subblock. Use it in subblock edit component. Properties:

Example

<Subblock subblock={this} className="additional_class" draggable={false}>
  ....
</Subblock>

Authors

This product was developed by RedTurtle Technology team.

RedTurtle Technology Site