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 / headline / css / desktop.js
generateblocks / src / blocks / headline / css Last commit date
desktop.js 6 years ago
desktop.js
170 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 '../../../components/color-picker/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
71 if ( fontFamily && fontFamilyFallback ) {
72 fontFamilyFallbackValue = ', ' + fontFamilyFallback;
73 }
74
75 if ( marginBottom ) {
76 marginBottomValue = marginBottom + marginUnit;
77 } else if ( typeof generateBlocksStyling.headline !== 'undefined' && ! removeText ) {
78 if ( typeof generateBlocksStyling.headline[ attributes.element ].marginBottom !== 'undefined' && ! isNaN( generateBlocksStyling.headline[ attributes.element ].marginBottom ) ) {
79 marginBottomValue = generateBlocksStyling.headline[ element ].marginBottom + generateBlocksStyling.headline[ element ].marginUnit;
80 }
81 }
82
83 if ( fontSize ) {
84 fontSizeValue = fontSize + fontSizeUnit;
85 } else if ( typeof generateBlocksStyling.headline !== 'undefined' && ! removeText ) {
86 if ( typeof generateBlocksStyling.headline[ attributes.element ].fontSize !== 'undefined' && generateBlocksStyling.headline[ attributes.element ].fontSize ) {
87 fontSizeValue = generateBlocksStyling.headline[ element ].fontSize + generateBlocksStyling.headline[ element ].fontSizeUnit;
88 }
89 }
90
91 let cssObj = [];
92
93 cssObj[ '.editor-styles-wrapper .gb-headline-' + uniqueId ] = [ {
94 'color': textColor, // eslint-disable-line quote-props
95 'font-family': fontFamily + fontFamilyFallbackValue,
96 'font-weight': fontWeight,
97 'text-transform': textTransform,
98 'text-align': alignment,
99 'font-size': fontSizeValue,
100 'line-height': valueWithUnit( lineHeight, lineHeightUnit ),
101 'letter-spacing': valueWithUnit( letterSpacing, 'em' ),
102 } ];
103
104 cssObj[ '.editor-styles-wrapper .gb-container .gb-headline-' + uniqueId ] = [ {
105 'color': textColor, // eslint-disable-line quote-props
106 } ];
107
108 cssObj[ '.gb-headline-wrapper-' + uniqueId ] = [ {
109 'flex-direction': icon && 'above' === iconLocation ? 'column' : false,
110 'justify-content': flexboxAlignment( alignment ),
111 'text-align': alignment,
112 'align-items': 'inline' === iconLocation ? flexboxAlignment( iconVerticalAlignment ) : flexboxAlignment( alignment ),
113 'font-size': fontSizeValue,
114 } ];
115
116 let headlineStyleSelector = '.editor-styles-wrapper .gb-headline-' + uniqueId;
117
118 if ( icon ) {
119 headlineStyleSelector = '.gb-headline-wrapper-' + uniqueId;
120 }
121
122 cssObj[ headlineStyleSelector ].push( {
123 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
124 'color': textColor, // eslint-disable-line quote-props
125 'display': inlineWidth ? 'inline-flex' : false, // eslint-disable-line quote-props
126 'margin': shorthandCSS( marginTop, marginRight, marginBottomValue, marginLeft, marginUnit ) + ' !important', // eslint-disable-line quote-props
127 'margin-bottom': marginBottomValue + ' !important', // The unit changes depending on the element if no value exists.
128 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props
129 } );
130
131 if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) {
132 cssObj[ headlineStyleSelector ].push( {
133 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ),
134 'border-style': 'solid',
135 'border-color': hexToRGBA( borderColor, borderColorOpacity ),
136 } );
137 }
138
139 cssObj[ '.editor-styles-wrapper .gb-headline-' + uniqueId + ' a' ] = [ {
140 'color': linkColor, // eslint-disable-line quote-props
141 } ];
142
143 cssObj[ '.gb-headline-wrapper-' + uniqueId + ' .gb-icon' ] = [ {
144 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props
145 'align-self': icon && 'above' === iconLocation ? flexboxAlignment( alignment ) : false,
146 'color': hexToRGBA( iconColor, iconColorOpacity ), // eslint-disable-line quote-props
147 'display': icon && 'above' === iconLocation ? 'unset' : false, // eslint-disable-line quote-props
148 } ];
149
150 cssObj[ '.gb-headline-wrapper-' + uniqueId + ' .gb-icon svg' ] = [ {
151 'width': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props
152 'height': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props
153 } ];
154
155 cssObj[ '.gb-headline-' + uniqueId + ' .gb-highlight' ] = [ {
156 'color': highlightTextColor, // eslint-disable-line quote-props
157 } ];
158
159 cssObj[ '#block-' + clientId ] = [ {
160 'display': inlineWidth ? 'inline-flex' : false, // eslint-disable-line quote-props
161 } ];
162
163 cssObj = applyFilters( 'generateblocks.editor.desktopCSS', cssObj, 'headline', this.props );
164
165 return (
166 <style>{ buildCSS( cssObj ) }</style>
167 );
168 }
169 }
170