Created
June 5, 2018 17:08
-
-
Save jorgefilipecosta/040835aec32a0b0c5f2f229e9ba90d86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function() { | |
const { registerBlockType } = wp.blocks; | |
const { createElement: el } = wp.element; | |
const { InnerBlocks } = wp.blocks; | |
const circle = el( 'circle', { cx: 10, cy: 10, r: 10, fill: 'red', stroke: 'blue', strokeWidth: '10' } ); | |
const svg = el( 'svg', { width: 20, height: 20, viewBox: '0 0 20 20'}, circle) | |
registerBlockType( 'acme/product', { | |
title: 'Product', | |
icon: svg, | |
category: 'common', | |
edit() { | |
return el( 'div', { className: 'product', style: { outline: '1px solid gray', padding: 5 } }, | |
// Only paragraphs, images, and products: | |
el( InnerBlocks, { allowedBlocks: [ 'core/paragraph', 'core/image' ] } ) | |
// Everything and products: | |
//el( InnerBlocks ) | |
); | |
}, | |
save() { | |
return el( 'div', { className: 'product', style: { outline: '1px solid gray', padding: 5 } }, | |
el( InnerBlocks.Content ) | |
); | |
}, | |
} ); | |
registerBlockType( 'acme/buy-button', { | |
title: 'Buy Button', | |
icon: { | |
background: '#7e70af', | |
src: 'cart', | |
}, | |
category: 'common', | |
// Only allow in products: | |
parent: [ 'acme/product' ], | |
edit() { | |
return el( | |
'button', | |
{ | |
className: 'buy-button', | |
style: { display: 'block', margin: '0 auto', padding: '10px 30px' }, | |
}, | |
'Buy Now' | |
); | |
}, | |
save() { | |
return el( | |
'button', | |
{ | |
className: 'buy-button', | |
style: { display: 'block', margin: '0 auto', padding: '10px 30px' }, | |
}, | |
'Buy Now' | |
); | |
}, | |
} ); | |
} )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment