PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.0
GenerateBlocks v1.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 / desktop.js
generateblocks / src / blocks / container / css Last commit date
desktop.js 6 years ago
desktop.js
225 lines
1 /* eslint-disable quotes */
2 import buildCSS from '../../../utils/build-css';
3 import shorthandCSS from '../../../utils/shorthand-css';
4 import hexToRGBA from '../../../components/color-picker/hex-to-rgba';
5 import valueWithUnit from '../../../utils/value-with-unit';
6
7 const { Component } = wp.element;
8 const { applyFilters } = wp.hooks;
9
10 export default class DesktopCSS extends Component {
11 render() {
12 const {
13 attributes,
14 clientId,
15 } = this.props;
16
17 const {
18 uniqueId,
19 isGrid,
20 width,
21 outerContainer,
22 innerContainer,
23 containerWidth,
24 minHeight,
25 minHeightUnit,
26 paddingTop,
27 paddingRight,
28 paddingBottom,
29 paddingLeft,
30 paddingUnit,
31 marginTop,
32 marginRight,
33 marginBottom,
34 marginLeft,
35 marginUnit,
36 borderSizeTop,
37 borderSizeRight,
38 borderSizeBottom,
39 borderSizeLeft,
40 borderRadiusTopRight,
41 borderRadiusBottomRight,
42 borderRadiusBottomLeft,
43 borderRadiusTopLeft,
44 borderRadiusUnit,
45 borderColor,
46 borderColorOpacity,
47 backgroundColor,
48 backgroundColorOpacity,
49 gradient,
50 gradientDirection,
51 gradientColorOne,
52 gradientColorOneOpacity,
53 gradientColorStopOne,
54 gradientColorTwo,
55 gradientColorTwoOpacity,
56 gradientColorStopTwo,
57 textColor,
58 linkColor,
59 linkColorHover,
60 bgImage,
61 bgOptions,
62 verticalAlignment,
63 zindex,
64 removeVerticalGap,
65 alignment,
66 fontFamily,
67 fontFamilyFallback,
68 fontWeight,
69 fontSize,
70 fontSizeUnit,
71 textTransform,
72 } = attributes;
73
74 let backgroundImageValue,
75 gradientColorStopOneValue = '',
76 gradientColorStopTwoValue = '';
77
78 if ( gradient ) {
79 if ( gradientColorOne && '' !== gradientColorStopOne ) {
80 gradientColorStopOneValue = ' ' + gradientColorStopOne + '%';
81 }
82
83 if ( gradientColorTwo && '' !== gradientColorStopTwo ) {
84 gradientColorStopTwoValue = ' ' + gradientColorStopTwo + '%';
85 }
86 }
87
88 if ( bgImage ) {
89 backgroundImageValue = 'url(' + bgImage.image.url + ')';
90
91 if ( bgOptions.overlay ) {
92 if ( gradient ) {
93 backgroundImageValue = 'linear-gradient(' + gradientDirection + 'deg, ' + hexToRGBA( gradientColorOne, gradientColorOneOpacity ) + gradientColorStopOneValue + ', ' + hexToRGBA( gradientColorTwo, gradientColorTwoOpacity ) + gradientColorStopTwoValue + '), url(' + bgImage.image.url + ')';
94 } else {
95 backgroundImageValue = 'linear-gradient(0deg, ' + hexToRGBA( backgroundColor, backgroundColorOpacity ) + ', ' + hexToRGBA( backgroundColor, backgroundColorOpacity ) + '), url(' + bgImage.image.url + ')';
96 }
97 }
98 } else if ( gradient ) {
99 backgroundImageValue = 'linear-gradient(' + gradientDirection + 'deg, ' + hexToRGBA( gradientColorOne, gradientColorOneOpacity ) + gradientColorStopOneValue + ', ' + hexToRGBA( gradientColorTwo, gradientColorTwoOpacity ) + gradientColorStopTwoValue + ');';
100 }
101
102 let containerWidthPreview = containerWidth;
103
104 if ( ! containerWidthPreview ) {
105 containerWidthPreview = generateBlocksDefaults.container.containerWidth;
106 }
107
108 let fontFamilyFallbackValue = '';
109
110 if ( fontFamily && fontFamilyFallback ) {
111 fontFamilyFallbackValue = ', ' + fontFamilyFallback;
112 }
113
114 let cssObj = [];
115
116 cssObj[ '.gb-container-' + uniqueId ] = [ {
117 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
118 'color': textColor, // eslint-disable-line quote-props
119 'background-image': backgroundImageValue,
120 'background-size': bgOptions.size,
121 'background-position': bgOptions.position,
122 'background-repeat': bgOptions.repeat,
123 'background-attachment': bgOptions.attachment,
124 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ),
125 'margin': shorthandCSS( marginTop, marginRight, marginBottom, marginLeft, marginUnit ), // eslint-disable-line quote-props
126 'z-index': zindex,
127 'position': zindex ? 'relative' : false, // eslint-disable-line quote-props
128 'text-align': alignment,
129 'font-family': fontFamily + fontFamilyFallbackValue,
130 'font-weight': fontWeight,
131 'text-transform': textTransform,
132 'font-size': valueWithUnit( fontSize, fontSizeUnit ),
133 'min-height': valueWithUnit( minHeight, minHeightUnit ),
134 } ];
135
136 cssObj[ `.editor-styles-wrapper .gb-container-` + uniqueId + ` h1,
137 .editor-styles-wrapper .gb-container-` + uniqueId + ` h2,
138 .editor-styles-wrapper .gb-container-` + uniqueId + ` h3,
139 .editor-styles-wrapper .gb-container-` + uniqueId + ` h4,
140 .editor-styles-wrapper .gb-container-` + uniqueId + ` h5,
141 .editor-styles-wrapper .gb-container-` + uniqueId + ` h6` ] = [ {
142 'color': textColor, // eslint-disable-line quote-props
143 } ];
144
145 if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) {
146 cssObj[ '.gb-container-' + uniqueId ].push( {
147 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ),
148 'border-style': 'solid',
149 'border-color': hexToRGBA( borderColor, borderColorOpacity ),
150 } );
151 }
152
153 if ( minHeight && ! isGrid ) {
154 cssObj[ '.gb-container-' + uniqueId ].push( {
155 'display': 'flex', // eslint-disable-line quote-props
156 'flex-direction': 'row',
157 'align-items': verticalAlignment,
158 } );
159 }
160
161 cssObj[ '.gb-container-' + uniqueId + ' a, .gb-container-' + uniqueId + ' a:visited' ] = [ {
162 'color': linkColor, // eslint-disable-line quote-props
163 } ];
164
165 cssObj[ '.gb-container-' + uniqueId + ' a:hover' ] = [ {
166 'color': linkColorHover, // eslint-disable-line quote-props
167 } ];
168
169 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ] = [ {
170 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props
171 'width': minHeight && ! isGrid ? '100%' : false, // eslint-disable-line quote-props
172 } ];
173
174 if ( 'contained' === innerContainer && ! isGrid ) {
175 cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ].push( {
176 'max-width': valueWithUnit( containerWidthPreview, 'px' ),
177 'margin-left': 'auto',
178 'margin-right': 'auto',
179 } );
180 }
181
182 cssObj[ '.gb-grid-wrapper > div > .block-editor-block-list__layout > #block-' + clientId ] = [ {
183 'width': valueWithUnit( width, '%' ), // eslint-disable-line quote-props
184 'display': 'flex', // eslint-disable-line quote-props
185 'flex-direction': 'column',
186 'margin-left': '0px',
187 'margin-right': '0px',
188 } ];
189
190 cssObj[ '.gb-grid-wrapper > div > .block-editor-block-list__layout > #block-' + clientId + ' > .gb-grid-column' ] = [ {
191 'height': '100%', // eslint-disable-line quote-props
192 } ];
193
194 cssObj[ '.block-editor-block-list__layout > #block-' + clientId ] = [ {
195 'max-width': 'contained' === outerContainer && ! isGrid ? valueWithUnit( containerWidthPreview, 'px' ) : false,
196 'margin-bottom': removeVerticalGap ? '0px !important' : false,
197 } ];
198
199 cssObj[ '.gb-grid-column > .gb-container-' + uniqueId ] = [ {
200 'display': 'flex', // eslint-disable-line quote-props
201 'flex-direction': 'column',
202 'height': '100%', // eslint-disable-line quote-props
203 'justify-content': verticalAlignment,
204 } ];
205
206 cssObj[ `.gb-grid-wrapper > div > .block-editor-block-list__layout > #block-` + clientId + ` > .block-editor-block-list__block-edit,
207 .gb-grid-wrapper > div > .block-editor-block-list__layout > #block-` + clientId + ` > .block-editor-block-list__block-edit > [data-block="` + clientId + `"],
208 .gb-grid-wrapper > div > .block-editor-block-list__layout > #block-` + clientId + ` > .block-editor-block-list__block-edit > [data-block="` + clientId + `"] > .gb-grid-column` ] = [ {
209 'height': '100%', // eslint-disable-line quote-props
210 } ];
211
212 cssObj[ `#block-` + clientId + `:not(.has-child-selected):not(.is-selected) .block-list-appender:not(:first-child),
213 #block-` + clientId + `:not(.has-child-selected):not(.is-selected) .block-editor-block-list__layout > div:not(:first-child) > .block-list-appender` ] = [ {
214 'display': 'none', // eslint-disable-line quote-props
215 } ];
216
217 cssObj = applyFilters( 'generateblocks.editor.desktopCSS', cssObj, 'container', this.props );
218
219 return (
220 <style>{ buildCSS( cssObj ) }</style>
221 );
222 }
223 }
224 /* eslint-enable quotes */
225