(function ( wpI18n, wpBlocks, wpElement, wpEditor, wpComponents ) { const { __ } = wpI18n; const { Component, Fragment } = wpElement; const { registerBlockType } = wpBlocks; const { InspectorControls, PanelColorSettings } = wpEditor; const { PanelBody, RangeControl, SelectControl, TextControl } = wpComponents; const newsletterBlockIcon = ( ); class AdvNewsletter extends Component { constructor() { super( ...arguments ); } componentWillMount() { const { attributes, setAttributes } = this.props; const currentBlockConfig = advgbDefaultConfig['advgb-newsletter']; // 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 { attributes, setAttributes } = this.props; const { formStyle, formWidth, fnameLabel, lnameLabel, emailLabel, submitLabel, successLabel, alertLabel, bgColor, textColor, borderColor, borderStyle, borderRadius, submitColor, submitBgColor, submitRadius, } = attributes; return ( {(typeof advgbBlocks !== 'undefined' && !parseInt(advgbBlocks.captchaEnabled)) && (

{ __( 'We strongly recommend to enable Google reCaptcha to avoid spam bot. You can enable it in Form Recaptcha in' ) } { __( 'settings' ) }.

) } setAttributes( { formStyle: value } ) } /> setAttributes( { formWidth: value } ) } min={ 200 } max={ 1000 } /> {formStyle === 'alt' && ( setAttributes( { fnameLabel: value } ) } /> setAttributes( { lnameLabel: value } ) } /> ) } setAttributes( { emailLabel: value } ) } /> setAttributes( { submitLabel: value } ) } /> setAttributes( { alertLabel: value } ) } /> setAttributes( { successLabel: value } ) } /> setAttributes( { bgColor: value } ), }, { label: __( 'Text color' ), value: textColor, onChange: (value) => setAttributes( { textColor: value } ), }, ] } /> setAttributes( { borderColor: value } ), }, ] } /> setAttributes( { borderStyle: value } ) } /> setAttributes( { borderRadius: value } ) } min={ 0 } max={ 50 } /> setAttributes( { submitColor: value } ), }, { label: __( 'Background' ), value: submitBgColor, onChange: (value) => setAttributes( { submitBgColor: value } ), }, ] } /> setAttributes( { submitRadius: value } ) } min={ 0 } max={ 50 } />
{formStyle === 'default' && (
) } {formStyle === 'alt' && (
) }
) } } registerBlockType( 'advgb/newsletter', { title: __( 'Newsletter' ), description: __( 'Fastest way to create a newsletter form for your page.' ), icon: { src: newsletterBlockIcon, foreground: typeof advgbBlocks !== 'undefined' ? advgbBlocks.color : undefined, }, category: 'advgb-category', keywords: [ __( 'newsletter' ), __( 'form' ), __( 'email' ) ], attributes: { formStyle: { type: 'string', default: 'default', }, formWidth: { type: 'number', default: 400, }, fnameLabel: { type: 'string', }, lnameLabel: { type: 'string', }, emailLabel: { type: 'string', }, submitLabel: { type: 'string', }, successLabel: { type: 'string', }, alertLabel: { type: 'string', }, bgColor: { type: 'string', }, textColor: { type: 'string', }, borderStyle: { type: 'string', }, borderColor: { type: 'string', }, borderRadius: { type: 'number', }, submitColor: { type: 'string', }, submitBgColor: { type: 'string', }, submitRadius: { type: 'number', }, changed: { type: 'boolean', default: false, } }, edit: AdvNewsletter, save: function ( { attributes } ) { const { formStyle, formWidth, fnameLabel, lnameLabel, emailLabel, submitLabel, successLabel, alertLabel, bgColor, textColor, borderColor, borderStyle, borderRadius, submitColor, submitBgColor, submitRadius, } = attributes; return (
{formStyle === 'default' && (
) } {formStyle === 'alt' && (
) }
); } } ); })( wp.i18n, wp.blocks, wp.element, wp.editor, wp.components );