PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.0
GenerateBlocks v1.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 / button / css / main.js
generateblocks / src / blocks / button / css Last commit date
desktop.js 5 years ago main.js 5 years ago mobile.js 5 years ago tablet-only.js 5 years ago tablet.js 5 years ago
main.js
150 lines
1 /* eslint-disable quotes */
2 import buildCSS from '../../../utils/build-css';
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 url,
21 uniqueId,
22 removeText,
23 backgroundColor,
24 backgroundColorOpacity,
25 textColor,
26 backgroundColorHover,
27 backgroundColorHoverOpacity,
28 textColorHover,
29 fontFamily,
30 fontFamilyFallback,
31 fontWeight,
32 textTransform,
33 letterSpacing,
34 fontSize,
35 fontSizeUnit,
36 marginTop,
37 marginRight,
38 marginBottom,
39 marginLeft,
40 marginUnit,
41 paddingTop,
42 paddingRight,
43 paddingBottom,
44 paddingLeft,
45 paddingUnit,
46 borderSizeTop,
47 borderSizeRight,
48 borderSizeBottom,
49 borderSizeLeft,
50 borderRadiusTopRight,
51 borderRadiusBottomRight,
52 borderRadiusBottomLeft,
53 borderRadiusTopLeft,
54 borderRadiusUnit,
55 borderColor,
56 borderColorOpacity,
57 borderColorHover,
58 borderColorHoverOpacity,
59 gradient,
60 gradientDirection,
61 gradientColorOne,
62 gradientColorOneOpacity,
63 gradientColorStopOne,
64 gradientColorTwo,
65 gradientColorTwoOpacity,
66 gradientColorStopTwo,
67 iconPaddingTop,
68 iconPaddingRight,
69 iconPaddingBottom,
70 iconPaddingLeft,
71 iconPaddingUnit,
72 iconSize,
73 iconSizeUnit,
74 } = attributes;
75
76 let fontFamilyFallbackValue = '',
77 backgroundImageValue,
78 gradientColorStopOneValue = '',
79 gradientColorStopTwoValue = '';
80
81 if ( gradient ) {
82 if ( gradientColorOne && '' !== gradientColorStopOne ) {
83 gradientColorStopOneValue = ' ' + gradientColorStopOne + '%';
84 }
85
86 if ( gradientColorTwo && '' !== gradientColorStopTwo ) {
87 gradientColorStopTwoValue = ' ' + gradientColorStopTwo + '%';
88 }
89 }
90
91 if ( gradient ) {
92 backgroundImageValue = 'linear-gradient(' + gradientDirection + 'deg, ' + hexToRGBA( gradientColorOne, gradientColorOneOpacity ) + gradientColorStopOneValue + ', ' + hexToRGBA( gradientColorTwo, gradientColorTwoOpacity ) + gradientColorStopTwoValue + ');';
93 }
94
95 if ( fontFamily && fontFamilyFallback ) {
96 fontFamilyFallbackValue = ', ' + fontFamilyFallback;
97 }
98
99 let selector = 'a.gb-button-' + uniqueId;
100
101 if ( ! url ) {
102 selector = '.gb-button-' + uniqueId;
103 }
104
105 let cssObj = [];
106
107 cssObj[ '.block-editor-block-list__block ' + selector ] = [ {
108 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
109 'background-image': backgroundImageValue,
110 'color': textColor, // eslint-disable-line quote-props
111 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props
112 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ),
113 'font-family': fontFamily + fontFamilyFallbackValue,
114 'font-weight': fontWeight,
115 'text-transform': textTransform,
116 'font-size': valueWithUnit( fontSize, fontSizeUnit ),
117 'letter-spacing': valueWithUnit( letterSpacing, 'em' ),
118 'margin': shorthandCSS( marginTop, marginRight, marginBottom, marginLeft, marginUnit ), // eslint-disable-line quote-props
119 'border-color': hexToRGBA( borderColor, borderColorOpacity ),
120 } ];
121
122 if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) {
123 cssObj[ '.block-editor-block-list__block ' + selector ].push( {
124 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ),
125 'border-style': 'solid',
126 } );
127 }
128
129 cssObj[ `.block-editor-block-list__block ` + selector + `:hover,
130 .block-editor-block-list__block ` + selector + `:focus,
131 .block-editor-block-list__block ` + selector + `:active` ] = [ {
132 'background-color': hexToRGBA( backgroundColorHover, backgroundColorHoverOpacity ),
133 'color': textColorHover, // eslint-disable-line quote-props
134 'border-color': hexToRGBA( borderColorHover, borderColorHoverOpacity ),
135 } ];
136
137 cssObj[ '.block-editor-block-list__block ' + selector + ' .gb-icon' ] = [ {
138 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props
139 'font-size': valueWithUnit( iconSize, iconSizeUnit ),
140 } ];
141
142 cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'button' );
143
144 return (
145 <style>{ buildCSS( cssObj ) }</style>
146 );
147 }
148 }
149 /* eslint-enable quotes */
150