desktop.js
4 years ago
main.js
4 years ago
mobile.js
4 years ago
tablet-only.js
4 years ago
tablet.js
4 years ago
mobile.js
90 lines
| 1 | import buildCSS from '../../../utils/build-css'; |
| 2 | import { applyFilters } from '@wordpress/hooks'; |
| 3 | import shorthandCSS from '../../../utils/shorthand-css'; |
| 4 | |
| 5 | export default function MobileCSS( props ) { |
| 6 | const attributes = applyFilters( 'generateblocks.editor.cssAttrs', props.attributes, props ); |
| 7 | |
| 8 | const { |
| 9 | uniqueId, |
| 10 | paddingTopMobile, |
| 11 | paddingRightMobile, |
| 12 | paddingBottomMobile, |
| 13 | paddingLeftMobile, |
| 14 | paddingUnit, |
| 15 | marginTopMobile, |
| 16 | marginRightMobile, |
| 17 | marginBottomMobile, |
| 18 | marginLeftMobile, |
| 19 | marginUnit, |
| 20 | borderSizeTopMobile, |
| 21 | borderSizeRightMobile, |
| 22 | borderSizeBottomMobile, |
| 23 | borderSizeLeftMobile, |
| 24 | borderRadiusTopRightMobile, |
| 25 | borderRadiusBottomRightMobile, |
| 26 | borderRadiusBottomLeftMobile, |
| 27 | borderRadiusTopLeftMobile, |
| 28 | borderRadiusUnit, |
| 29 | borderColor, |
| 30 | objectFitMobile, |
| 31 | widthMobile, |
| 32 | heightMobile, |
| 33 | alignment, |
| 34 | alignmentTablet, |
| 35 | alignmentMobile, |
| 36 | } = attributes; |
| 37 | |
| 38 | let cssObj = []; |
| 39 | |
| 40 | const floats = { |
| 41 | floatLeft: 'left', |
| 42 | floatRight: 'right', |
| 43 | floatNone: 'none', |
| 44 | }; |
| 45 | |
| 46 | let float = alignmentMobile.startsWith( 'float' ) ? floats[ alignmentMobile ] : null; |
| 47 | |
| 48 | if ( |
| 49 | alignmentMobile && |
| 50 | ! float && |
| 51 | ( |
| 52 | alignmentTablet.startsWith( 'float' ) || |
| 53 | alignment.startsWith( 'float' ) |
| 54 | ) |
| 55 | ) { |
| 56 | // We have a mobile alignment and tablet/desktop is set to float, so let's disable it. |
| 57 | float = 'none'; |
| 58 | } |
| 59 | |
| 60 | cssObj[ '.editor-styles-wrapper .gb-block-image-' + uniqueId ] = [ { |
| 61 | margin: shorthandCSS( marginTopMobile, marginRightMobile, marginBottomMobile, marginLeftMobile, marginUnit ), |
| 62 | padding: shorthandCSS( paddingTopMobile, paddingRightMobile, paddingBottomMobile, paddingLeftMobile, paddingUnit ), |
| 63 | 'text-align': ! alignmentMobile.startsWith( 'float' ) ? alignmentMobile : null, |
| 64 | float, |
| 65 | position: float && 'none' !== float ? 'relative' : null, |
| 66 | 'z-index': float && 'none' !== float ? '22' : null, |
| 67 | } ]; |
| 68 | |
| 69 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId ] = [ { |
| 70 | 'border-radius': shorthandCSS( borderRadiusTopLeftMobile, borderRadiusTopRightMobile, borderRadiusBottomRightMobile, borderRadiusBottomLeftMobile, borderRadiusUnit ), |
| 71 | 'border-color': borderColor, |
| 72 | width: widthMobile, |
| 73 | height: heightMobile, |
| 74 | 'object-fit': objectFitMobile, |
| 75 | } ]; |
| 76 | |
| 77 | if ( borderSizeTopMobile || borderSizeRightMobile || borderSizeBottomMobile || borderSizeLeftMobile ) { |
| 78 | cssObj[ '.editor-styles-wrapper .gb-image-' + uniqueId ].push( { |
| 79 | 'border-width': shorthandCSS( borderSizeTopMobile, borderSizeRightMobile, borderSizeBottomMobile, borderSizeLeftMobile, 'px' ), |
| 80 | 'border-style': 'solid', |
| 81 | } ); |
| 82 | } |
| 83 | |
| 84 | cssObj = applyFilters( 'generateblocks.editor.mobileCSS', cssObj, props, 'image' ); |
| 85 | |
| 86 | return ( |
| 87 | <style>{ buildCSS( cssObj ) }</style> |
| 88 | ); |
| 89 | } |
| 90 |