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
124 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 | } ]; |
| 77 | |
| 78 | TypographyCSS( cssObj, selector, { ...attributes.typography, fontFamilyFallback } ); |
| 79 | SpacingCSS( cssObj, selector, attributes.spacing ); |
| 80 | BorderCSS( cssObj, selector, attributes.borders ); |
| 81 | LayoutCSS( cssObj, selector, attributes ); |
| 82 | SizingCSS( cssObj, selector, attributes ); |
| 83 | FlexChildCSS( cssObj, selector, attributes ); |
| 84 | |
| 85 | const currentSelector = sprintf( |
| 86 | '%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', |
| 87 | selector |
| 88 | ); |
| 89 | |
| 90 | cssObj[ currentSelector ] = [ { |
| 91 | 'background-color': backgroundColorCurrent, |
| 92 | color: textColorCurrent, |
| 93 | } ]; |
| 94 | |
| 95 | BorderCSSColor( cssObj, currentSelector, { ...attributes.borders }, 'Current' ); |
| 96 | |
| 97 | cssObj[ selector + ':hover, ' + selector + ':focus, ' + selector + ':active' ] = [ { |
| 98 | 'background-color': hexToRGBA( backgroundColorHover, backgroundColorHoverOpacity ), |
| 99 | 'color': textColorHover, // eslint-disable-line quote-props |
| 100 | } ]; |
| 101 | |
| 102 | BorderCSSColor( cssObj, selector + ':hover, ' + selector + ':focus, ' + selector + ':active', { ...attributes.borders }, 'Hover' ); |
| 103 | |
| 104 | cssObj[ selector + ' .gb-icon' ] = [ { |
| 105 | 'padding-top': ! removeText ? iconStyles?.paddingTop : null, |
| 106 | 'padding-right': ! removeText ? iconStyles?.paddingRight : null, |
| 107 | 'padding-bottom': ! removeText ? iconStyles?.paddingBottom : null, |
| 108 | 'padding-left': ! removeText ? iconStyles?.paddingLeft : null, |
| 109 | } ]; |
| 110 | |
| 111 | cssObj[ selector + ' .gb-icon svg' ] = [ { |
| 112 | width: iconStyles?.width, |
| 113 | height: iconStyles?.height, |
| 114 | } ]; |
| 115 | |
| 116 | cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'button' ); |
| 117 | |
| 118 | return ( |
| 119 | <style>{ buildCSS( cssObj ) }</style> |
| 120 | ); |
| 121 | } |
| 122 | } |
| 123 | /* eslint-enable quotes */ |
| 124 |