BlockControls.js
4 years ago
ComponentCSS.js
4 years ago
InspectorAdvancedControls.js
4 years ago
InspectorControls.js
4 years ago
LayoutSelector.js
4 years ago
InspectorControls.js
193 lines
| 1 | import PanelArea from '../../../components/panel-area'; |
| 2 | import { Fragment } from '@wordpress/element'; |
| 3 | import { __ } from '@wordpress/i18n'; |
| 4 | import { SelectControl } from '@wordpress/components'; |
| 5 | import getIcon from '../../../utils/get-icon'; |
| 6 | import { applyFilters } from '@wordpress/hooks'; |
| 7 | import { InspectorControls } from '@wordpress/block-editor'; |
| 8 | import NumberControl from '../../../components/number-control'; |
| 9 | |
| 10 | export default ( props ) => { |
| 11 | const { |
| 12 | attributes, |
| 13 | state, |
| 14 | deviceType, |
| 15 | setAttributes, |
| 16 | } = props; |
| 17 | |
| 18 | const { |
| 19 | verticalAlignment, |
| 20 | verticalAlignmentTablet, |
| 21 | verticalAlignmentMobile, |
| 22 | horizontalAlignment, |
| 23 | horizontalAlignmentTablet, |
| 24 | horizontalAlignmentMobile, |
| 25 | isQueryLoop, |
| 26 | } = attributes; |
| 27 | |
| 28 | return ( |
| 29 | <InspectorControls> |
| 30 | <PanelArea |
| 31 | { ...props } |
| 32 | title={ __( 'Layout', 'generateblocks' ) } |
| 33 | initialOpen={ ! isQueryLoop } |
| 34 | icon={ getIcon( 'layout' ) } |
| 35 | className={ 'gblocks-panel-label' } |
| 36 | id={ 'gridLayout' } |
| 37 | state={ state } |
| 38 | > |
| 39 | <NumberControl |
| 40 | { ...props } |
| 41 | label={ __( 'Horizontal Gap', 'generateblocks' ) } |
| 42 | attributeName="horizontalGap" |
| 43 | unit="px" |
| 44 | units={ [ 'px' ] } |
| 45 | device={ deviceType } |
| 46 | presets={ |
| 47 | [ |
| 48 | { |
| 49 | unit: 'px', |
| 50 | data: [ 20, 40, 60, 80 ], |
| 51 | }, |
| 52 | ] |
| 53 | } |
| 54 | /> |
| 55 | |
| 56 | <NumberControl |
| 57 | { ...props } |
| 58 | label={ __( 'Vertical Gap', 'generateblocks' ) } |
| 59 | attributeName="verticalGap" |
| 60 | unit="px" |
| 61 | units={ [ 'px' ] } |
| 62 | device={ deviceType } |
| 63 | presets={ |
| 64 | [ |
| 65 | { |
| 66 | unit: 'px', |
| 67 | data: [ 20, 40, 60, 80 ], |
| 68 | }, |
| 69 | ] |
| 70 | } |
| 71 | /> |
| 72 | |
| 73 | { 'Desktop' === deviceType && ( |
| 74 | <Fragment> |
| 75 | <SelectControl |
| 76 | label={ __( 'Vertical Alignment', 'generateblocks' ) } |
| 77 | value={ verticalAlignment } |
| 78 | help={ __( 'Align grid items. Removes same height columns and overrides grid item content alignment.', 'generateblocks' ) } |
| 79 | options={ [ |
| 80 | { label: __( 'Default', 'generateblocks' ), value: '' }, |
| 81 | { label: __( 'Top', 'generateblocks' ), value: 'flex-start' }, |
| 82 | { label: __( 'Center', 'generateblocks' ), value: 'center' }, |
| 83 | { label: __( 'Bottom', 'generateblocks' ), value: 'flex-end' }, |
| 84 | ] } |
| 85 | onChange={ ( value ) => { |
| 86 | setAttributes( { |
| 87 | verticalAlignment: value, |
| 88 | } ); |
| 89 | } } |
| 90 | /> |
| 91 | |
| 92 | <SelectControl |
| 93 | label={ __( 'Horizontal Alignment', 'generateblocks' ) } |
| 94 | value={ horizontalAlignment } |
| 95 | options={ [ |
| 96 | { label: __( 'Default', 'generateblocks' ), value: '' }, |
| 97 | { label: __( 'Left', 'generateblocks' ), value: 'flex-start' }, |
| 98 | { label: __( 'Center', 'generateblocks' ), value: 'center' }, |
| 99 | { label: __( 'Right', 'generateblocks' ), value: 'flex-end' }, |
| 100 | ] } |
| 101 | onChange={ ( value ) => { |
| 102 | setAttributes( { |
| 103 | horizontalAlignment: value, |
| 104 | } ); |
| 105 | } } |
| 106 | /> |
| 107 | </Fragment> |
| 108 | ) } |
| 109 | |
| 110 | { 'Tablet' === deviceType && ( |
| 111 | <Fragment> |
| 112 | <SelectControl |
| 113 | label={ __( 'Vertical Alignment', 'generateblocks' ) } |
| 114 | help={ __( 'Align grid items. Removes same height columns and overrides grid item content alignment.', 'generateblocks' ) } |
| 115 | value={ verticalAlignmentTablet } |
| 116 | options={ [ |
| 117 | { label: __( 'Inherit', 'generateblocks' ), value: 'inherit' }, |
| 118 | { label: __( 'Default', 'generateblocks' ), value: '' }, |
| 119 | { label: __( 'Top', 'generateblocks' ), value: 'flex-start' }, |
| 120 | { label: __( 'Center', 'generateblocks' ), value: 'center' }, |
| 121 | { label: __( 'Bottom', 'generateblocks' ), value: 'flex-end' }, |
| 122 | ] } |
| 123 | onChange={ ( value ) => { |
| 124 | setAttributes( { |
| 125 | verticalAlignmentTablet: value, |
| 126 | } ); |
| 127 | } } |
| 128 | /> |
| 129 | |
| 130 | <SelectControl |
| 131 | label={ __( 'Horizontal Alignment', 'generateblocks' ) } |
| 132 | value={ horizontalAlignmentTablet } |
| 133 | options={ [ |
| 134 | { label: __( 'Inherit', 'generateblocks' ), value: 'inherit' }, |
| 135 | { label: __( 'Default', 'generateblocks' ), value: '' }, |
| 136 | { label: __( 'Left', 'generateblocks' ), value: 'flex-start' }, |
| 137 | { label: __( 'Center', 'generateblocks' ), value: 'center' }, |
| 138 | { label: __( 'Right', 'generateblocks' ), value: 'flex-end' }, |
| 139 | ] } |
| 140 | onChange={ ( value ) => { |
| 141 | setAttributes( { |
| 142 | horizontalAlignmentTablet: value, |
| 143 | } ); |
| 144 | } } |
| 145 | /> |
| 146 | </Fragment> |
| 147 | ) } |
| 148 | |
| 149 | { 'Mobile' === deviceType && ( |
| 150 | <Fragment> |
| 151 | <SelectControl |
| 152 | label={ __( 'Vertical Alignment', 'generateblocks' ) } |
| 153 | help={ __( 'Align grid items. Removes same height columns and overrides grid item content alignment.', 'generateblocks' ) } |
| 154 | value={ verticalAlignmentMobile } |
| 155 | options={ [ |
| 156 | { label: __( 'Inherit', 'generateblocks' ), value: 'inherit' }, |
| 157 | { label: __( 'Default', 'generateblocks' ), value: '' }, |
| 158 | { label: __( 'Top', 'generateblocks' ), value: 'flex-start' }, |
| 159 | { label: __( 'Center', 'generateblocks' ), value: 'center' }, |
| 160 | { label: __( 'Bottom', 'generateblocks' ), value: 'flex-end' }, |
| 161 | ] } |
| 162 | onChange={ ( value ) => { |
| 163 | setAttributes( { |
| 164 | verticalAlignmentMobile: value, |
| 165 | } ); |
| 166 | } } |
| 167 | /> |
| 168 | |
| 169 | <SelectControl |
| 170 | label={ __( 'Horizontal Alignment', 'generateblocks' ) } |
| 171 | value={ horizontalAlignmentMobile } |
| 172 | options={ [ |
| 173 | { label: __( 'Inherit', 'generateblocks' ), value: 'inherit' }, |
| 174 | { label: __( 'Default', 'generateblocks' ), value: '' }, |
| 175 | { label: __( 'Left', 'generateblocks' ), value: 'flex-start' }, |
| 176 | { label: __( 'Center', 'generateblocks' ), value: 'center' }, |
| 177 | { label: __( 'Right', 'generateblocks' ), value: 'flex-end' }, |
| 178 | ] } |
| 179 | onChange={ ( value ) => { |
| 180 | setAttributes( { |
| 181 | horizontalAlignmentMobile: value, |
| 182 | } ); |
| 183 | } } |
| 184 | /> |
| 185 | </Fragment> |
| 186 | ) } |
| 187 | |
| 188 | { applyFilters( 'generateblocks.editor.controls', '', 'gridLayout', props, state ) } |
| 189 | </PanelArea> |
| 190 | </InspectorControls> |
| 191 | ); |
| 192 | }; |
| 193 |