generateCSS.js
| 1 | function generateCSS( |
| 2 | selectorsObj, |
| 3 | id, |
| 4 | isResponsive = false, // eslint-disable-line no-unused-vars |
| 5 | responsiveType = '' // eslint-disable-line no-unused-vars |
| 6 | ) { |
| 7 | let gen_styling_css = ''; |
| 8 | |
| 9 | for ( const selector in selectorsObj ) { |
| 10 | const cssProps = selectorsObj[ selector ]; |
| 11 | let css = ''; |
| 12 | |
| 13 | for ( const property in cssProps ) { |
| 14 | if ( |
| 15 | typeof cssProps[ property ] === 'undefined' || |
| 16 | cssProps[ property ] === null || |
| 17 | cssProps[ property ]?.length === 0 |
| 18 | ) { |
| 19 | continue; |
| 20 | } |
| 21 | |
| 22 | const propertyValue = cssProps[ property ]; |
| 23 | |
| 24 | if ( 'font-family' === property && 'Default' === propertyValue ) { |
| 25 | continue; |
| 26 | } |
| 27 | |
| 28 | if ( 'font-family' === property ) { |
| 29 | css += property + ': ' + "'" + propertyValue + "'" + ';'; |
| 30 | } else { |
| 31 | css += property + ': ' + propertyValue + ';'; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | if ( css.length !== 0 ) { |
| 36 | if ( responsiveType === 'tablet' ) { |
| 37 | gen_styling_css += |
| 38 | '@media only screen and (max-width: ' + |
| 39 | srfm_blocks_info.tablet_breakpoint + |
| 40 | 'px) {'; |
| 41 | gen_styling_css += id; |
| 42 | gen_styling_css += selector + '{'; |
| 43 | gen_styling_css += css; |
| 44 | gen_styling_css += '}}'; |
| 45 | } else if ( responsiveType === 'mobile' ) { |
| 46 | gen_styling_css += |
| 47 | '@media only screen and (max-width: ' + |
| 48 | srfm_blocks_info.mobile_breakpoint + |
| 49 | 'px) {'; |
| 50 | gen_styling_css += id; |
| 51 | gen_styling_css += selector + '{'; |
| 52 | gen_styling_css += css; |
| 53 | gen_styling_css += '}}'; |
| 54 | } else { |
| 55 | gen_styling_css += id; |
| 56 | gen_styling_css += selector + '{'; |
| 57 | gen_styling_css += css; |
| 58 | gen_styling_css += '}'; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return gen_styling_css; |
| 64 | } |
| 65 | |
| 66 | export default generateCSS; |
| 67 |