/** * BLOCK: number-box * * Registering a basic block with Gutenberg. * Simple block, renders and saves the same content without any interactivity. */ //Import Icon import icon from './icons/icon'; // Import CSS. import './style.scss'; import './editor.scss'; import { version_1_1_2 } from './oldVersions'; const { __ } = wp.i18n; const { registerBlockType } = wp.blocks; const { InspectorControls, AlignmentToolbar, PanelColorSettings, BlockControls, RichText } = wp.editor; const { PanelBody, Toolbar, RangeControl, SelectControl } = wp.components; const { withState } = wp.compose; const attributes = { column: { type: 'select', default: '2' }, columnOneNumber: { type: 'array', source: 'children', selector: '.ub_number_one_number' }, columnTwoNumber: { type: 'array', source: 'children', selector: '.ub_number_two_number' }, columnThreeNumber: { type: 'array', source: 'children', selector: '.ub_number_three_number' }, columnOneTitle: { type: 'array', source: 'children', selector: '.ub_number_one_title' }, columnTwoTitle: { type: 'array', source: 'children', selector: '.ub_number_two_title' }, columnThreeTitle: { type: 'array', source: 'children', selector: '.ub_number_three_title' }, columnOneBody: { type: 'array', source: 'children', selector: '.ub_number_one_body' }, columnTwoBody: { type: 'array', source: 'children', selector: '.ub_number_two_body' }, columnThreeBody: { type: 'array', source: 'children', selector: '.ub_number_three_body' }, numberBackground: { type: 'string', default: '#CCCCCC' }, numberColor: { type: 'string', default: '#000000' }, borderColor: { type: 'string', default: '#CCCCCC' } }; /** * Register: aa Gutenberg Block. * * Registers a new block provided a unique name and an object defining its * behavior. Once registered, the block is made editor as an option to any * editor interface where blocks are implemented. * * @link https://wordpress.org/gutenberg/handbook/block-api/ * @param {string} name Block name. * @param {Object} settings Block settings. * @return {?WPBlock} The block, if it has been successfully * registered; otherwise `undefined`. */ registerBlockType('advanced-blocks/number-box', { title: __('Number Box'), icon: 'sos', category: 'advanced-blocks', keywords: [__('Number box'), __('Feature'), __('Ultimate Blocks')], attributes, /** * The edit function describes the structure of your block in the context of the editor. * This represents what the editor will render when the block is used. * * The "edit" property must be a valid function. * * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ */ edit: withState({ editable: 'content' })(function(props) { const { isSelected, editable, setState } = props; const { column, columnOneNumber, columnTwoNumber, columnThreeNumber, columnOneTitle, columnTwoTitle, columnThreeTitle, columnOneBody, columnTwoBody, columnThreeBody, numberBackground, numberColor, borderColor } = props.attributes; const columns = [ { value: '1', label: __('One Column') }, { value: '2', label: __('Two Column') }, { value: '3', label: __('Three Column') } ]; const onSetActiveEditable = newEditable => () => { setState({ editable: newEditable }); }; return [ isSelected && , isSelected && ( ({ value: value, label: label }))} onChange={value => { props.setAttributes({ column: value }); }} /> props.setAttributes({ numberBackground: colorValue }), label: __('Number Background Color') }, { value: numberColor, onChange: colorValue => props.setAttributes({ numberColor: colorValue }), label: __('Number Color') }, { value: borderColor, onChange: colorValue => props.setAttributes({ borderColor: colorValue }), label: __('Border Color') } ]} /> ),
props.setAttributes({ columnOneNumber: value }) } isSelected={ isSelected && editable === 'number_one' } onFocus={onSetActiveEditable('number_one')} keepPlaceholderOnFocus={true} />
props.setAttributes({ columnOneTitle: value }) } isSelected={isSelected && editable === 'title_one'} onFocus={onSetActiveEditable('title_one')} keepPlaceholderOnFocus={true} /> props.setAttributes({ columnOneBody: value }) } isSelected={isSelected && editable === 'body_one'} onFocus={onSetActiveEditable('body_one')} keepPlaceholderOnFocus={true} />
props.setAttributes({ columnTwoNumber: value }) } isSelected={ isSelected && editable === 'number_two' } onFocus={onSetActiveEditable('number_two')} keepPlaceholderOnFocus={true} />
props.setAttributes({ columnTwoTitle: value }) } isSelected={isSelected && editable === 'title_two'} onFocus={onSetActiveEditable('title_two')} keepPlaceholderOnFocus={true} /> props.setAttributes({ columnTwoBody: value }) } isSelected={isSelected && editable === 'body_two'} onFocus={onSetActiveEditable('body_two')} keepPlaceholderOnFocus={true} />
props.setAttributes({ columnThreeNumber: value }) } isSelected={ isSelected && editable === 'number_three' } onFocus={onSetActiveEditable('number_three')} keepPlaceholderOnFocus={true} />
props.setAttributes({ columnThreeTitle: value }) } isSelected={ isSelected && editable === 'title_three' } onFocus={onSetActiveEditable('title_three')} keepPlaceholderOnFocus={true} /> props.setAttributes({ columnThreeBody: value }) } isSelected={isSelected && editable === 'body_three'} onFocus={onSetActiveEditable('body_three')} keepPlaceholderOnFocus={true} />
]; }), /** * The save function defines the way in which the different attributes should be combined * into the final markup, which is then serialized by Gutenberg into post_content. * * The "save" property must be specified and must be a valid function. * * @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ */ save: function(props) { const { column, columnOneNumber, columnTwoNumber, columnThreeNumber, columnOneTitle, columnTwoTitle, columnThreeTitle, columnOneBody, columnTwoBody, columnThreeBody, numberBackground, numberColor, borderColor } = props.attributes; return (

{columnOneNumber}

{columnOneTitle}

{columnOneBody}

{columnTwoNumber}

{columnTwoTitle}

{columnTwoBody}

{columnThreeNumber}

{columnThreeTitle}

{columnThreeBody}

); }, deprecated: [ { attributes, save: version_1_1_2 } ] });