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