(function ( wpI18n, wpBlocks, wpElement, wpEditor, wpComponents ) { const { __ } = wpI18n; const { Component, Fragment } = wpElement; const { registerBlockType } = wpBlocks; const { InspectorControls, RichText, PanelColorSettings, InnerBlocks } = wpEditor; const { RangeControl, PanelBody, BaseControl , SelectControl, ToggleControl } = wpComponents; const HEADER_ICONS = { plus: ( ), plusCircle: ( ), plusCircleOutline: ( ), plusBox: ( ), unfold: ( ), threeDots: ( ), arrowDown: ( ) }; class AdvAccordion extends Component { constructor() { super( ...arguments ); this.state = { currentAccordion: null, } } componentWillMount() { const { attributes, setAttributes } = this.props; const currentBlockConfig = advgbDefaultConfig['advgb-accordion']; // No override attributes of blocks inserted before if (attributes.changed !== true) { if (typeof currentBlockConfig === 'object' && currentBlockConfig !== null) { Object.keys(currentBlockConfig).map((attribute) => { if (typeof attributes[attribute] === 'boolean') { attributes[attribute] = !!currentBlockConfig[attribute]; } else { attributes[attribute] = currentBlockConfig[attribute]; } }); } // Finally set changed attribute to true, so we don't modify anything again setAttributes( { changed: true } ); } } render() { const { isSelected, attributes, setAttributes } = this.props; const { header, headerBgColor, headerTextColor, headerIcon, headerIconColor, bodyBgColor, bodyTextColor, borderStyle, borderWidth, borderColor, borderRadius, marginBottom, collapsedAll, } = attributes; return ( setAttributes( { marginBottom: value } ) } />
{Object.keys( HEADER_ICONS ).map( ( key, index ) => (
setAttributes( { headerIcon: key } ) }> { HEADER_ICONS[key] }
) ) }
setAttributes( { headerBgColor: value === undefined ? '#000' : value } ), }, { label: __( 'Text Color' ), value: headerTextColor, onChange: ( value ) => setAttributes( { headerTextColor: value === undefined ? '#eee' : value } ), }, { label: __( 'Icon Color' ), value: headerIconColor, onChange: ( value ) => setAttributes( { headerIconColor: value === undefined ? '#fff' : value } ), }, ] } />
setAttributes( { bodyBgColor: value } ), }, { label: __( 'Text Color' ), value: bodyTextColor, onChange: ( value ) => setAttributes( { bodyTextColor: value } ), }, ] } /> setAttributes( { borderStyle: value } ) } /> setAttributes( { borderColor: value } ), }, ] } /> setAttributes( { borderWidth: value } ) } /> setAttributes( { borderRadius: value } ) } /> setAttributes( { collapsedAll: !collapsedAll } ) } />
{ HEADER_ICONS[headerIcon] } setAttributes( { header: value } ) } unstableOnSplit={ () => null } className="advgb-accordion-header-title" placeholder={ __( 'Enter header…' ) } />
) } } const accordionBlockIcon = ( ); const accordionAttrs = { header: { type: 'string', default: __( 'Header text' ), }, headerBgColor: { type: 'string', default: '#000', }, headerTextColor: { type: 'string', default: '#eee', }, headerIcon: { type: 'string', default: 'unfold', }, headerIconColor: { type: 'string', default: '#fff', }, bodyBgColor: { type: 'string', }, bodyTextColor: { type: 'string', }, borderStyle: { type: 'string', default: 'solid', }, borderWidth: { type: 'number', default: 0, }, borderColor: { type: 'string', }, borderRadius: { type: 'number', default: 2, }, marginBottom: { type: 'number', default: 15, }, collapsedAll: { type: 'boolean', default: false, }, changed: { type: 'boolean', default: false, }, }; registerBlockType( 'advgb/accordion', { title: __( 'Accordion' ), description: __( 'Easy to create an accordion for your post/page.' ), icon: { src: accordionBlockIcon, foreground: typeof advgbBlocks !== 'undefined' ? advgbBlocks.color : undefined, }, category: 'advgb-category', keywords: [ __( 'accordion' ), __( 'list' ), __( 'faq' ) ], attributes: accordionAttrs, edit: AdvAccordion, save: function ( { attributes } ) { const { header, headerBgColor, headerTextColor, headerIcon, headerIconColor, bodyBgColor, bodyTextColor, borderStyle, borderWidth, borderColor, borderRadius, marginBottom, collapsedAll, } = attributes; return (
{ HEADER_ICONS[headerIcon] }

{ header }

); }, } ); })( wp.i18n, wp.blocks, wp.element, wp.editor, wp.components );