index.js
72 lines
| 1 | (function(blocks, blockEditor, element, components, i18n) { |
| 2 | |
| 3 | var el = element.createElement, |
| 4 | SelectControl = components.SelectControl, |
| 5 | Button = components.Button, |
| 6 | __ = i18n.__; |
| 7 | |
| 8 | blocks.registerBlockType('widget-google-reviews/reviews', { |
| 9 | apiVersion: 3, |
| 10 | title: __('Google Reviews Block', 'widget-google-reviews'), |
| 11 | icon: 'star-filled', |
| 12 | category: 'widgets', |
| 13 | keywords: ['google', 'reviews', 'google reviews', 'block'], |
| 14 | attributes: {id: {type: 'string'}}, |
| 15 | |
| 16 | edit: function(props) { |
| 17 | |
| 18 | var attributes = props.attributes; |
| 19 | var blockProps = blockEditor.useBlockProps(); |
| 20 | |
| 21 | let feeds = grwBlockData.feeds, |
| 22 | options = [{label: __('Select reviews widget', 'widget-google-reviews'), value: ''}]; |
| 23 | |
| 24 | for (let i = 0; i < feeds.length; i++) { |
| 25 | options.push({label: feeds[i].name, value: String(feeds[i].id)}); |
| 26 | } |
| 27 | |
| 28 | return el( |
| 29 | 'div', |
| 30 | blockProps, |
| 31 | el( |
| 32 | SelectControl, |
| 33 | { |
| 34 | id: 'id', |
| 35 | name: 'id', |
| 36 | value: attributes.id || '', |
| 37 | options: options, |
| 38 | onChange: function(newval) { |
| 39 | props.setAttributes({id: newval}); |
| 40 | } |
| 41 | } |
| 42 | ), |
| 43 | el( |
| 44 | Button, |
| 45 | { |
| 46 | text: __('Edit reviews widget', 'widget-google-reviews'), |
| 47 | href: grwBlockData.builderUrl + '&grw_feed_id=' + attributes.id, |
| 48 | target: '_blank' |
| 49 | } |
| 50 | ), |
| 51 | el( |
| 52 | Button, |
| 53 | { |
| 54 | text: __('Create new reviews widget', 'widget-google-reviews'), |
| 55 | href: grwBlockData.builderUrl, |
| 56 | target: '_blank' |
| 57 | } |
| 58 | ) |
| 59 | ); |
| 60 | }, |
| 61 | |
| 62 | save: function() { |
| 63 | return null; |
| 64 | } |
| 65 | }); |
| 66 | }( |
| 67 | window.wp.blocks, |
| 68 | window.wp.blockEditor, |
| 69 | window.wp.element, |
| 70 | window.wp.components, |
| 71 | window.wp.i18n |
| 72 | )); |