index.js
91 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { PanelBody, BaseControl, SelectControl } from '@wordpress/components'; |
| 3 | import { Component } from '@wordpress/element'; |
| 4 | import { createHigherOrderComponent, compose } from '@wordpress/compose'; |
| 5 | import { ColumnLayout } from '@vkblocks/components/column-layout'; |
| 6 | |
| 7 | export const setOptions = (name) => { |
| 8 | const options = { |
| 9 | 'vk-blocks/card': [ |
| 10 | { |
| 11 | value: 'card', |
| 12 | label: __('Card', 'vk-blocks'), |
| 13 | }, |
| 14 | { |
| 15 | value: 'card-noborder', |
| 16 | label: __('Card (No border)', 'vk-blocks'), |
| 17 | }, |
| 18 | { |
| 19 | value: 'card-imageRound', |
| 20 | label: __('Card (Image Round)', 'vk-blocks'), |
| 21 | }, |
| 22 | ], |
| 23 | 'vk-blocks/else': [ |
| 24 | { |
| 25 | value: 'card', |
| 26 | label: __('Card', 'vk-blocks'), |
| 27 | }, |
| 28 | { |
| 29 | value: 'card-noborder', |
| 30 | label: __('Card (No border)', 'vk-blocks'), |
| 31 | }, |
| 32 | { |
| 33 | value: 'card-intext', |
| 34 | label: __('Card (Intext)', 'vk-blocks'), |
| 35 | }, |
| 36 | { |
| 37 | value: 'card-horizontal', |
| 38 | label: __('Card (Horizontal)', 'vk-blocks'), |
| 39 | }, |
| 40 | { |
| 41 | value: 'media', |
| 42 | label: __('Media', 'vk-blocks'), |
| 43 | }, |
| 44 | { |
| 45 | value: 'postListText', |
| 46 | label: __('Text 1 Column', 'vk-blocks'), |
| 47 | }, |
| 48 | ], |
| 49 | }; |
| 50 | |
| 51 | if (name === 'vk-blocks/card') { |
| 52 | return options[name]; |
| 53 | } |
| 54 | return options['vk-blocks/else']; |
| 55 | }; |
| 56 | |
| 57 | const ColumnLayoutControlRaw = createHigherOrderComponent( |
| 58 | (WrappedComponent) => |
| 59 | class extends Component { |
| 60 | render() { |
| 61 | const { setAttributes, attributes } = this.props; |
| 62 | const { layout, name } = attributes; |
| 63 | return ( |
| 64 | <PanelBody |
| 65 | title={__('Display type and columns', 'vk-blocks')} |
| 66 | initialOpen={false} |
| 67 | > |
| 68 | <BaseControl |
| 69 | label={__('Display type', 'vk-blocks')} |
| 70 | id={'vk_column-displayType'} |
| 71 | > |
| 72 | <SelectControl |
| 73 | value={layout} |
| 74 | onChange={(value) => |
| 75 | setAttributes({ layout: value }) |
| 76 | } |
| 77 | options={setOptions(name)} |
| 78 | /> |
| 79 | </BaseControl> |
| 80 | <WrappedComponent {...this.props} /> |
| 81 | </PanelBody> |
| 82 | ); |
| 83 | } |
| 84 | }, |
| 85 | 'ColumnLayoutControlRaw' |
| 86 | ); |
| 87 | |
| 88 | export const ColumnLayoutControl = compose(ColumnLayoutControlRaw)( |
| 89 | ColumnLayout |
| 90 | ); |
| 91 |