desktop.js
5 years ago
main.js
3 years ago
mobile.js
3 years ago
tablet-only.js
5 years ago
tablet.js
3 years ago
main.js
166 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 | import LayoutCSS from '../../../extend/inspector-control/controls/layout/components/LayoutCSS'; |
| 7 | import SizingCSS from '../../../extend/inspector-control/controls/sizing/components/SizingCSS'; |
| 8 | import FlexChildCSS from '../../../extend/inspector-control/controls/flex-child-panel/components/FlexChildCSS'; |
| 9 | |
| 10 | import { |
| 11 | Component, |
| 12 | } from '@wordpress/element'; |
| 13 | |
| 14 | import { |
| 15 | applyFilters, |
| 16 | } from '@wordpress/hooks'; |
| 17 | import SpacingCSS from '../../../extend/inspector-control/controls/spacing/components/SpacingCSS'; |
| 18 | import { sprintf } from '@wordpress/i18n'; |
| 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 | fontFamily, |
| 34 | fontFamilyFallback, |
| 35 | fontWeight, |
| 36 | textTransform, |
| 37 | letterSpacing, |
| 38 | fontSize, |
| 39 | fontSizeUnit, |
| 40 | paddingTop, |
| 41 | paddingRight, |
| 42 | paddingBottom, |
| 43 | paddingLeft, |
| 44 | paddingUnit, |
| 45 | borderSizeTop, |
| 46 | borderSizeRight, |
| 47 | borderSizeBottom, |
| 48 | borderSizeLeft, |
| 49 | borderRadiusTopRight, |
| 50 | borderRadiusBottomRight, |
| 51 | borderRadiusBottomLeft, |
| 52 | borderRadiusTopLeft, |
| 53 | borderRadiusUnit, |
| 54 | borderColor, |
| 55 | borderColorOpacity, |
| 56 | borderColorHover, |
| 57 | borderColorHoverOpacity, |
| 58 | gradient, |
| 59 | gradientDirection, |
| 60 | gradientColorOne, |
| 61 | gradientColorOneOpacity, |
| 62 | gradientColorStopOne, |
| 63 | gradientColorTwo, |
| 64 | gradientColorTwoOpacity, |
| 65 | gradientColorStopTwo, |
| 66 | iconPaddingTop, |
| 67 | iconPaddingRight, |
| 68 | iconPaddingBottom, |
| 69 | iconPaddingLeft, |
| 70 | iconPaddingUnit, |
| 71 | iconSize, |
| 72 | iconSizeUnit, |
| 73 | hasButtonContainer, |
| 74 | alignment, |
| 75 | backgroundColorCurrent, |
| 76 | textColorCurrent, |
| 77 | borderColorCurrent, |
| 78 | } = attributes; |
| 79 | |
| 80 | let fontFamilyFallbackValue = '', |
| 81 | backgroundImageValue, |
| 82 | gradientColorStopOneValue = '', |
| 83 | gradientColorStopTwoValue = ''; |
| 84 | |
| 85 | if ( gradient ) { |
| 86 | if ( gradientColorOne && '' !== gradientColorStopOne ) { |
| 87 | gradientColorStopOneValue = ' ' + gradientColorStopOne + '%'; |
| 88 | } |
| 89 | |
| 90 | if ( gradientColorTwo && '' !== gradientColorStopTwo ) { |
| 91 | gradientColorStopTwoValue = ' ' + gradientColorStopTwo + '%'; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if ( gradient ) { |
| 96 | backgroundImageValue = 'linear-gradient(' + gradientDirection + 'deg, ' + hexToRGBA( gradientColorOne, gradientColorOneOpacity ) + gradientColorStopOneValue + ', ' + hexToRGBA( gradientColorTwo, gradientColorTwoOpacity ) + gradientColorStopTwoValue + ');'; |
| 97 | } |
| 98 | |
| 99 | if ( fontFamily && fontFamilyFallback ) { |
| 100 | fontFamilyFallbackValue = ', ' + fontFamilyFallback; |
| 101 | } |
| 102 | |
| 103 | const containerSelector = !! hasButtonContainer ? '.gb-button-wrapper ' : ''; |
| 104 | let selector = '.gb-button-' + uniqueId; |
| 105 | selector = '.editor-styles-wrapper ' + containerSelector + selector; |
| 106 | |
| 107 | let cssObj = []; |
| 108 | |
| 109 | cssObj[ selector ] = [ { |
| 110 | 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ), |
| 111 | 'background-image': backgroundImageValue, |
| 112 | 'color': textColor, // eslint-disable-line quote-props |
| 113 | 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props |
| 114 | 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ), |
| 115 | 'font-family': fontFamily + fontFamilyFallbackValue, |
| 116 | 'font-weight': fontWeight, |
| 117 | 'text-transform': textTransform, |
| 118 | 'font-size': valueWithUnit( fontSize, fontSizeUnit ), |
| 119 | 'text-align': alignment, |
| 120 | 'letter-spacing': valueWithUnit( letterSpacing, 'em' ), |
| 121 | 'border-color': hexToRGBA( borderColor, borderColorOpacity ), |
| 122 | } ]; |
| 123 | |
| 124 | SpacingCSS( cssObj, selector, attributes ); |
| 125 | LayoutCSS( cssObj, selector, attributes ); |
| 126 | SizingCSS( cssObj, selector, attributes ); |
| 127 | FlexChildCSS( cssObj, selector, attributes ); |
| 128 | |
| 129 | if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) { |
| 130 | cssObj[ selector ].push( { |
| 131 | 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ), |
| 132 | 'border-style': 'solid', |
| 133 | } ); |
| 134 | } |
| 135 | |
| 136 | const currentSelector = sprintf( |
| 137 | '%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', |
| 138 | selector |
| 139 | ); |
| 140 | |
| 141 | cssObj[ currentSelector ] = [ { |
| 142 | 'background-color': backgroundColorCurrent, |
| 143 | color: textColorCurrent, |
| 144 | 'border-color': borderColorCurrent, |
| 145 | } ]; |
| 146 | |
| 147 | cssObj[ selector + ':hover, ' + selector + ':focus, ' + selector + ':active' ] = [ { |
| 148 | 'background-color': hexToRGBA( backgroundColorHover, backgroundColorHoverOpacity ), |
| 149 | 'color': textColorHover, // eslint-disable-line quote-props |
| 150 | 'border-color': hexToRGBA( borderColorHover, borderColorHoverOpacity ), |
| 151 | } ]; |
| 152 | |
| 153 | cssObj[ selector + ' .gb-icon' ] = [ { |
| 154 | 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props |
| 155 | 'font-size': valueWithUnit( iconSize, iconSizeUnit ), |
| 156 | } ]; |
| 157 | |
| 158 | cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'button' ); |
| 159 | |
| 160 | return ( |
| 161 | <style>{ buildCSS( cssObj ) }</style> |
| 162 | ); |
| 163 | } |
| 164 | } |
| 165 | /* eslint-enable quotes */ |
| 166 |