PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.1.2
GenerateBlocks v1.1.2
2.4.1 2.4.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 / headline / css / desktop.js
generateblocks / src / blocks / headline / css Last commit date
desktop.js 6 years ago
desktop.js
172 lines
1 import buildCSS from '../../../utils/build-css';
2 import flexboxAlignment from '../../../utils/flexbox-alignment';
3 import valueWithUnit from '../../../utils/value-with-unit';
4 import shorthandCSS from '../../../utils/shorthand-css';
5 import hexToRGBA from '../../../utils/hex-to-rgba';
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 element,
20 alignment,
21 backgroundColor,
22 backgroundColorOpacity,
23 textColor,
24 linkColor,
25 borderColor,
26 borderColorOpacity,
27 highlightTextColor,
28 fontFamily,
29 fontFamilyFallback,
30 fontWeight,
31 fontSize,
32 fontSizeUnit,
33 textTransform,
34 lineHeight,
35 lineHeightUnit,
36 letterSpacing,
37 marginTop,
38 marginRight,
39 marginBottom,
40 marginLeft,
41 marginUnit,
42 paddingTop,
43 paddingRight,
44 paddingBottom,
45 paddingLeft,
46 paddingUnit,
47 borderSizeTop,
48 borderSizeRight,
49 borderSizeBottom,
50 borderSizeLeft,
51 icon,
52 iconColor,
53 iconColorOpacity,
54 iconLocation,
55 iconVerticalAlignment,
56 iconPaddingTop,
57 iconPaddingRight,
58 iconPaddingBottom,
59 iconPaddingLeft,
60 iconPaddingUnit,
61 iconSize,
62 iconSizeUnit,
63 inlineWidth,
64 removeText,
65 } = attributes;
66
67 let fontFamilyFallbackValue = '',
68 marginBottomValue = '',
69 fontSizeValue = '',
70 inlineWidthValue = 'inline-block';
71
72 if ( fontFamily && fontFamilyFallback ) {
73 fontFamilyFallbackValue = ', ' + fontFamilyFallback;
74 }
75
76 if ( marginBottom ) {
77 marginBottomValue = marginBottom + marginUnit;
78 } else if ( typeof generateBlocksStyling.headline !== 'undefined' && ! removeText ) {
79 if ( typeof generateBlocksStyling.headline[ attributes.element ].marginBottom !== 'undefined' && ! isNaN( generateBlocksStyling.headline[ attributes.element ].marginBottom ) ) {
80 marginBottomValue = generateBlocksStyling.headline[ element ].marginBottom + generateBlocksStyling.headline[ element ].marginUnit;
81 }
82 }
83
84 if ( fontSize ) {
85 fontSizeValue = fontSize + fontSizeUnit;
86 } else if ( typeof generateBlocksStyling.headline !== 'undefined' && ! removeText ) {
87 if ( typeof generateBlocksStyling.headline[ attributes.element ].fontSize !== 'undefined' && generateBlocksStyling.headline[ attributes.element ].fontSize ) {
88 fontSizeValue = generateBlocksStyling.headline[ element ].fontSize + generateBlocksStyling.headline[ element ].fontSizeUnit;
89 }
90 }
91
92 let cssObj = [];
93
94 cssObj[ '.editor-styles-wrapper .gb-headline-' + uniqueId ] = [ {
95 'color': textColor, // eslint-disable-line quote-props
96 'font-family': fontFamily + fontFamilyFallbackValue,
97 'font-weight': fontWeight,
98 'text-transform': textTransform,
99 'text-align': alignment,
100 'font-size': fontSizeValue,
101 'line-height': valueWithUnit( lineHeight, lineHeightUnit ),
102 'letter-spacing': valueWithUnit( letterSpacing, 'em' ),
103 } ];
104
105 cssObj[ '.editor-styles-wrapper .gb-container .gb-headline-' + uniqueId ] = [ {
106 'color': textColor, // eslint-disable-line quote-props
107 } ];
108
109 cssObj[ '.gb-headline-wrapper-' + uniqueId ] = [ {
110 'flex-direction': icon && 'above' === iconLocation ? 'column' : false,
111 'justify-content': flexboxAlignment( alignment ),
112 'text-align': alignment,
113 'align-items': 'inline' === iconLocation ? flexboxAlignment( iconVerticalAlignment ) : flexboxAlignment( alignment ),
114 'font-size': fontSizeValue,
115 } ];
116
117 let headlineStyleSelector = '.editor-styles-wrapper .gb-headline-' + uniqueId;
118
119 if ( icon ) {
120 headlineStyleSelector = '.gb-headline-wrapper-' + uniqueId;
121 inlineWidthValue = 'inline-flex';
122 }
123
124 cssObj[ headlineStyleSelector ].push( {
125 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
126 'color': textColor, // eslint-disable-line quote-props
127 'display': inlineWidth ? inlineWidthValue : false, // eslint-disable-line quote-props
128 'margin': shorthandCSS( marginTop, marginRight, marginBottomValue, marginLeft, marginUnit ) + ' !important', // eslint-disable-line quote-props
129 'margin-bottom': marginBottomValue + ' !important', // The unit changes depending on the element if no value exists.
130 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props
131 } );
132
133 if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) {
134 cssObj[ headlineStyleSelector ].push( {
135 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ),
136 'border-style': 'solid',
137 'border-color': hexToRGBA( borderColor, borderColorOpacity ),
138 } );
139 }
140
141 cssObj[ '.editor-styles-wrapper .gb-headline-' + uniqueId + ' a' ] = [ {
142 'color': linkColor, // eslint-disable-line quote-props
143 } ];
144
145 cssObj[ '.gb-headline-wrapper-' + uniqueId + ' .gb-icon' ] = [ {
146 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props
147 'align-self': icon && 'above' === iconLocation ? flexboxAlignment( alignment ) : false,
148 'color': hexToRGBA( iconColor, iconColorOpacity ), // eslint-disable-line quote-props
149 'display': icon && 'above' === iconLocation ? 'inline' : false, // eslint-disable-line quote-props
150 } ];
151
152 cssObj[ '.gb-headline-wrapper-' + uniqueId + ' .gb-icon svg' ] = [ {
153 'width': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props
154 'height': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props
155 } ];
156
157 cssObj[ '.gb-headline-' + uniqueId + ' .gb-highlight' ] = [ {
158 'color': highlightTextColor, // eslint-disable-line quote-props
159 } ];
160
161 cssObj[ '#block-' + clientId ] = [ {
162 'display': inlineWidth ? 'inline-flex' : false, // eslint-disable-line quote-props
163 } ];
164
165 cssObj = applyFilters( 'generateblocks.editor.desktopCSS', cssObj, this.props, 'headline' );
166
167 return (
168 <style>{ buildCSS( cssObj ) }</style>
169 );
170 }
171 }
172