PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.6.0
GenerateBlocks v1.6.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 / main.js
generateblocks / src / blocks / headline / 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
168 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 import {
8 Component,
9 } from '@wordpress/element';
10
11 import {
12 applyFilters,
13 } from '@wordpress/hooks';
14
15 export default class MainCSS extends Component {
16 render() {
17 const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props );
18
19 const {
20 clientId,
21 } = this.props;
22
23 const {
24 uniqueId,
25 element,
26 alignment,
27 backgroundColor,
28 backgroundColorOpacity,
29 textColor,
30 linkColor,
31 linkColorHover,
32 borderColor,
33 borderColorOpacity,
34 highlightTextColor,
35 fontFamily,
36 fontFamilyFallback,
37 fontWeight,
38 fontSize,
39 fontSizeUnit,
40 textTransform,
41 lineHeight,
42 lineHeightUnit,
43 letterSpacing,
44 marginTop,
45 marginRight,
46 marginBottom,
47 marginLeft,
48 marginUnit,
49 paddingTop,
50 paddingRight,
51 paddingBottom,
52 paddingLeft,
53 paddingUnit,
54 borderSizeTop,
55 borderSizeRight,
56 borderSizeBottom,
57 borderSizeLeft,
58 borderRadiusTopRight,
59 borderRadiusBottomRight,
60 borderRadiusBottomLeft,
61 borderRadiusTopLeft,
62 borderRadiusUnit,
63 icon,
64 iconColor,
65 iconColorOpacity,
66 iconLocation,
67 iconVerticalAlignment,
68 iconPaddingTop,
69 iconPaddingRight,
70 iconPaddingBottom,
71 iconPaddingLeft,
72 iconPaddingUnit,
73 iconSize,
74 iconSizeUnit,
75 inlineWidth,
76 removeText,
77 } = attributes;
78
79 let fontFamilyFallbackValue = '',
80 inlineWidthValue = 'inline-block';
81
82 if ( fontFamily && fontFamilyFallback ) {
83 fontFamilyFallbackValue = ', ' + fontFamilyFallback;
84 }
85
86 const selector = element + '.gb-headline-' + uniqueId;
87
88 let cssObj = [];
89
90 cssObj[ '.editor-styles-wrapper ' + selector ] = [ {
91 color: textColor,
92 'font-family': fontFamily + fontFamilyFallbackValue,
93 'font-weight': fontWeight,
94 'text-transform': textTransform,
95 'text-align': alignment,
96 'font-size': valueWithUnit( fontSize, fontSizeUnit ),
97 'line-height': valueWithUnit( lineHeight, lineHeightUnit ),
98 'letter-spacing': valueWithUnit( letterSpacing, 'em' ),
99 display: !! icon ? 'flex' : false,
100 'align-items': 'inline' === iconLocation ? flexboxAlignment( iconVerticalAlignment ) : flexboxAlignment( alignment ),
101 'justify-content': flexboxAlignment( alignment ),
102 'flex-direction': icon && 'above' === iconLocation ? 'column' : false,
103 } ];
104
105 cssObj[ '.editor-styles-wrapper .gb-container ' + selector ] = [ {
106 color: textColor,
107 } ];
108
109 if ( icon ) {
110 inlineWidthValue = 'inline-flex';
111 }
112
113 cssObj[ '.editor-styles-wrapper ' + selector ].push( {
114 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
115 'color': textColor, // eslint-disable-line quote-props
116 'display': inlineWidth ? inlineWidthValue : false, // eslint-disable-line quote-props
117 'margin-top': valueWithUnit( marginTop, marginUnit ),
118 'margin-right': valueWithUnit( marginRight, marginUnit ),
119 'margin-bottom': valueWithUnit( marginBottom, marginUnit ),
120 'margin-left': valueWithUnit( marginLeft, marginUnit ),
121 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props
122 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ),
123 'border-color': hexToRGBA( borderColor, borderColorOpacity ),
124 } );
125
126 if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) {
127 cssObj[ '.editor-styles-wrapper ' + selector ].push( {
128 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ),
129 'border-style': 'solid',
130 } );
131 }
132
133 cssObj[ '.editor-styles-wrapper ' + selector + ' a' ] = [ {
134 color: linkColor,
135 } ];
136
137 cssObj[ '.editor-styles-wrapper ' + selector + ' a:hover' ] = [ {
138 color: linkColorHover,
139 } ];
140
141 cssObj[ selector + ' .gb-icon' ] = [ {
142 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props
143 'align-self': icon && 'above' === iconLocation ? flexboxAlignment( alignment ) : false,
144 'color': hexToRGBA( iconColor, iconColorOpacity ), // eslint-disable-line quote-props
145 'display': icon && 'above' === iconLocation ? 'inline' : false, // eslint-disable-line quote-props
146 } ];
147
148 cssObj[ selector + ' .gb-icon svg' ] = [ {
149 'width': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props
150 'height': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props
151 } ];
152
153 cssObj[ selector + ' .gb-highlight' ] = [ {
154 'color': highlightTextColor, // eslint-disable-line quote-props
155 } ];
156
157 cssObj[ '.gb-is-root-block[data-block="' + clientId + '"]' ] = [ {
158 'display': inlineWidth ? 'inline-flex' : false, // eslint-disable-line quote-props
159 } ];
160
161 cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'headline' );
162
163 return (
164 <style>{ buildCSS( cssObj ) }</style>
165 );
166 }
167 }
168