PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.2.0
GenerateBlocks v2.2.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 2 years ago mobile.js 2 years ago tablet-only.js 5 years ago tablet.js 2 years ago
main.js
125 lines
1 /* eslint-disable quotes */
2 import buildCSS from '../../../utils/build-css';
3 import hexToRGBA from '../../../utils/hex-to-rgba';
4 import LayoutCSS from '../../../extend/inspector-control/controls/layout/components/LayoutCSS';
5 import SizingCSS from '../../../extend/inspector-control/controls/sizing/components/SizingCSS';
6 import FlexChildCSS from '../../../extend/inspector-control/controls/flex-child-panel/components/FlexChildCSS';
7
8 import {
9 Component,
10 } from '@wordpress/element';
11
12 import {
13 applyFilters,
14 } from '@wordpress/hooks';
15 import SpacingCSS from '../../../extend/inspector-control/controls/spacing/components/SpacingCSS';
16 import { sprintf } from '@wordpress/i18n';
17 import TypographyCSS from '../../../extend/inspector-control/controls/typography/components/TypographyCSS';
18 import BorderCSS, { BorderCSSColor } from '../../../extend/inspector-control/controls/borders/BorderCSS';
19
20 export default class MainCSS extends Component {
21 render() {
22 const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props );
23
24 const {
25 uniqueId,
26 removeText,
27 backgroundColor,
28 backgroundColorOpacity,
29 textColor,
30 backgroundColorHover,
31 backgroundColorHoverOpacity,
32 textColorHover,
33 fontFamilyFallback,
34 gradient,
35 gradientDirection,
36 gradientColorOne,
37 gradientColorOneOpacity,
38 gradientColorStopOne,
39 gradientColorTwo,
40 gradientColorTwoOpacity,
41 gradientColorStopTwo,
42 hasButtonContainer,
43 backgroundColorCurrent,
44 textColorCurrent,
45 iconStyles,
46 } = attributes;
47
48 let backgroundImageValue,
49 gradientColorStopOneValue = '',
50 gradientColorStopTwoValue = '';
51
52 if ( gradient ) {
53 if ( gradientColorOne && '' !== gradientColorStopOne ) {
54 gradientColorStopOneValue = ' ' + gradientColorStopOne + '%';
55 }
56
57 if ( gradientColorTwo && '' !== gradientColorStopTwo ) {
58 gradientColorStopTwoValue = ' ' + gradientColorStopTwo + '%';
59 }
60 }
61
62 if ( gradient ) {
63 backgroundImageValue = 'linear-gradient(' + gradientDirection + 'deg, ' + hexToRGBA( gradientColorOne, gradientColorOneOpacity ) + gradientColorStopOneValue + ', ' + hexToRGBA( gradientColorTwo, gradientColorTwoOpacity ) + gradientColorStopTwoValue + ');';
64 }
65
66 const containerSelector = !! hasButtonContainer ? '.gb-button-wrapper ' : '';
67 let selector = '.gb-button-' + uniqueId;
68 selector = '.editor-styles-wrapper ' + containerSelector + selector;
69
70 let cssObj = [];
71
72 cssObj[ selector ] = [ {
73 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ),
74 'background-image': backgroundImageValue,
75 'color': textColor, // eslint-disable-line quote-props
76 'text-decoration': 'none',
77 } ];
78
79 TypographyCSS( cssObj, selector, { ...attributes.typography, fontFamilyFallback } );
80 SpacingCSS( cssObj, selector, attributes.spacing );
81 BorderCSS( cssObj, selector, attributes.borders );
82 LayoutCSS( cssObj, selector, attributes );
83 SizingCSS( cssObj, selector, attributes );
84 FlexChildCSS( cssObj, selector, attributes );
85
86 const currentSelector = sprintf(
87 '%1$s[data-button-is-current], %1$s[data-button-is-current]:hover, %1$s[data-button-is-current]:active, %1$s[data-button-is-current]:focus',
88 selector
89 );
90
91 cssObj[ currentSelector ] = [ {
92 'background-color': backgroundColorCurrent,
93 color: textColorCurrent,
94 } ];
95
96 BorderCSSColor( cssObj, currentSelector, { ...attributes.borders }, 'Current' );
97
98 cssObj[ selector + ':hover, ' + selector + ':focus, ' + selector + ':active' ] = [ {
99 'background-color': hexToRGBA( backgroundColorHover, backgroundColorHoverOpacity ),
100 'color': textColorHover, // eslint-disable-line quote-props
101 } ];
102
103 BorderCSSColor( cssObj, selector + ':hover, ' + selector + ':focus, ' + selector + ':active', { ...attributes.borders }, 'Hover' );
104
105 cssObj[ selector + ' .gb-icon' ] = [ {
106 'padding-top': ! removeText ? iconStyles?.paddingTop : null,
107 'padding-right': ! removeText ? iconStyles?.paddingRight : null,
108 'padding-bottom': ! removeText ? iconStyles?.paddingBottom : null,
109 'padding-left': ! removeText ? iconStyles?.paddingLeft : null,
110 } ];
111
112 cssObj[ selector + ' .gb-icon svg' ] = [ {
113 width: iconStyles?.width,
114 height: iconStyles?.height,
115 } ];
116
117 cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'button' );
118
119 return (
120 <style>{ buildCSS( cssObj ) }</style>
121 );
122 }
123 }
124 /* eslint-enable quotes */
125