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