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
148 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 = '.editor-styles-wrapper .gb-button-wrapper a.gb-button-' + uniqueId; |
| 100 | |
| 101 | if ( ! url ) { |
| 102 | selector = '.editor-styles-wrapper .gb-button-wrapper .gb-button-' + uniqueId; |
| 103 | } |
| 104 | |
| 105 | let cssObj = []; |
| 106 | |
| 107 | cssObj[ 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[ selector ].push( { |
| 124 | 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ), |
| 125 | 'border-style': 'solid', |
| 126 | } ); |
| 127 | } |
| 128 | |
| 129 | cssObj[ selector + ':hover, ' + selector + ':focus, ' + selector + ':active' ] = [ { |
| 130 | 'background-color': hexToRGBA( backgroundColorHover, backgroundColorHoverOpacity ), |
| 131 | 'color': textColorHover, // eslint-disable-line quote-props |
| 132 | 'border-color': hexToRGBA( borderColorHover, borderColorHoverOpacity ), |
| 133 | } ]; |
| 134 | |
| 135 | cssObj[ selector + ' .gb-icon' ] = [ { |
| 136 | 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props |
| 137 | 'font-size': valueWithUnit( iconSize, iconSizeUnit ), |
| 138 | } ]; |
| 139 | |
| 140 | cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'button' ); |
| 141 | |
| 142 | return ( |
| 143 | <style>{ buildCSS( cssObj ) }</style> |
| 144 | ); |
| 145 | } |
| 146 | } |
| 147 | /* eslint-enable quotes */ |
| 148 |