BlockControls.js
4 years ago
ComponentCSS.js
1 year ago
InspectorAdvancedControls.js
2 years ago
InspectorControls.js
2 years ago
LayoutSelector.js
3 years ago
WidthControls.js
2 years ago
WidthControls.js
68 lines
| 1 | import { Fragment } from '@wordpress/element'; |
| 2 | import { addFilter } from '@wordpress/hooks'; |
| 3 | import { __ } from '@wordpress/i18n'; |
| 4 | import { BaseControl, ButtonGroup, Button } from '@wordpress/components'; |
| 5 | import getAttribute from '../../../utils/get-attribute'; |
| 6 | import getDeviceType from '../../../utils/get-device-type'; |
| 7 | |
| 8 | function GridItemSettings( content, props ) { |
| 9 | const { attributes, setAttributes, name } = props; |
| 10 | const { isGrid, sizing } = attributes; |
| 11 | |
| 12 | if ( 'generateblocks/container' !== name || ! isGrid ) { |
| 13 | return content; |
| 14 | } |
| 15 | |
| 16 | const device = getDeviceType(); |
| 17 | |
| 18 | function getValue( attributeName ) { |
| 19 | return sizing && sizing[ getAttribute( attributeName, { attributes, deviceType: device }, true ) ] |
| 20 | ? sizing[ getAttribute( attributeName, { attributes, deviceType: device }, true ) ] |
| 21 | : ''; |
| 22 | } |
| 23 | |
| 24 | const widths = [ |
| 25 | { value: '25%', label: '25' }, |
| 26 | { value: '33.33%', label: '33' }, |
| 27 | { value: '50%', label: '50' }, |
| 28 | { value: '66.66%', label: '66' }, |
| 29 | { value: '75%', label: '75' }, |
| 30 | { value: '100%', label: '100' }, |
| 31 | ]; |
| 32 | |
| 33 | return ( |
| 34 | <> |
| 35 | <BaseControl |
| 36 | id="gridItemWidth" |
| 37 | label={ __( 'Grid Item Width (%)', 'generateblocks' ) } |
| 38 | help={ __( 'More values can be set in the Sizing panel.', 'generateblocks' ) } |
| 39 | > |
| 40 | <ButtonGroup id="gridItemWidth" className="gblocks-flex-button-group"> |
| 41 | { |
| 42 | Object.values( widths ).map( ( width, index ) => { |
| 43 | return ( |
| 44 | <Fragment key={ 'gridItemWidth' + index }> |
| 45 | <Button |
| 46 | isPrimary={ width.value === getValue( 'width' ) } |
| 47 | onClick={ () => setAttributes( { sizing: { [ getAttribute( 'width', { attributes, deviceType: device }, true ) ]: width.value } } ) } |
| 48 | > |
| 49 | { width.label } |
| 50 | </Button> |
| 51 | </Fragment> |
| 52 | ); |
| 53 | } ) |
| 54 | } |
| 55 | </ButtonGroup> |
| 56 | </BaseControl> |
| 57 | |
| 58 | { content } |
| 59 | </> |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | addFilter( |
| 64 | 'generateblocks.editor.settingsPanel', |
| 65 | 'generateblocks/grid/gridItemSettings', |
| 66 | GridItemSettings |
| 67 | ); |
| 68 |