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 / main.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
main.js
364 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 import sizingValue from '../../../utils/sizingValue';
8 import {
9 applyFilters,
10 } from '@wordpress/hooks';
11 import SizingCSS from '../../../extend/inspector-control/controls/sizing/components/SizingCSS';
12 import LayoutCSS from '../../../extend/inspector-control/controls/layout/components/LayoutCSS';
13 import FlexChildCSS from '../../../extend/inspector-control/controls/flex-child-panel/components/FlexChildCSS';
14 import isFlexItem from '../../../utils/is-flex-item';
15 import SpacingCSS from '../../../extend/inspector-control/controls/spacing/components/SpacingCSS';
16 import TypographyCSS from '../../../extend/inspector-control/controls/typography/components/TypographyCSS';
17 import BorderCSS, { BorderCSSColor } from '../../../extend/inspector-control/controls/borders/BorderCSS';
18
19 export default function MainCSS( props ) {
20 const attributes = applyFilters( 'generateblocks.editor.cssAttrs', props.attributes, props );
21
22 const {
23 clientId,
24 device,
25 } = props;
26
27 const {
28 uniqueId,
29 isGrid,
30 flexGrow,
31 flexShrink,
32 flexBasis,
33 outerContainer,
34 innerContainer,
35 containerWidth,
36 backgroundColor,
37 backgroundColorOpacity,
38 gradient,
39 gradientSelector,
40 textColor,
41 linkColor,
42 linkColorHover,
43 bgImage,
44 bgOptions,
45 verticalAlignment,
46 zindex,
47 innerZindex,
48 fontFamilyFallback,
49 shapeDividers,
50 gridId,
51 useDynamicData,
52 dynamicContentType,
53 bgImageInline,
54 useInnerContainer,
55 sizing,
56 order,
57 display,
58 displayTablet,
59 displayMobile,
60 } = attributes;
61
62 const {
63 paddingTop,
64 paddingRight,
65 paddingBottom,
66 paddingLeft,
67 } = attributes.spacing;
68
69 const {
70 borderTopLeftRadius,
71 borderTopRightRadius,
72 borderBottomRightRadius,
73 borderBottomLeftRadius,
74 } = attributes.borders;
75
76 let containerWidthPreview = containerWidth;
77
78 if ( ! containerWidthPreview ) {
79 containerWidthPreview = generateBlocksDefaults.container.containerWidth;
80 }
81
82 const hasBgImage = !! bgImage || ( useDynamicData && '' !== dynamicContentType );
83 const backgroundImageValue = getBackgroundImageCSS( 'image', props );
84 const gradientValue = getBackgroundImageCSS( 'gradient', props );
85 const selector = '.editor-styles-wrapper .gb-container-' + uniqueId;
86
87 let cssObj = [];
88 cssObj[ selector ] = [ {
89 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
90 'color': textColor, // eslint-disable-line quote-props
91 } ];
92
93 TypographyCSS( cssObj, selector, { ...attributes.typography, fontFamilyFallback } );
94 SpacingCSS( cssObj, selector, { ...attributes.spacing, useInnerContainer } );
95 BorderCSS( cssObj, selector, attributes.borders );
96 SizingCSS( cssObj, selector, attributes );
97 LayoutCSS( cssObj, selector, attributes );
98 FlexChildCSS( cssObj, selector, attributes );
99
100 if ( hasBgImage && 'element' === bgOptions.selector && backgroundImageValue ) {
101 cssObj[ selector ].push( {
102 'background-image': ! bgImageInline ? backgroundImageValue : null,
103 'background-size': bgOptions.size,
104 'background-position': bgOptions.position,
105 'background-repeat': bgOptions.repeat,
106 'background-attachment': bgOptions.attachment,
107 } );
108 } else if ( gradient && 'element' === gradientSelector ) {
109 cssObj[ selector ].push( {
110 'background-image': gradientValue,
111 } );
112 }
113
114 BorderCSSColor( cssObj, selector + ':hover', { ...attributes.borders }, 'Hover' );
115
116 const currentSelector = selector + '[data-container-is-current], ' + selector + '[data-container-is-current]:hover';
117 BorderCSSColor( cssObj, currentSelector, { ...attributes.borders }, 'Current' );
118
119 if ( useInnerContainer ) {
120 if (
121 ( hasBgImage && 'pseudo-element' === bgOptions.selector ) ||
122 zindex ||
123 ( gradient && 'pseudo-element' === gradientSelector )
124 ) {
125 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
126 'position': 'relative', // eslint-disable-line quote-props
127 } );
128 }
129
130 if (
131 ( hasBgImage && 'pseudo-element' === bgOptions.selector ) ||
132 ( gradient && 'pseudo-element' === gradientSelector )
133 ) {
134 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
135 'overflow': 'hidden', // eslint-disable-line quote-props
136 } );
137
138 cssObj[ '.gb-container-' + uniqueId + ' .block-list-appender' ] = [ {
139 'z-index': 10,
140 } ];
141 }
142 }
143
144 if (
145 ( hasBgImage && 'pseudo-element' === bgOptions.selector ) ||
146 ( gradient && 'pseudo-element' === gradientSelector )
147 ) {
148 cssObj[ '.gb-container-' + uniqueId + ' .block-list-appender' ] = [ {
149 'z-index': 10,
150 } ];
151 }
152
153 cssObj[ `.editor-styles-wrapper .gb-container-` + uniqueId + ` h1,
154 .editor-styles-wrapper .gb-container-` + uniqueId + ` h2,
155 .editor-styles-wrapper .gb-container-` + uniqueId + ` h3,
156 .editor-styles-wrapper .gb-container-` + uniqueId + ` h4,
157 .editor-styles-wrapper .gb-container-` + uniqueId + ` h5,
158 .editor-styles-wrapper .gb-container-` + uniqueId + ` h6` ] = [ {
159 'color': textColor, // eslint-disable-line quote-props
160 } ];
161
162 if ( hasBgImage && 'pseudo-element' === bgOptions.selector ) {
163 cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ {
164 'content': '""', // eslint-disable-line quote-props
165 'background-image': backgroundImageValue,
166 'background-repeat': bgOptions.repeat,
167 'background-position': bgOptions.position,
168 'background-size': bgOptions.size,
169 'background-attachment': bgOptions.attachment,
170 'z-index': '0',
171 'position': 'absolute', // eslint-disable-line quote-props
172 'top': '0', // eslint-disable-line quote-props
173 'right': '0', // eslint-disable-line quote-props
174 'bottom': '0', // eslint-disable-line quote-props
175 'left': '0', // eslint-disable-line quote-props
176 'border-radius': shorthandCSS( borderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadius ),
177 'pointer-events': 'none',
178 } ];
179
180 if ( typeof bgOptions.opacity !== 'undefined' && 1 !== bgOptions.opacity ) {
181 cssObj[ '.gb-container-' + uniqueId + ':before' ].push( {
182 'opacity': bgOptions.opacity, // eslint-disable-line quote-props
183 } );
184 }
185 }
186
187 if ( gradient && 'pseudo-element' === gradientSelector ) {
188 cssObj[ '.gb-container-' + uniqueId + ':after' ] = [ {
189 'content': '""', // eslint-disable-line quote-props
190 'background-image': gradientValue,
191 'z-index': '0 !important',
192 'position': 'absolute', // eslint-disable-line quote-props
193 'top': '0', // eslint-disable-line quote-props
194 'right': '0', // eslint-disable-line quote-props
195 'bottom': '0', // eslint-disable-line quote-props
196 'left': '0', // eslint-disable-line quote-props
197 'pointer-events': 'none',
198 } ];
199 }
200
201 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId + ' a, .editor-styles-wrapper .gb-container-' + uniqueId + ' a:visited' ] = [ {
202 'color': linkColor, // eslint-disable-line quote-props
203 } ];
204
205 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId + ' a:hover' ] = [ {
206 'color': linkColorHover, // eslint-disable-line quote-props
207 } ];
208
209 if ( useInnerContainer ) {
210 if ( sizingValue( 'minHeight', sizing ) && ! isGrid ) {
211 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
212 'display': 'flex', // eslint-disable-line quote-props
213 'flex-direction': 'row',
214 'align-items': verticalAlignment,
215 } );
216 }
217
218 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ] = [ {
219 padding: shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft ),
220 'width': sizingValue( 'minHeight', sizing ) && ! isGrid ? '100%' : false, // eslint-disable-line quote-props
221 } ];
222
223 if ( innerZindex || 0 === innerZindex ) {
224 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ].push( {
225 'z-index': innerZindex,
226 position: 'relative',
227 } );
228 }
229
230 if ( 'contained' === innerContainer && ! isGrid ) {
231 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ].push( {
232 'max-width': valueWithUnit( containerWidthPreview, 'px' ),
233 'margin-left': 'auto',
234 'margin-right': 'auto',
235 } );
236 }
237
238 // We need use an ID for the contained block width so it overrides other
239 // .wp-block max-width selectors.
240 cssObj[ '#block-' + clientId ] = [ {
241 'max-width': 'contained' === outerContainer && ! isGrid ? valueWithUnit( containerWidthPreview, 'px' ) : false,
242 'margin-left': 'contained' === outerContainer && ! isGrid ? 'auto' : false,
243 'margin-right': 'contained' === outerContainer && ! isGrid ? 'auto' : false,
244 } ];
245 }
246
247 if ( isGrid ) {
248 const gridColumnSelectors = [
249 '.gb-post-template-' + gridId + ' > .gb-post-template-wrapper > .block-editor-inner-blocks',
250 '.gb-grid-wrapper > .block-editor-inner-blocks > .block-editor-block-list__layout > .gb-grid-column-' + uniqueId,
251 ];
252
253 cssObj[ gridColumnSelectors.join( ',' ) ] = [ {
254 width: sizingValue( 'width', sizing ),
255 'flex-grow': flexGrow,
256 'flex-shrink': flexShrink,
257 'flex-basis': flexBasis,
258 order,
259 } ];
260
261 if ( useInnerContainer ) {
262 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
263 display: 'flex',
264 'flex-direction': 'column',
265 height: '100%',
266 'justify-content': verticalAlignment,
267 } );
268 }
269 }
270
271 if ( shapeDividers.length ) {
272 if ( useInnerContainer ) {
273 cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( {
274 position: 'relative',
275 } );
276 }
277
278 cssObj[ '.gb-container-' + uniqueId + ' .block-list-appender' ] = [ {
279 position: 'relative',
280 'z-index': 100,
281 } ];
282
283 shapeDividers.forEach( ( location, index ) => {
284 const shapeTransforms = [];
285 const shapeNumber = index + 1;
286
287 if ( 'top' === shapeDividers[ index ].location ) {
288 shapeTransforms.push( 'scaleY(-1)' );
289 }
290
291 if ( shapeDividers[ index ].flipHorizontally ) {
292 shapeTransforms.push( 'scaleX(-1)' );
293
294 cssObj[ '.gblocks-shape-container > .gblocks-shape-toggle-preview-' + shapeNumber + ' .gblocks-shape-divider-preview' ] = [ {
295 transform: 'scaleX(-1)',
296 } ];
297 }
298
299 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ] = [ {
300 color: hexToRGBA( shapeDividers[ index ].color, shapeDividers[ index ].colorOpacity ),
301 'z-index': shapeDividers[ index ].zindex,
302 } ];
303
304 if ( 'top' === shapeDividers[ index ].location || 'bottom' === shapeDividers[ index ].location ) {
305 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
306 left: '0',
307 right: '0',
308 } );
309 }
310
311 if ( 'bottom' === shapeDividers[ index ].location ) {
312 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
313 bottom: '-1px',
314 } );
315 }
316
317 if ( 'top' === shapeDividers[ index ].location ) {
318 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
319 top: '-1px',
320 } );
321 }
322
323 if ( shapeTransforms.length ) {
324 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber ].push( {
325 transform: shapeTransforms.join( ' ' ),
326 } );
327 }
328
329 let shapeWidth = shapeDividers[ index ].width + '%';
330
331 if ( 100 === shapeDividers[ index ].width ) {
332 shapeWidth = 'calc(' + shapeWidth + ' + 1.3px)';
333 }
334
335 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ] = [ {
336 height: valueWithUnit( shapeDividers[ index ].height, 'px' ),
337 width: shapeWidth,
338 } ];
339
340 if ( 'top' === shapeDividers[ index ].location || 'bottom' === shapeDividers[ index ].location ) {
341 cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ].push( {
342 position: 'relative',
343 left: '50%',
344 transform: 'translateX(-50%)',
345 'min-width': '100%',
346 } );
347 }
348 } );
349 }
350
351 if ( isFlexItem( { device, display, displayTablet, displayMobile } ) ) {
352 cssObj[ '.gb-container-' + uniqueId + '.block-editor-block-list__block > .block-list-appender' ] = [ {
353 'margin-top': 0,
354 } ];
355 }
356
357 cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, props, 'container' );
358
359 return (
360 <style>{ buildCSS( cssObj ) }</style>
361 );
362 }
363 /* eslint-enable quotes */
364