PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.0
GenerateBlocks v1.4.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 / container / css / mobile.js
generateblocks / src / blocks / container / css Last commit date
desktop.js 5 years ago main.js 4 years ago mobile.js 4 years ago tablet-only.js 5 years ago tablet.js 4 years ago
mobile.js
168 lines
1 /* eslint-disable quotes */
2 import buildCSS from '../../../utils/build-css';
3 import valueWithUnit from '../../../utils/value-with-unit';
4
5 import {
6 Component,
7 } from '@wordpress/element';
8
9 import {
10 applyFilters,
11 } from '@wordpress/hooks';
12
13 export default class MobileCSS extends Component {
14 render() {
15 const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props );
16
17 const {
18 clientId,
19 } = this.props;
20
21 const {
22 uniqueId,
23 isGrid,
24 widthMobile,
25 autoWidthMobile,
26 flexGrowMobile,
27 flexShrinkMobile,
28 flexBasisMobile,
29 flexBasisUnit,
30 minHeightMobile,
31 minHeightUnitMobile,
32 paddingTopMobile,
33 paddingRightMobile,
34 paddingBottomMobile,
35 paddingLeftMobile,
36 paddingUnit,
37 marginTopMobile,
38 marginRightMobile,
39 marginBottomMobile,
40 marginLeftMobile,
41 marginUnit,
42 borderSizeTopMobile,
43 borderSizeRightMobile,
44 borderSizeBottomMobile,
45 borderSizeLeftMobile,
46 borderRadiusTopRightMobile,
47 borderRadiusBottomRightMobile,
48 borderRadiusBottomLeftMobile,
49 borderRadiusTopLeftMobile,
50 borderRadiusUnit,
51 verticalAlignmentMobile,
52 removeVerticalGapMobile,
53 alignmentMobile,
54 fontSizeMobile,
55 fontSizeUnit,
56 orderMobile,
57 shapeDividers,
58 bgImage,
59 bgOptions,
60 } = attributes;
61
62 let cssObj = [];
63 cssObj[ '.gb-container-' + uniqueId ] = [ {
64 'border-top-left-radius': valueWithUnit( borderRadiusTopLeftMobile, borderRadiusUnit ),
65 'border-top-right-radius': valueWithUnit( borderRadiusTopRightMobile, borderRadiusUnit ),
66 'border-bottom-right-radius': valueWithUnit( borderRadiusBottomRightMobile, borderRadiusUnit ),
67 'border-bottom-left-radius': valueWithUnit( borderRadiusBottomLeftMobile, borderRadiusUnit ),
68 'margin-top': valueWithUnit( marginTopMobile, marginUnit ),
69 'margin-right': valueWithUnit( marginRightMobile, marginUnit ),
70 'margin-bottom': valueWithUnit( marginBottomMobile, marginUnit ),
71 'margin-left': valueWithUnit( marginLeftMobile, marginUnit ),
72 'text-align': alignmentMobile,
73 'font-size': valueWithUnit( fontSizeMobile, fontSizeUnit ),
74 'min-height': valueWithUnit( minHeightMobile, minHeightUnitMobile ),
75 } ];
76
77 if ( borderSizeTopMobile || borderSizeRightMobile || borderSizeBottomMobile || borderSizeLeftMobile ) {
78 cssObj[ '.gb-container-' + uniqueId ].push( {
79 'border-top-width': valueWithUnit( borderSizeTopMobile, 'px' ),
80 'border-right-width': valueWithUnit( borderSizeRightMobile, 'px' ),
81 'border-bottom-width': valueWithUnit( borderSizeBottomMobile, 'px' ),
82 'border-left-width': valueWithUnit( borderSizeLeftMobile, 'px' ),
83 'border-style': 'solid',
84 } );
85 }
86
87 if ( 'inherit' !== verticalAlignmentMobile && minHeightMobile && ! isGrid ) {
88 cssObj[ '.gb-container-' + uniqueId ].push( {
89 'display': 'flex', // eslint-disable-line quote-props
90 'flex-direction': 'row',
91 'align-items': verticalAlignmentMobile,
92 } );
93 }
94
95 if ( isGrid && 'inherit' !== verticalAlignmentMobile ) {
96 cssObj[ '.gb-container-' + uniqueId ].push( {
97 'display': 'flex', // eslint-disable-line quote-props
98 'flex-direction': 'column',
99 'height': '100%', // eslint-disable-line quote-props
100 'justify-content': verticalAlignmentMobile,
101 } );
102 }
103
104 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ] = [ {
105 'padding-top': valueWithUnit( paddingTopMobile, paddingUnit ),
106 'padding-right': valueWithUnit( paddingRightMobile, paddingUnit ),
107 'padding-bottom': valueWithUnit( paddingBottomMobile, paddingUnit ),
108 'padding-left': valueWithUnit( paddingLeftMobile, paddingUnit ),
109 'width': minHeightMobile && ! isGrid ? '100%' : false, // eslint-disable-line quote-props
110 } ];
111
112 cssObj[ '.gb-grid-wrapper > div > .block-editor-block-list__layout > #block-' + clientId ] = [ {
113 width: ! autoWidthMobile ? valueWithUnit( widthMobile, '%' ) : 'auto',
114 'flex-grow': flexGrowMobile,
115 'flex-shrink': flexShrinkMobile,
116 'flex-basis': isNaN( flexBasisMobile ) ? flexBasisMobile : valueWithUnit( flexBasisMobile, flexBasisUnit ),
117 'order': orderMobile, // eslint-disable-line quote-props
118 } ];
119
120 if ( removeVerticalGapMobile ) {
121 cssObj[ '.block-editor-block-list__layout > #block-' + clientId ] = [ {
122 'margin-bottom': '0px !important',
123 } ];
124 }
125
126 if ( !! bgImage && 'pseudo-element' === bgOptions.selector ) {
127 cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ {
128 'border-top-left-radius': valueWithUnit( borderRadiusTopLeftMobile, borderRadiusUnit ),
129 'border-top-right-radius': valueWithUnit( borderRadiusTopRightMobile, borderRadiusUnit ),
130 'border-bottom-right-radius': valueWithUnit( borderRadiusBottomRightMobile, borderRadiusUnit ),
131 'border-bottom-left-radius': valueWithUnit( borderRadiusBottomLeftMobile, borderRadiusUnit ),
132 } ];
133 }
134
135 if ( shapeDividers.length ) {
136 shapeDividers.forEach( ( location, index ) => {
137 const shapeNumber = index + 1;
138
139 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ] = [ {
140 height: valueWithUnit( shapeDividers[ index ].heightMobile, 'px' ),
141 width: valueWithUnit( shapeDividers[ index ].widthMobile, '%' ),
142 } ];
143 } );
144 }
145
146 if ( !! bgImage && 'fixed' === bgOptions.attachment ) {
147 if ( 'element' === bgOptions.selector ) {
148 cssObj[ '.gb-container-' + uniqueId ].push( {
149 'background-attachment': 'initial',
150 } );
151 }
152
153 if ( 'pseudo-element' === bgOptions.selector ) {
154 cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ {
155 'background-attachment': 'initial',
156 } ];
157 }
158 }
159
160 cssObj = applyFilters( 'generateblocks.editor.mobileCSS', cssObj, this.props, 'container' );
161
162 return (
163 <style>{ buildCSS( cssObj ) }</style>
164 );
165 }
166 }
167 /* eslint-enable quotes */
168