desktop.js
4 years ago
main.js
3 years ago
mobile.js
3 years ago
tablet-only.js
4 years ago
tablet.js
3 years ago
mobile.js
180 lines
| 1 | /* eslint-disable quotes */ |
| 2 | import buildCSS from '../../../utils/build-css'; |
| 3 | import valueWithUnit from '../../../utils/value-with-unit'; |
| 4 | import LayoutCSS from '../../../extend/inspector-control/controls/layout/components/LayoutCSS'; |
| 5 | import FlexChildCSS from '../../../extend/inspector-control/controls/flex-child-panel/components/FlexChildCSS'; |
| 6 | import SpacingCSS from '../../../extend/inspector-control/controls/spacing/components/SpacingCSS'; |
| 7 | |
| 8 | import { |
| 9 | Component, |
| 10 | } from '@wordpress/element'; |
| 11 | |
| 12 | import { |
| 13 | applyFilters, |
| 14 | } from '@wordpress/hooks'; |
| 15 | import sizingValue from '../../../utils/sizingValue'; |
| 16 | import SizingCSS from '../../../extend/inspector-control/controls/sizing/components/SizingCSS'; |
| 17 | |
| 18 | export default class MobileCSS extends Component { |
| 19 | render() { |
| 20 | const attributes = applyFilters( 'generateblocks.editor.cssAttrs', this.props.attributes, this.props ); |
| 21 | |
| 22 | const { |
| 23 | uniqueId, |
| 24 | isGrid, |
| 25 | flexGrowMobile, |
| 26 | flexShrinkMobile, |
| 27 | flexBasisMobile, |
| 28 | paddingTopMobile, |
| 29 | paddingRightMobile, |
| 30 | paddingBottomMobile, |
| 31 | paddingLeftMobile, |
| 32 | paddingUnit, |
| 33 | borderSizeTopMobile, |
| 34 | borderSizeRightMobile, |
| 35 | borderSizeBottomMobile, |
| 36 | borderSizeLeftMobile, |
| 37 | borderRadiusTopRightMobile, |
| 38 | borderRadiusBottomRightMobile, |
| 39 | borderRadiusBottomLeftMobile, |
| 40 | borderRadiusTopLeftMobile, |
| 41 | borderRadiusUnit, |
| 42 | verticalAlignmentMobile, |
| 43 | removeVerticalGapMobile, |
| 44 | alignmentMobile, |
| 45 | fontSizeMobile, |
| 46 | fontSizeUnit, |
| 47 | orderMobile, |
| 48 | shapeDividers, |
| 49 | bgImage, |
| 50 | bgOptions, |
| 51 | gridId, |
| 52 | useInnerContainer, |
| 53 | sizing, |
| 54 | } = attributes; |
| 55 | |
| 56 | let cssObj = []; |
| 57 | cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ] = [ { |
| 58 | 'border-top-left-radius': valueWithUnit( borderRadiusTopLeftMobile, borderRadiusUnit ), |
| 59 | 'border-top-right-radius': valueWithUnit( borderRadiusTopRightMobile, borderRadiusUnit ), |
| 60 | 'border-bottom-right-radius': valueWithUnit( borderRadiusBottomRightMobile, borderRadiusUnit ), |
| 61 | 'border-bottom-left-radius': valueWithUnit( borderRadiusBottomLeftMobile, borderRadiusUnit ), |
| 62 | 'text-align': alignmentMobile, |
| 63 | 'font-size': valueWithUnit( fontSizeMobile, fontSizeUnit ), |
| 64 | } ]; |
| 65 | |
| 66 | SpacingCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' ); |
| 67 | SizingCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' ); |
| 68 | LayoutCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' ); |
| 69 | FlexChildCSS( cssObj, '.editor-styles-wrapper .gb-container-' + uniqueId, attributes, 'Mobile' ); |
| 70 | |
| 71 | if ( ! useInnerContainer ) { |
| 72 | cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( { |
| 73 | 'padding-top': valueWithUnit( paddingTopMobile, paddingUnit ), |
| 74 | 'padding-right': valueWithUnit( paddingRightMobile, paddingUnit ), |
| 75 | 'padding-bottom': valueWithUnit( paddingBottomMobile, paddingUnit ), |
| 76 | 'padding-left': valueWithUnit( paddingLeftMobile, paddingUnit ), |
| 77 | } ); |
| 78 | } |
| 79 | |
| 80 | if ( borderSizeTopMobile || borderSizeRightMobile || borderSizeBottomMobile || borderSizeLeftMobile ) { |
| 81 | cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( { |
| 82 | 'border-top-width': valueWithUnit( borderSizeTopMobile, 'px' ), |
| 83 | 'border-right-width': valueWithUnit( borderSizeRightMobile, 'px' ), |
| 84 | 'border-bottom-width': valueWithUnit( borderSizeBottomMobile, 'px' ), |
| 85 | 'border-left-width': valueWithUnit( borderSizeLeftMobile, 'px' ), |
| 86 | 'border-style': 'solid', |
| 87 | } ); |
| 88 | } |
| 89 | |
| 90 | if ( useInnerContainer ) { |
| 91 | cssObj[ '.gb-container-' + uniqueId + ' > .gb-inside-container' ] = [ { |
| 92 | 'padding-top': valueWithUnit( paddingTopMobile, paddingUnit ), |
| 93 | 'padding-right': valueWithUnit( paddingRightMobile, paddingUnit ), |
| 94 | 'padding-bottom': valueWithUnit( paddingBottomMobile, paddingUnit ), |
| 95 | 'padding-left': valueWithUnit( paddingLeftMobile, paddingUnit ), |
| 96 | 'width': sizingValue( 'minHeightMobile', sizing ) && ! isGrid ? '100%' : false, // eslint-disable-line quote-props |
| 97 | } ]; |
| 98 | |
| 99 | if ( 'inherit' !== verticalAlignmentMobile && sizingValue( 'minHeightMobile', sizing ) && ! isGrid ) { |
| 100 | cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( { |
| 101 | 'display': 'flex', // eslint-disable-line quote-props |
| 102 | 'flex-direction': 'row', |
| 103 | 'align-items': verticalAlignmentMobile, |
| 104 | } ); |
| 105 | } |
| 106 | |
| 107 | if ( isGrid && 'inherit' !== verticalAlignmentMobile ) { |
| 108 | cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( { |
| 109 | 'display': 'flex', // eslint-disable-line quote-props |
| 110 | 'flex-direction': 'column', |
| 111 | 'height': '100%', // eslint-disable-line quote-props |
| 112 | 'justify-content': verticalAlignmentMobile, |
| 113 | } ); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if ( isGrid ) { |
| 118 | const gridColumnSelectors = [ |
| 119 | '.gb-post-template-' + gridId + ' > .gb-post-template-wrapper > .block-editor-inner-blocks', |
| 120 | '.gb-grid-wrapper > .block-editor-inner-blocks > .block-editor-block-list__layout > .gb-grid-column-' + uniqueId, |
| 121 | ]; |
| 122 | |
| 123 | cssObj[ gridColumnSelectors.join( ',' ) ] = [ { |
| 124 | width: sizingValue( 'widthMobile', sizing ), |
| 125 | 'flex-grow': flexGrowMobile, |
| 126 | 'flex-shrink': flexShrinkMobile, |
| 127 | 'flex-basis': flexBasisMobile, |
| 128 | 'order': orderMobile, // eslint-disable-line quote-props |
| 129 | } ]; |
| 130 | } |
| 131 | |
| 132 | if ( removeVerticalGapMobile ) { |
| 133 | cssObj[ '.gb-grid-column-' + uniqueId ] = [ { |
| 134 | 'margin-bottom': '0px !important', |
| 135 | } ]; |
| 136 | } |
| 137 | |
| 138 | if ( !! bgImage && 'pseudo-element' === bgOptions.selector ) { |
| 139 | cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ { |
| 140 | 'border-top-left-radius': valueWithUnit( borderRadiusTopLeftMobile, borderRadiusUnit ), |
| 141 | 'border-top-right-radius': valueWithUnit( borderRadiusTopRightMobile, borderRadiusUnit ), |
| 142 | 'border-bottom-right-radius': valueWithUnit( borderRadiusBottomRightMobile, borderRadiusUnit ), |
| 143 | 'border-bottom-left-radius': valueWithUnit( borderRadiusBottomLeftMobile, borderRadiusUnit ), |
| 144 | } ]; |
| 145 | } |
| 146 | |
| 147 | if ( shapeDividers.length ) { |
| 148 | shapeDividers.forEach( ( location, index ) => { |
| 149 | const shapeNumber = index + 1; |
| 150 | |
| 151 | cssObj[ '.gb-container-' + uniqueId + ' > .gb-shapes .gb-shape-' + shapeNumber + ' svg' ] = [ { |
| 152 | height: valueWithUnit( shapeDividers[ index ].heightMobile, 'px' ), |
| 153 | width: valueWithUnit( shapeDividers[ index ].widthMobile, '%' ), |
| 154 | } ]; |
| 155 | } ); |
| 156 | } |
| 157 | |
| 158 | if ( !! bgImage && 'fixed' === bgOptions.attachment ) { |
| 159 | if ( 'element' === bgOptions.selector ) { |
| 160 | cssObj[ '.editor-styles-wrapper .gb-container-' + uniqueId ].push( { |
| 161 | 'background-attachment': 'initial', |
| 162 | } ); |
| 163 | } |
| 164 | |
| 165 | if ( 'pseudo-element' === bgOptions.selector ) { |
| 166 | cssObj[ '.gb-container-' + uniqueId + ':before' ] = [ { |
| 167 | 'background-attachment': 'initial', |
| 168 | } ]; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | cssObj = applyFilters( 'generateblocks.editor.mobileCSS', cssObj, this.props, 'container' ); |
| 173 | |
| 174 | return ( |
| 175 | <style>{ buildCSS( cssObj ) }</style> |
| 176 | ); |
| 177 | } |
| 178 | } |
| 179 | /* eslint-enable quotes */ |
| 180 |