desktop.js
5 years ago
main.js
5 years ago
mobile.js
5 years ago
tablet-only.js
5 years ago
tablet.js
5 years ago
main.js
163 lines
| 1 | import buildCSS from '../../../utils/build-css'; |
| 2 | import flexboxAlignment from '../../../utils/flexbox-alignment'; |
| 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 | clientId, |
| 21 | } = this.props; |
| 22 | |
| 23 | const { |
| 24 | uniqueId, |
| 25 | element, |
| 26 | alignment, |
| 27 | backgroundColor, |
| 28 | backgroundColorOpacity, |
| 29 | textColor, |
| 30 | linkColor, |
| 31 | borderColor, |
| 32 | borderColorOpacity, |
| 33 | highlightTextColor, |
| 34 | fontFamily, |
| 35 | fontFamilyFallback, |
| 36 | fontWeight, |
| 37 | fontSize, |
| 38 | fontSizeUnit, |
| 39 | textTransform, |
| 40 | lineHeight, |
| 41 | lineHeightUnit, |
| 42 | letterSpacing, |
| 43 | marginTop, |
| 44 | marginRight, |
| 45 | marginBottom, |
| 46 | marginLeft, |
| 47 | marginUnit, |
| 48 | paddingTop, |
| 49 | paddingRight, |
| 50 | paddingBottom, |
| 51 | paddingLeft, |
| 52 | paddingUnit, |
| 53 | borderSizeTop, |
| 54 | borderSizeRight, |
| 55 | borderSizeBottom, |
| 56 | borderSizeLeft, |
| 57 | borderRadiusTopRight, |
| 58 | borderRadiusBottomRight, |
| 59 | borderRadiusBottomLeft, |
| 60 | borderRadiusTopLeft, |
| 61 | borderRadiusUnit, |
| 62 | icon, |
| 63 | iconColor, |
| 64 | iconColorOpacity, |
| 65 | iconLocation, |
| 66 | iconVerticalAlignment, |
| 67 | iconPaddingTop, |
| 68 | iconPaddingRight, |
| 69 | iconPaddingBottom, |
| 70 | iconPaddingLeft, |
| 71 | iconPaddingUnit, |
| 72 | iconSize, |
| 73 | iconSizeUnit, |
| 74 | inlineWidth, |
| 75 | removeText, |
| 76 | } = attributes; |
| 77 | |
| 78 | let fontFamilyFallbackValue = '', |
| 79 | inlineWidthValue = 'inline-block'; |
| 80 | |
| 81 | if ( fontFamily && fontFamilyFallback ) { |
| 82 | fontFamilyFallbackValue = ', ' + fontFamilyFallback; |
| 83 | } |
| 84 | |
| 85 | const selector = element + '.gb-headline-' + uniqueId; |
| 86 | |
| 87 | let cssObj = []; |
| 88 | |
| 89 | cssObj[ '.editor-styles-wrapper ' + selector ] = [ { |
| 90 | color: textColor, |
| 91 | 'font-family': fontFamily + fontFamilyFallbackValue, |
| 92 | 'font-weight': fontWeight, |
| 93 | 'text-transform': textTransform, |
| 94 | 'text-align': alignment, |
| 95 | 'font-size': valueWithUnit( fontSize, fontSizeUnit ), |
| 96 | 'line-height': valueWithUnit( lineHeight, lineHeightUnit ), |
| 97 | 'letter-spacing': valueWithUnit( letterSpacing, 'em' ), |
| 98 | display: !! icon ? 'flex' : false, |
| 99 | 'align-items': 'inline' === iconLocation ? flexboxAlignment( iconVerticalAlignment ) : flexboxAlignment( alignment ), |
| 100 | 'justify-content': flexboxAlignment( alignment ), |
| 101 | 'flex-direction': icon && 'above' === iconLocation ? 'column' : false, |
| 102 | } ]; |
| 103 | |
| 104 | cssObj[ '.editor-styles-wrapper .gb-container ' + selector ] = [ { |
| 105 | color: textColor, |
| 106 | } ]; |
| 107 | |
| 108 | if ( icon ) { |
| 109 | inlineWidthValue = 'inline-flex'; |
| 110 | } |
| 111 | |
| 112 | cssObj[ '.editor-styles-wrapper ' + selector ].push( { |
| 113 | 'background-color': hexToRGBA( backgroundColor, backgroundColorOpacity ), |
| 114 | 'color': textColor, // eslint-disable-line quote-props |
| 115 | 'display': inlineWidth ? inlineWidthValue : false, // eslint-disable-line quote-props |
| 116 | 'margin-top': valueWithUnit( marginTop, marginUnit ), |
| 117 | 'margin-right': valueWithUnit( marginRight, marginUnit ), |
| 118 | 'margin-bottom': valueWithUnit( marginBottom, marginUnit ), |
| 119 | 'margin-left': valueWithUnit( marginLeft, marginUnit ), |
| 120 | 'padding': shorthandCSS( paddingTop, paddingRight, paddingBottom, paddingLeft, paddingUnit ), // eslint-disable-line quote-props |
| 121 | 'border-radius': shorthandCSS( borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomRight, borderRadiusBottomLeft, borderRadiusUnit ), |
| 122 | 'border-color': hexToRGBA( borderColor, borderColorOpacity ), |
| 123 | } ); |
| 124 | |
| 125 | if ( borderSizeTop || borderSizeRight || borderSizeBottom || borderSizeLeft ) { |
| 126 | cssObj[ '.editor-styles-wrapper ' + selector ].push( { |
| 127 | 'border-width': shorthandCSS( borderSizeTop, borderSizeRight, borderSizeBottom, borderSizeLeft, 'px' ), |
| 128 | 'border-style': 'solid', |
| 129 | } ); |
| 130 | } |
| 131 | |
| 132 | cssObj[ '.editor-styles-wrapper ' + selector + ' a' ] = [ { |
| 133 | 'color': linkColor, // eslint-disable-line quote-props |
| 134 | } ]; |
| 135 | |
| 136 | cssObj[ selector + ' .gb-icon' ] = [ { |
| 137 | 'padding': ! removeText ? shorthandCSS( iconPaddingTop, iconPaddingRight, iconPaddingBottom, iconPaddingLeft, iconPaddingUnit ) : false, // eslint-disable-line quote-props |
| 138 | 'align-self': icon && 'above' === iconLocation ? flexboxAlignment( alignment ) : false, |
| 139 | 'color': hexToRGBA( iconColor, iconColorOpacity ), // eslint-disable-line quote-props |
| 140 | 'display': icon && 'above' === iconLocation ? 'inline' : false, // eslint-disable-line quote-props |
| 141 | } ]; |
| 142 | |
| 143 | cssObj[ selector + ' .gb-icon svg' ] = [ { |
| 144 | 'width': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props |
| 145 | 'height': valueWithUnit( iconSize, iconSizeUnit ), // eslint-disable-line quote-props |
| 146 | } ]; |
| 147 | |
| 148 | cssObj[ selector + ' .gb-highlight' ] = [ { |
| 149 | 'color': highlightTextColor, // eslint-disable-line quote-props |
| 150 | } ]; |
| 151 | |
| 152 | cssObj[ '#block-' + clientId ] = [ { |
| 153 | 'display': inlineWidth ? 'inline-flex' : false, // eslint-disable-line quote-props |
| 154 | } ]; |
| 155 | |
| 156 | cssObj = applyFilters( 'generateblocks.editor.mainCSS', cssObj, this.props, 'headline' ); |
| 157 | |
| 158 | return ( |
| 159 | <style>{ buildCSS( cssObj ) }</style> |
| 160 | ); |
| 161 | } |
| 162 | } |
| 163 |