PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.3.4
GenerateBlocks v1.3.4
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 / main.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
main.js
361 lines
1 /* eslint-disable quotes */
2 import buildCSS from '../../../utils/build-css';
3 import shorthandCSS from '../../../utils/shorthand-css';
4 import hexToRGBA from '../../../utils/hex-to-rgba';
5 import valueWithUnit from '../../../utils/value-with-unit';
6 import getBackgroundImageCSS from '../../../utils/get-background-image';
7
8 import {
9 Component,
10 } from '@wordpress/element';
11
12 import {
13 applyFilters,
14 } from '@wordpress/hooks';
15
16 export default class MainCSS extends Component {
17 render() {
18 const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props );
19
20 const {
21 clientId,
22 } = this.props;
23
24 const {
25 uniqueId,
26 isGrid,
27 width,
28 outerContainer,
29 innerContainer,
30 containerWidth,
31 minHeight,
32 minHeightUnit,
33 paddingTop,
34 paddingRight,
35 paddingBottom,
36 paddingLeft,
37 paddingUnit,
38 marginTop,
39 marginRight,
40 marginBottom,
41 marginLeft,
42 marginUnit,
43 borderSizeTop,
44 borderSizeRight,
45 borderSizeBottom,
46 borderSizeLeft,
47 borderRadiusTopRight,
48 borderRadiusBottomRight,
49 borderRadiusBottomLeft,
50 borderRadiusTopLeft,
51 borderRadiusUnit,
52 borderColor,
53 borderColorOpacity,
54 backgroundColor,
55 backgroundColorOpacity,
56 gradient,
57 gradientSelector,
58 textColor,
59 linkColor,
60 linkColorHover,
61 bgImage,
62 bgOptions,
63 verticalAlignment,
64 zindex,
65 innerZindex,
66 alignment,
67 fontFamily,
68 fontFamilyFallback,
69 fontWeight,
70 fontSize,
71 fontSizeUnit,
72 textTransform,
73 shapeDividers,
74 } = attributes;
75
76 let containerWidthPreview = containerWidth;
77
78 if ( ! containerWidthPreview ) {
79 containerWidthPreview = generateBlocksDefaults.container.containerWidth;
80 }
81
82 let fontFamilyFallbackValue = '';
83
84 if ( fontFamily && fontFamilyFallback ) {
85 fontFamilyFallbackValue = ', ' + fontFamilyFallback;
86 }
87
88 const hasBgImage = !! bgImage;
89 const backgroundImageValue = getBackgroundImageCSS( 'image', this.props );
90 const gradientValue = getBackgroundImageCSS( 'gradient', this.props );
91
92 let innerZIndexValue = innerZindex;
93
94 let cssObj = [];
95 cssObj[ '.gb-container-' + uniqueId ] = [ {
96 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
97 'color': textColor, // eslint-disable-line quote-props
98 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ),
99 'margin': shorthandCSS( marginTop, marginRight, marginBottom, marginLeft, marginUnit ), // eslint-disable-line quote-props
100 'z-index': zindex,
101 'text-align': alignment,
102 'font-family': fontFamily + fontFamilyFallbackValue,
103 'font-weight': fontWeight,
104 'text-transform': textTransform,
105 'font-size': valueWithUnit( fontSize, fontSizeUnit ),
106 'min-height': valueWithUnit( minHeight, minHeightUnit ),
107 'border-color': hexToRGBA( borderColor, borderColorOpacity ),
108 } ];
109
110 if ( hasBgImage && 'element' === bgOptions.selector && backgroundImageValue ) {
111 cssObj[ '.gb-container-' + uniqueId ].push( {
112 'background-image': backgroundImageValue,
113 'background-size': bgOptions.size,
114 'background-position': bgOptions.position,
115 'background-repeat': bgOptions.repeat,
116 'background-attachment': bgOptions.attachment,
117 } );
118 } else if ( gradient && 'element' === gradientSelector ) {
119 cssObj[ '.gb-container-' + uniqueId ].push( {
120 'background-image': gradientValue,
121 } );
122 }
123
124 if (
125 ( hasBgImage && 'pseudo-element' === bgOptions.selector ) ||
126 zindex ||
127 ( gradient && 'pseudo-element' === gradientSelector )
128 ) {
129 cssObj[ '.gb-container-' + uniqueId ].push( {
130 'position': 'relative', // eslint-disable-line quote-props
131 } );
132 }
133
134 if (
135 ( hasBgImage && 'pseudo-element' === bgOptions.selector ) ||
136 ( gradient && 'pseudo-element' === gradientSelector )
137 ) {
138 cssObj[ '.gb-container-' + uniqueId ].push( {
139 'overflow': 'hidden', // eslint-disable-line quote-props
140 } );
141
142 cssObj[ '.gb-container-' + uniqueId + ' .block-list-appender' ] = [ {
143 'z-index': 10,
144 } ];
145
146 if ( ! innerZIndexValue ) {
147 innerZIndexValue = 1;
148 }
149 }
150
151 cssObj[ `.editor-styles-wrapper .gb-container-` + uniqueId + ` h1,
152 .editor-styles-wrapper .gb-container-` + uniqueId + ` h2,
153 .editor-styles-wrapper .gb-container-` + uniqueId + ` h3,
154 .editor-styles-wrapper .gb-container-` + uniqueId + ` h4,
155 .editor-styles-wrapper .gb-container-` + uniqueId + ` h5,
156 .editor-styles-wrapper .gb-container-` + uniqueId + ` h6` ] = [ {
157 'color': textColor, // eslint-disable-line quote-props
158 } ];
159
160 if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) {
161 cssObj[ '.gb-container-' + uniqueId ].push( {
162 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ),
163 'border-style': 'solid',
164 } );
165 }
166
167 if ( minHeight && ! isGrid ) {
168 cssObj[ '.gb-container-' + uniqueId ].push( {
169 'display': 'flex', // eslint-disable-line quote-props
170 'flex-direction': 'row',
171 'align-items': verticalAlignment,
172 } );
173 }
174
175 if ( isGrid ) {
176 cssObj[ '.gb-container-' + uniqueId ].push( {
177 'display': 'flex', // eslint-disable-line quote-props
178 'flex-direction': 'column',
179 'height': '100%', // eslint-disable-line quote-props
180 'justify-content': verticalAlignment,
181 } );
182
183 cssObj[ '.block-editor-block-list__layout > #block-' + clientId ] = [ {
184 'height': '100%', // eslint-disable-line quote-props
185 } ];
186 }
187
188 if ( hasBgImage && 'pseudo-element' === bgOptions.selector ) {
189 cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ {
190 'content': '""', // eslint-disable-line quote-props
191 'background-image': backgroundImageValue,
192 'background-repeat': bgOptions.repeat,
193 'background-position': bgOptions.position,
194 'background-size': bgOptions.size,
195 'background-attachment': bgOptions.attachment,
196 'z-index': '0',
197 'position': 'absolute', // eslint-disable-line quote-props
198 'top': '0', // eslint-disable-line quote-props
199 'right': '0', // eslint-disable-line quote-props
200 'bottom': '0', // eslint-disable-line quote-props
201 'left': '0', // eslint-disable-line quote-props
202 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ),
203 } ];
204
205 if ( typeof bgOptions.opacity !== 'undefined' && 1 !== bgOptions.opacity ) {
206 cssObj[ '.gb-container-' + uniqueId + ':before' ].push( {
207 'opacity': bgOptions.opacity, // eslint-disable-line quote-props
208 } );
209 }
210 }
211
212 if ( gradient && 'pseudo-element' === gradientSelector ) {
213 cssObj[ '.gb-container-' + uniqueId + ':after' ] = [ {
214 'content': '""', // eslint-disable-line quote-props
215 'background-image': gradientValue,
216 'z-index': '0',
217 'position': 'absolute', // eslint-disable-line quote-props
218 'top': '0', // eslint-disable-line quote-props
219 'right': '0', // eslint-disable-line quote-props
220 'bottom': '0', // eslint-disable-line quote-props
221 'left': '0', // eslint-disable-line quote-props
222 } ];
223 }
224
225 cssObj[ '.gb-container-' + uniqueId + ' a, .gb-container-' + uniqueId + ' a:visited' ] = [ {
226 'color': linkColor, // eslint-disable-line quote-props
227 } ];
228
229 cssObj[ '.gb-container-' + uniqueId + ' a:hover' ] = [ {
230 'color': linkColorHover, // eslint-disable-line quote-props
231 } ];
232
233 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ] = [ {
234 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props
235 'width': minHeight && ! isGrid ? '100%' : false, // eslint-disable-line quote-props
236 } ];
237
238 if ( innerZIndexValue || 0 === innerZIndexValue ) {
239 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ].push( {
240 'z-index': innerZIndexValue,
241 position: 'relative',
242 } );
243 }
244
245 if ( 'contained' === innerContainer && ! isGrid ) {
246 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ].push( {
247 'max-width': valueWithUnit( containerWidthPreview, 'px' ),
248 'margin-left': 'auto',
249 'margin-right': 'auto',
250 } );
251 }
252
253 cssObj[ '.gb-grid-wrapper > div > .block-editor-block-list__layout > #block-' + clientId ] = [ {
254 'width': valueWithUnit( width, '%' ), // eslint-disable-line quote-props
255 'display': 'flex', // eslint-disable-line quote-props
256 'flex-direction': 'column',
257 'margin-left': '0px',
258 'margin-right': '0px',
259 } ];
260
261 cssObj[ '.block-editor-block-list__layout > #block-' + clientId ] = [ {
262 'max-width': 'contained' === outerContainer && ! isGrid ? valueWithUnit( containerWidthPreview, 'px' ) : false,
263 } ];
264
265 cssObj[ `.gb-grid-wrapper > div > .block-editor-block-list__layout > #block-` + clientId + ` > .block-editor-block-list__block-edit,
266 .gb-grid-wrapper > div > .block-editor-block-list__layout > #block-` + clientId + ` > .block-editor-block-list__block-edit > [data-block="` + clientId + `"]` ] = [ {
267 'height': '100%', // eslint-disable-line quote-props
268 } ];
269
270 cssObj[ `#block-` + clientId + `:not(.has-child-selected):not(.is-selected) .block-list-appender:not(:first-child),
271 #block-` + clientId + `:not(.has-child-selected):not(.is-selected) .block-editor-block-list__layout > div:not(:first-child) > .block-list-appender` ] = [ {
272 'display': 'none', // eslint-disable-line quote-props
273 } ];
274
275 if ( shapeDividers.length ) {
276 cssObj[ '.gb-container-' + uniqueId ].push( {
277 position: 'relative',
278 } );
279
280 cssObj[ '.gb-container-' + uniqueId + ' .block-list-appender' ] = [ {
281 position: 'relative',
282 'z-index': 100,
283 } ];
284
285 shapeDividers.forEach( ( location, index ) => {
286 const shapeTransforms = [];
287 const shapeNumber = index + 1;
288
289 if ( 'top' === shapeDividers[ index ].location ) {
290 shapeTransforms.push( 'scaleY(-1)' );
291 }
292
293 if ( shapeDividers[ index ].flipHorizontally ) {
294 shapeTransforms.push( 'scaleX(-1)' );
295
296 cssObj[ '.gblocks-shape-container > .gblocks-shape-toggle-preview-' + shapeNumber + ' .gblocks-shape-divider-preview' ] = [ {
297 transform: 'scaleX(-1)',
298 } ];
299 }
300
301 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ] = [ {
302 color: hexToRGBA( shapeDividers[ index ].color, shapeDividers[ index ].colorOpacity ),
303 'z-index': shapeDividers[ index ].zindex,
304 } ];
305
306 if ( 'top' === shapeDividers[ index ].location || 'bottom' === shapeDividers[ index ].location ) {
307 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
308 left: '0',
309 right: '0',
310 } );
311 }
312
313 if ( 'bottom' === shapeDividers[ index ].location ) {
314 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
315 bottom: '-1px',
316 } );
317 }
318
319 if ( 'top' === shapeDividers[ index ].location ) {
320 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
321 top: '-1px',
322 } );
323 }
324
325 if ( shapeTransforms.length ) {
326 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
327 transform: shapeTransforms.join( ' ' ),
328 } );
329 }
330
331 let shapeWidth = shapeDividers[ index ].width + '%';
332
333 if ( 100 === shapeDividers[ index ].width ) {
334 shapeWidth = 'calc(' + shapeWidth + ' + 1.3px)';
335 }
336
337 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ] = [ {
338 height: valueWithUnit( shapeDividers[ index ].height, 'px' ),
339 width: shapeWidth,
340 } ];
341
342 if ( 'top' === shapeDividers[ index ].location || 'bottom' === shapeDividers[ index ].location ) {
343 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ].push( {
344 position: 'relative',
345 left: '50%',
346 transform: 'translateX(-50%)',
347 'min-width': '100%',
348 } );
349 }
350 } );
351 }
352
353 cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'container' );
354
355 return (
356 <style>{ buildCSS( cssObj ) }</style>
357 );
358 }
359 }
360 /* eslint-enable quotes */
361