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