PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / grid / components / WidthControls.js
generateblocks / src / blocks / grid / components Last commit date
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