PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.2
GenerateBlocks v1.8.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 / spacing / index.js
generateblocks / src / extend / inspector-control / controls / spacing Last commit date
components 2 years ago attributes.js 2 years ago index.js 2 years ago
index.js
127 lines
1 import { __ } from '@wordpress/i18n';
2 import PanelArea from '../../../../components/panel-area';
3 import getIcon from '../../../../utils/get-icon';
4 import { useContext } from '@wordpress/element';
5 import ControlsContext from '../../../../block-context';
6 import DeviceControls from './components/device-controls';
7 import getDeviceType from '../../../../utils/get-device-type';
8 import useDeviceAttributes from '../../../../hooks/useDeviceAttributes';
9 import getResponsivePlaceholder from '../../../../utils/get-responsive-placeholder';
10 import DimensionsControl from '../../../../components/dimensions';
11
12 export default function Spacing( { attributes, setAttributes, computedStyles } ) {
13 const device = getDeviceType();
14 const { id, supports: { spacing } } = useContext( ControlsContext );
15 const [ deviceAttributes, setDeviceAttributes ] = useDeviceAttributes( attributes, setAttributes );
16
17 const {
18 inlineWidth,
19 inlineWidthTablet,
20 inlineWidthMobile,
21 stack,
22 stackTablet,
23 stackMobile,
24 fillHorizontalSpace,
25 fillHorizontalSpaceTablet,
26 fillHorizontalSpaceMobile,
27 } = attributes;
28
29 const paddingAttributes = [ 'paddingTop', 'paddingLeft', 'paddingRight', 'paddingBottom' ];
30 const marginAttributes = [ 'marginTop', 'marginLeft', 'marginRight', 'marginBottom' ];
31
32 return (
33 <PanelArea
34 title={ __( 'Spacing', 'generateblocks' ) }
35 initialOpen={ false }
36 icon={ getIcon( 'spacing' ) }
37 className="gblocks-panel-label"
38 id={ `${ id }Spacing` }
39 >
40 { spacing.padding &&
41 <DimensionsControl
42 label={ __( 'Padding', 'generateblocks' ) }
43 attributeNames={ paddingAttributes }
44 values={ deviceAttributes.spacing }
45 placeholders={ paddingAttributes.reduce( ( o, key ) => (
46 { ...o, [ key ]: getResponsivePlaceholder( key, attributes.spacing, device, '' ) }
47 ), {} ) }
48 onChange={ ( values ) => setDeviceAttributes( values, 'spacing' ) }
49 />
50 }
51
52 { spacing.margin &&
53 <DimensionsControl
54 label={ __( 'Margin', 'generateblocks' ) }
55 attributeNames={ marginAttributes }
56 values={ deviceAttributes.spacing }
57 placeholders={ marginAttributes.reduce( ( o, key ) => (
58 { ...o, [ key ]: getResponsivePlaceholder( key, attributes.spacing, device, computedStyles[ key ] ) }
59 ), {} ) }
60 onChange={ ( values ) => setDeviceAttributes( values, 'spacing' ) }
61 />
62 }
63
64 { 'Desktop' === device &&
65 <>
66 <DeviceControls
67 inlineWidth={ !! inlineWidth }
68 onChangeInlineWidth={ ( checked ) => setAttributes( { inlineWidth: checked } ) }
69 stack={ !! stack }
70 onChangeStack={ ( value ) => {
71 setAttributes( {
72 stack: value,
73 stackTablet: !! value && ! stackTablet ? value : stackTablet,
74 stackMobile: !! value && ! stackMobile ? value : stackMobile,
75 } );
76 } }
77 fill={ !! fillHorizontalSpace }
78 onFillChange={ ( value ) => {
79 setAttributes( {
80 fillHorizontalSpace: value,
81 fillHorizontalSpaceTablet: !! value && ! fillHorizontalSpaceTablet ? value : fillHorizontalSpaceTablet,
82 fillHorizontalSpaceMobile: !! value && ! fillHorizontalSpaceMobile ? value : fillHorizontalSpaceMobile,
83 } );
84 } }
85 />
86 </>
87 }
88
89 { 'Tablet' === device &&
90 <>
91 <DeviceControls
92 inlineWidth={ !! inlineWidthTablet }
93 onChangeInlineWidth={ ( checked ) => setAttributes( { inlineWidthTablet: checked } ) }
94 stack={ !! stackTablet }
95 onChangeStack={ ( value ) => {
96 setAttributes( {
97 stackTablet: value,
98 stackMobile: !! value && ! stackMobile ? value : stackMobile,
99 } );
100 } }
101 fill={ !! fillHorizontalSpaceTablet }
102 onFillChange={ ( value ) => {
103 setAttributes( {
104 fillHorizontalSpaceTablet: value,
105 fillHorizontalSpaceMobile: !! value && ! fillHorizontalSpaceMobile ? value : fillHorizontalSpaceMobile,
106 } );
107 } }
108 />
109 </>
110 }
111
112 { 'Mobile' === device &&
113 <>
114 <DeviceControls
115 inlineWidth={ !! inlineWidthMobile }
116 onChangeInlineWidth={ ( checked ) => setAttributes( { inlineWidthMobile: checked } ) }
117 stack={ !! stackMobile }
118 onChangeStack={ ( value ) => setAttributes( { stackMobile: value } ) }
119 fill={ !! fillHorizontalSpaceMobile }
120 onFillChange={ ( value ) => setAttributes( { fillHorizontalSpaceMobile: value } ) }
121 />
122 </>
123 }
124 </PanelArea>
125 );
126 }
127