PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.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 4 years ago main.js 2 years ago mobile.js 2 years ago tablet-only.js 4 years ago tablet.js 2 years ago
mobile.js
154 lines
1 /* eslint-disable quotes */
2 import buildCSS from '../../../utils/build-css';
3 import valueWithUnit from '../../../utils/value-with-unit';
4 import LayoutCSS from '../../../extend/inspector-control/controls/layout/components/LayoutCSS';
5 import FlexChildCSS from '../../../extend/inspector-control/controls/flex-child-panel/components/FlexChildCSS';
6 import SpacingCSS from '../../../extend/inspector-control/controls/spacing/components/SpacingCSS';
7 import TypographyCSS from '../../../extend/inspector-control/controls/typography/components/TypographyCSS';
8 import BorderCSS from '../../../extend/inspector-control/controls/borders/BorderCSS';
9
10 import {
11 Component,
12 } from '@wordpress/element';
13
14 import {
15 applyFilters,
16 } from '@wordpress/hooks';
17 import sizingValue from '../../../utils/sizingValue';
18 import SizingCSS from '../../../extend/inspector-control/controls/sizing/components/SizingCSS';
19
20 export default class MobileCSS extends Component {
21 render() {
22 const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props );
23
24 const {
25 uniqueId,
26 isGrid,
27 flexGrowMobile,
28 flexShrinkMobile,
29 flexBasisMobile,
30 verticalAlignmentMobile,
31 removeVerticalGapMobile,
32 orderMobile,
33 shapeDividers,
34 bgImage,
35 bgOptions,
36 gridId,
37 useInnerContainer,
38 sizing,
39 } = attributes;
40
41 const {
42 paddingTopMobile,
43 paddingRightMobile,
44 paddingBottomMobile,
45 paddingLeftMobile,
46 } = attributes.spacing;
47
48 const {
49 borderTopLeftRadiusMobile,
50 borderTopRightRadiusMobile,
51 borderBottomRightRadiusMobile,
52 borderBottomLeftRadiusMobile,
53 } = attributes.borders;
54
55 let cssObj = [];
56
57 TypographyCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes.typography, 'Mobile' );
58 SpacingCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, { ...attributes.spacing, useInnerContainer }, 'Mobile' );
59 BorderCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes.borders, 'Mobile' );
60 SizingCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' );
61 LayoutCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' );
62 FlexChildCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' );
63
64 if ( useInnerContainer ) {
65 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ] = [ {
66 'padding-top': paddingTopMobile,
67 'padding-right': paddingRightMobile,
68 'padding-bottom': paddingBottomMobile,
69 'padding-left': paddingLeftMobile,
70 'width': sizingValue( 'minHeightMobile', sizing ) && ! isGrid ? '100%' : false, // eslint-disable-line quote-props
71 } ];
72
73 if ( 'inherit' !== verticalAlignmentMobile && sizingValue( 'minHeightMobile', sizing ) && ! isGrid ) {
74 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
75 'display': 'flex', // eslint-disable-line quote-props
76 'flex-direction': 'row',
77 'align-items': verticalAlignmentMobile,
78 } );
79 }
80
81 if ( isGrid && 'inherit' !== verticalAlignmentMobile ) {
82 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
83 'display': 'flex', // eslint-disable-line quote-props
84 'flex-direction': 'column',
85 'height': '100%', // eslint-disable-line quote-props
86 'justify-content': verticalAlignmentMobile,
87 } );
88 }
89 }
90
91 if ( isGrid ) {
92 const gridColumnSelectors = [
93 '.gb-post-template-' + gridId + ' > .gb-post-template-wrapper > .block-editor-inner-blocks',
94 '.gb-grid-wrapper > .block-editor-inner-blocks > .block-editor-block-list__layout > .gb-grid-column-' + uniqueId,
95 ];
96
97 cssObj[ gridColumnSelectors.join( ',' ) ] = [ {
98 width: sizingValue( 'widthMobile', sizing ),
99 'flex-grow': flexGrowMobile,
100 'flex-shrink': flexShrinkMobile,
101 'flex-basis': flexBasisMobile,
102 'order': orderMobile, // eslint-disable-line quote-props
103 } ];
104 }
105
106 if ( removeVerticalGapMobile ) {
107 cssObj[ '.gb-grid-column-' + uniqueId ] = [ {
108 'margin-bottom': '0px !important',
109 } ];
110 }
111
112 if ( !! bgImage && 'pseudo-element' === bgOptions.selector ) {
113 cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ {
114 'border-top-left-radius': borderTopLeftRadiusMobile,
115 'border-top-right-radius': borderTopRightRadiusMobile,
116 'border-bottom-right-radius': borderBottomRightRadiusMobile,
117 'border-bottom-left-radius': borderBottomLeftRadiusMobile,
118 } ];
119 }
120
121 if ( shapeDividers.length ) {
122 shapeDividers.forEach( ( location, index ) => {
123 const shapeNumber = index + 1;
124
125 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ] = [ {
126 height: valueWithUnit( shapeDividers[ index ].heightMobile, 'px' ),
127 width: valueWithUnit( shapeDividers[ index ].widthMobile, '%' ),
128 } ];
129 } );
130 }
131
132 if ( !! bgImage && 'fixed' === bgOptions.attachment ) {
133 if ( 'element' === bgOptions.selector ) {
134 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
135 'background-attachment': 'initial',
136 } );
137 }
138
139 if ( 'pseudo-element' === bgOptions.selector ) {
140 cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ {
141 'background-attachment': 'initial',
142 } ];
143 }
144 }
145
146 cssObj = applyFilters( 'generateblocks.editor.mobileCSS', cssObj, this.props, 'container' );
147
148 return (
149 <style>{ buildCSS( cssObj ) }</style>
150 );
151 }
152 }
153 /* eslint-enable quotes */
154