(function ( wpI18n, wpBlocks, wpElement, wpEditor, wpComponents ) { const { __ } = wpI18n; const { Component, Fragment } = wpElement; const { registerBlockType } = wpBlocks; const { InspectorControls, RichText, PanelColorSettings } = wpEditor; const { RangeControl, PanelBody, TextControl, FormToggle } = wpComponents; class AdvCountUp extends Component { constructor() { super(...arguments); this.state = { currentEdit: '', }; } componentWillMount() { const { attributes, setAttributes } = this.props; const currentBlockConfig = advgbDefaultConfig['advgb-count-up']; // 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 { currentEdit } = this.state; const { attributes, setAttributes, isSelected } = this.props; const { headerText, headerText2, headerText3, headerTextColor, countUpNumber, countUpNumber2, countUpNumber3, countUpNumberColor, countUpNumberSize, countUpSymbol, countUpSymbol2, countUpSymbol3, countUpSymbolAfter, countUpSymbolAfter2, countUpSymbolAfter3, descText, descText2, descText3, descTextColor, columns, } = attributes; return ( setAttributes( { headerTextColor: value } ), }, { label: __( 'Count Up Color' ), value: countUpNumberColor, onChange: ( value ) => setAttributes( { countUpNumberColor: value } ), }, { label: __( 'Description Color' ), value: descTextColor, onChange: ( value ) => setAttributes( { descTextColor: value } ), }, ] } /> setAttributes( { columns: value } ) } /> setAttributes( { countUpNumberSize: value } ) } />
{ __( 'Counter Up Symbol' ) }
{
setAttributes( { countUpSymbol: value } ) } /> setAttributes( { countUpSymbolAfter: !countUpSymbolAfter } ) } title={ !!countUpSymbolAfter ? __( 'After' ) : __( 'Before' ) } />
} {parseInt(columns) > 1 &&
setAttributes( { countUpSymbol2: value } ) } /> setAttributes( { countUpSymbolAfter2: !countUpSymbolAfter2 } ) } title={ !!countUpSymbolAfter2 ? __( 'After' ) : __( 'Before' ) } />
} {parseInt(columns) > 2 &&
setAttributes( { countUpSymbol3: value } ) } /> setAttributes( { countUpSymbolAfter3: !countUpSymbolAfter3 } ) } title={ !!countUpSymbolAfter3 ? __( 'After' ) : __( 'Before' ) } />
}

{ __( 'Use toggle buttons above to define symbol placement before/after the number (toggle on is after).' ) }

setAttributes( { headerText: value } ) } isSelected={ isSelected && currentEdit === 'header' } unstableOnFocus={ () => this.setState( { currentEdit: 'header' } ) } style={ { color: headerTextColor } } placeholder={ __( 'Enter text…' ) } /> setAttributes( { countUpNumber: value } ) } isSelected={ isSelected && currentEdit === 'countUp' } unstableOnFocus={ () => this.setState( { currentEdit: 'countUp' } ) } style={ { fontSize: countUpNumberSize + 'px', color: countUpNumberColor } } /> setAttributes( { descText: value } ) } isSelected={ isSelected && currentEdit === 'desc' } unstableOnFocus={ () => this.setState( { currentEdit: 'desc' } ) } style={ { color: descTextColor } } placeholder={ __( 'Enter text…' ) } />
setAttributes( { headerText2: value } ) } isSelected={ isSelected && currentEdit === 'header2' } unstableOnFocus={ () => this.setState( { currentEdit: 'header2' } ) } style={ { color: headerTextColor } } placeholder={ __( 'Enter text…' ) } /> setAttributes( { countUpNumber2: value } ) } isSelected={ isSelected && currentEdit === 'countUp2' } unstableOnFocus={ () => this.setState( { currentEdit: 'countUp2' } ) } style={ { fontSize: countUpNumberSize + 'px', color: countUpNumberColor } } /> setAttributes( { descText2: value } ) } isSelected={ isSelected && currentEdit === 'desc2' } unstableOnFocus={ () => this.setState( { currentEdit: 'desc2' } ) } style={ { color: descTextColor } } placeholder={ __( 'Enter text…' ) } />
setAttributes( { headerText3: value } ) } isSelected={ isSelected && currentEdit === 'header3' } unstableOnFocus={ () => this.setState( { currentEdit: 'header3' } ) } style={ { color: headerTextColor } } placeholder={ __( 'Enter text…' ) } /> setAttributes( { countUpNumber3: value } ) } isSelected={ isSelected && currentEdit === 'countUp3' } unstableOnFocus={ () => this.setState( { currentEdit: 'countUp3' } ) } style={ { fontSize: countUpNumberSize + 'px', color: countUpNumberColor } } /> setAttributes( { descText3: value } ) } isSelected={ isSelected && currentEdit === 'desc3' } unstableOnFocus={ () => this.setState( { currentEdit: 'desc3' } ) } style={ { color: descTextColor } } placeholder={ __( 'Enter text…' ) } />
) } } function AdvCountUpSave( { attributes } ) { const { headerText, headerText2, headerText3, headerTextColor, countUpNumber, countUpNumber2, countUpNumber3, countUpNumberColor, countUpNumberSize, countUpSymbol, countUpSymbol2, countUpSymbol3, countUpSymbolAfter, countUpSymbolAfter2, countUpSymbolAfter3, descText, descText2, descText3, descTextColor, columns, } = attributes; const countSymbolElm = countUpSymbol ? { countUpSymbol } : ''; const countSymbolElm2 = countUpSymbol2 ? { countUpSymbol2 } : ''; const countSymbolElm3 = countUpSymbol3 ? { countUpSymbol3 } : ''; return (

{ headerText }

{!countUpSymbolAfter && countSymbolElm} { countUpNumber } {!!countUpSymbolAfter && countSymbolElm}

{ descText }

{parseInt(columns) > 1 && (

{ headerText2 }

{!countUpSymbolAfter2 && countSymbolElm2} { countUpNumber2 } {!!countUpSymbolAfter2 && countSymbolElm2}

{ descText2 }

) } {parseInt(columns) > 2 && (

{ headerText3 }

{!countUpSymbolAfter3 && countSymbolElm3} { countUpNumber3 } {!!countUpSymbolAfter3 && countSymbolElm3}

{ descText3 }

) }
); } const countUpBlockIcon = ( ); registerBlockType( 'advgb/count-up', { title: __( 'Count Up' ), description: __( 'Make a block with animate counting numbers.' ), icon: { src: countUpBlockIcon, foreground: typeof advgbBlocks !== 'undefined' ? advgbBlocks.color : undefined, }, category: 'advgb-category', keywords: [ __( 'numbers' ), __( 'count' ), __( 'increase' ) ], attributes: { headerText: { type: 'string', default: __( 'Header text' ), }, headerText2: { type: 'string', default: __( 'Header text' ), }, headerText3: { type: 'string', default: __( 'Header text' ), }, headerTextColor: { type: 'string', }, countUpNumber: { type: 'string', default: '56789' }, countUpNumber2: { type: 'string', default: '56789' }, countUpNumber3: { type: 'string', default: '56789' }, countUpNumberColor: { type: 'string', }, countUpNumberSize: { type: 'number', default: 55, }, countUpSymbol: { type: 'string', }, countUpSymbol2: { type: 'string', }, countUpSymbol3: { type: 'string', }, countUpSymbolAfter: { type: 'boolean', default: false, }, countUpSymbolAfter2: { type: 'boolean', default: false, }, countUpSymbolAfter3: { type: 'boolean', default: false, }, descText: { type: 'string', default: __( 'and description' ), }, descText2: { type: 'string', default: __( 'and description' ), }, descText3: { type: 'string', default: __( 'and description' ), }, descTextColor: { type: 'string', }, columns: { type: 'number', default: 1, }, changed: { type: 'boolean', default: false, }, }, edit: AdvCountUp, save: AdvCountUpSave, } ); })( wp.i18n, wp.blocks, wp.element, wp.editor, wp.components );