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