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