Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. ( function() {
  2. const { registerBlockType } = wp.blocks;
  3. const { createElement: el } = wp.element;
  4. const { InnerBlocks } = wp.editor;
  5.  
  6. registerBlockType( 'acme/product', {
  7. title: 'Product',
  8. icon: 'carrot',
  9. category: 'common',
  10.  
  11. edit() {
  12. return el( 'div', { className: 'product', style: { outline: '1px solid gray', padding: 5 } },
  13. // Only paragraphs, images, and products:
  14. el( InnerBlocks, { templateLock: 'insert', allowedBlocks: [ 'core/image', 'core/list' ], template: [ [ 'acme/buy-button' ], [ 'core/image' ], [ 'core/list' ] ] } )
  15. // Everything and products:
  16. //el( InnerBlocks )
  17. );
  18. },
  19.  
  20. save() {
  21. return el( 'div', { className: 'product', style: { outline: '1px solid gray', padding: 5 } },
  22. el( InnerBlocks.Content )
  23. );
  24. },
  25. } );
  26.  
  27. registerBlockType( 'acme/buy-button', {
  28. title: 'Buy Button',
  29. icon: 'cart',
  30. category: 'common',
  31.  
  32. // Only allow in products:
  33. parent: [ 'acme/product' ],
  34.  
  35. edit() {
  36. return el(
  37. 'button',
  38. {
  39. className: 'buy-button',
  40. style: { display: 'block', margin: '0 auto', padding: '10px 30px' },
  41. },
  42. 'Buy Now'
  43. );
  44. },
  45.  
  46. save() {
  47. return el(
  48. 'button',
  49. {
  50. className: 'buy-button',
  51. style: { display: 'block', margin: '0 auto', padding: '10px 30px' },
  52. },
  53. 'Buy Now'
  54. );
  55. },
  56. } );
  57. } )();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement