const { __ } = wp.i18n; const { createHigherOrderComponent } = wp.compose; const { registerBlockType } = wp.blocks; const { SelectControl, RadioControl, TextControl, Toolbar, Button, Tooltip, Panel, PanelBody, PanelRow, FormToggle, RangeControl } = wp.components; const { Fragment } = wp.element; const { RichText, AlignmentToolbar, BlockControls, BlockAlignmentToolbar, InspectorControls, InnerBlocks } = wp.editor; const buttonStyle = ({ style, outline, block }) => { let styles = style; if (outline) styles = styles.replace("btn-", "btn-outline-"); if (block) styles = styles + " btn-block"; return styles; } const buttonNewWindow = (newWindow) => { if (newWindow) return "_blank"; return "_self"; } registerBlockType( 'advanced-bootstrap-blocks/button', { title: __( 'Button (advanced-bootstrap-blocks)', 'advanced-bootstrap-blocks' ), description: __(''), icon: 'layout', category: 'layout', keywords: [ __('advanced-bootstrap-blocks'), __('button'), ], attributes: { type: { type: 'string', default: 'default' }, style: { type: 'string', default: 'btn-primary' }, outline: { type: 'bool', default: false }, block: { type: 'bool', default: false }, text: { type: 'string', default: 'Button' }, link: { type: 'string', default: '#' }, size: { type: 'string', default: '' }, newWindow: { type: 'bool', default: false }, }, edit: function( props ) { const { className, attributes: { type, text, link, style, outline, block, size, newWindow }, setAttributes } = props; const onChangeText = ( value ) => { setAttributes( { text: value } ); } const onChangeLink = ( value ) => { setAttributes( { link: value } ); } const onChangeStyle = ( value ) => { setAttributes( { style: value } ); } const onChangeOutline = () => { setAttributes( { outline: !outline } ); } const onChangeBlock = () => { setAttributes( { block: !block } ); } const onChangeSize = ( value ) => { setAttributes( { size: value } ); } const onChangeNewWindow = () => { setAttributes( { newWindow: !newWindow } ); } return ( { e.preventDefault()} > {text} } ); }, save: function( props ) { return ( {props.attributes.text} ); }, } ); // const modifyBlockListBlockContainer = createHigherOrderComponent( ( BlockListBlock ) => { // return ( props ) => { // if (props.block.name == "advanced-bootstrap-blocks/container") { // props.className = props.attributes.isWrapped ? props.className : ""; // } // return ; // }; // }, 'modifyBlockListBlockContainer' ); // wp.hooks.addFilter( // 'editor.BlockListBlock', // 'advanced-bootstrap-blocks/container/modify-element-edit', // modifyBlockListBlockContainer // ); // const modifyGetSaveElementContainer = (element, blockType, attributes ) => { // if (!element) { // return; // } // if (blockType.name === 'advanced-bootstrap-blocks/container') { // if (attributes.isWrapped) { // return ( //
//
// {element} //
//
// ) // } // return ( //
// {element} //
// ) // } // return element; // } // wp.hooks.addFilter( // 'blocks.getSaveElement', // 'advanced-bootstrap-blocks/container/modify-element-save', // modifyGetSaveElementContainer // );