PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.2
GenerateBlocks v2.0.2
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 / extend / inspector-control / controls / flex-child-panel / components / FlexControls.js
generateblocks / src / extend / inspector-control / controls / flex-child-panel / components Last commit date
FlexChildCSS.js 3 years ago FlexControls.js 3 years ago
FlexControls.js
115 lines
1 import {
2 BaseControl,
3 Button,
4 TextControl,
5 Tooltip,
6 } from '@wordpress/components';
7 import { __ } from '@wordpress/i18n';
8 import getResponsivePlaceholder from '../../../../../utils/get-responsive-placeholder';
9 import getIcon from '../../../../../utils/get-icon';
10 import getAttribute from '../../../../../utils/get-attribute';
11 import UnitControl from '../../../../../components/unit-control';
12 import getDeviceType from '../../../../../utils/get-device-type';
13
14 export default function FlexChildControls( props ) {
15 const {
16 attributes,
17 setAttributes,
18 } = props;
19
20 const deviceType = getDeviceType();
21
22 return (
23 <>
24 <BaseControl
25 className="gblocks-flex-controls"
26 label={ __( 'Flex', 'generateblocks' ) }
27 id="gblocks-flex-grow"
28 >
29 <div className="gblocks-utility-label">
30 <Tooltip text={ __( 'Reset', 'generateblocks' ) } position="top">
31 <Button
32 className="gblocks-reset-button"
33 icon={ getIcon( 'reset' ) }
34 onClick={ () => {
35 setAttributes( {
36 [ getAttribute( 'flexGrow', { attributes, deviceType }, true ) ]: '',
37 [ getAttribute( 'flexShrink', { attributes, deviceType }, true ) ]: '',
38 [ getAttribute( 'flexBasis', { attributes, deviceType }, true ) ]: '',
39 } );
40 } }
41 />
42 </Tooltip>
43 </div>
44
45 <div className="gblocks-flex-controls-inner">
46 <TextControl
47 help={ __( 'Grow', 'generateblocks' ) }
48 id="gblocks-flex-grow"
49 type={ 'number' }
50 value={ getAttribute( 'flexGrow', { attributes, deviceType } ) }
51 min="0"
52 step="1"
53 placeholder={ getResponsivePlaceholder( 'flexGrow', attributes, deviceType, '0' ) }
54 onChange={ ( value ) => {
55 setAttributes( {
56 [ getAttribute( 'flexGrow', { attributes, deviceType }, true ) ]: value,
57 } );
58 } }
59 onBlur={ () => {
60 if ( '' !== getAttribute( 'flexGrow', { attributes, deviceType } ) ) {
61 setAttributes( {
62 [ getAttribute( 'flexGrow', { attributes, deviceType }, true ) ]: parseFloat( getAttribute( 'flexGrow', { attributes, deviceType } ) ),
63 } );
64 }
65 } }
66 onClick={ ( e ) => {
67 // Make sure onBlur fires in Firefox.
68 e.currentTarget.focus();
69 } }
70 />
71
72 <TextControl
73 help={ __( 'Shrink', 'generateblocks' ) }
74 id="gblocks-flex-shrink"
75 type={ 'number' }
76 value={ getAttribute( 'flexShrink', { attributes, deviceType } ) }
77 min="0"
78 step="1"
79 placeholder={ getResponsivePlaceholder( 'flexShrink', attributes, deviceType, '1' ) }
80 onChange={ ( value ) => {
81 setAttributes( {
82 [ getAttribute( 'flexShrink', { attributes, deviceType }, true ) ]: value,
83 } );
84 } }
85 onBlur={ () => {
86 if ( '' !== getAttribute( 'flexShrink', { attributes, deviceType } ) ) {
87 setAttributes( {
88 [ getAttribute( 'flexShrink', { attributes, deviceType }, true ) ]: parseFloat( getAttribute( 'flexShrink', { attributes, deviceType } ) ),
89 } );
90 }
91 } }
92 onClick={ ( e ) => {
93 // Make sure onBlur fires in Firefox.
94 e.currentTarget.focus();
95 } }
96 />
97
98 <div className="gblocks-flex-basis-wrapper">
99 <UnitControl
100 help={ __( 'Basis', 'generateblocks' ) }
101 value={ getAttribute( 'flexBasis', { attributes, deviceType } ) }
102 placeholder={ getResponsivePlaceholder( 'flexBasis', attributes, deviceType ) }
103 onChange={ ( value ) => {
104 setAttributes( {
105 [ getAttribute( 'flexBasis', { attributes, deviceType }, true ) ]: value,
106 } );
107 } }
108 />
109 </div>
110 </div>
111 </BaseControl>
112 </>
113 );
114 }
115