| 1 |
import sharedDynamicCss from "../shared/dynamicCss"; |
| 2 |
import { |
| 3 |
convertToClassName, |
| 4 |
isEmptyObject, |
| 5 |
objectToCssString, |
| 6 |
removeEmptyCss, |
| 7 |
removeEmptyValues, |
| 8 |
spacingGenerate, |
| 9 |
wrapInMediaQuery, |
| 10 |
} from "../shared/helpFn"; |
| 11 |
|
| 12 |
const cacheCss = { desktop: "", mobile: "", tablet: "" }; |
| 13 |
const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => { |
| 14 |
const { |
| 15 |
uniqueId, |
| 16 |
gridThreeHorizontalGap, |
| 17 |
gridThreeVerticalGap, |
| 18 |
gridThreeColumns, |
| 19 |
largeItemHeight, |
| 20 |
smallItemHeight, |
| 21 |
largeItemTitleTypography, |
| 22 |
largeItemTitleFontSize, |
| 23 |
largeItemTitleLatterSpacing, |
| 24 |
largeItemTitleLineHeight, |
| 25 |
equalHeightEnable, |
| 26 |
contentAreaPadding, |
| 27 |
titleFontSize, |
| 28 |
titleLatterSpacing, |
| 29 |
titleLineHeight, |
| 30 |
catTabCategoryMargin, |
| 31 |
largeItemTitleWordSpacing, |
| 32 |
titleWordSpacing, |
| 33 |
globalBreakPointData, |
| 34 |
} = attributes; |
| 35 |
|
| 36 |
const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page); |
| 37 |
|
| 38 |
const largeItemTitleClass = `#${uniqueId} .sp-smart-post-static-grid-contents.grid-three-layout-one .sp-smart-post-card .sp-smart-post-card-content .sp-smart-post-title, #${uniqueId} .sp-smart-post-dynamic-grid-contents.grid-three-layout-four .sp-smart-post-card:nth-child(4n + 1) .sp-smart-post-card-content .sp-smart-post-title, #${uniqueId} .sp-smart-post-dynamic-grid-contents.grid-three-layout-four .sp-smart-post-card:nth-child(4n + 4) .sp-smart-post-card-content .sp-smart-post-title, #${uniqueId} .sp-smart-post-static-grid-contents.grid-three-layout-two .sp-smart-post-card:first-child .sp-smart-post-card-content .sp-smart-post-title, #${uniqueId} .sp-smart-post-static-grid-contents.grid-three-layout-three .sp-smart-post-card:first-child .sp-smart-post-card-content .sp-smart-post-title, #${uniqueId} .sp-smart-post-static-grid-contents.grid-three-layout-five .sp-smart-post-card:first-child .sp-smart-post-card-content .sp-smart-post-title`; |
| 39 |
|
| 40 |
const responsiveCss = (deviceType) => { |
| 41 |
return [ |
| 42 |
{ |
| 43 |
class: `.sp-h-gap-${convertToClassName( |
| 44 |
gridThreeHorizontalGap.device.Desktop + gridThreeHorizontalGap.unit.Desktop |
| 45 |
)}`, |
| 46 |
property: "column-gap", |
| 47 |
value: gridThreeHorizontalGap.device?.[deviceType] + gridThreeHorizontalGap.unit?.[deviceType], |
| 48 |
}, |
| 49 |
{ |
| 50 |
class: `.sp-v-gap-${convertToClassName( |
| 51 |
gridThreeVerticalGap.device.Desktop + gridThreeVerticalGap.unit.Desktop |
| 52 |
)}`, |
| 53 |
property: "row-gap", |
| 54 |
value: gridThreeVerticalGap.device?.[deviceType] + gridThreeVerticalGap.unit?.[deviceType], |
| 55 |
}, |
| 56 |
{ |
| 57 |
class: `#${uniqueId} .sp-smart-post-grid-three-contents:has(.sp-smart-post-static-grid-contents .sp-smart-post-card)`, |
| 58 |
styles: { |
| 59 |
display: "grid", |
| 60 |
"row-gap": gridThreeVerticalGap.device?.[deviceType] + gridThreeVerticalGap.unit?.[deviceType], |
| 61 |
}, |
| 62 |
}, |
| 63 |
{ |
| 64 |
class: `#${uniqueId} .sp-smart-post-grid-three-contents .sp-smart-post-dynamic-grid-contents:not(.grid-three-layout-four):not(.grid-three-layout-five)`, |
| 65 |
styles: { |
| 66 |
"grid-template-columns": `repeat(${ |
| 67 |
gridThreeColumns.device?.[deviceType] ? gridThreeColumns.device?.[deviceType] : 3 |
| 68 |
}, 1fr)`, |
| 69 |
}, |
| 70 |
}, |
| 71 |
{ |
| 72 |
class: `#${uniqueId} .sp-smart-post-grid-three-contents .sp-smart-post-dynamic-grid-contents.grid-three-layout-five`, |
| 73 |
styles: { |
| 74 |
"grid-template-columns": `repeat(${ |
| 75 |
gridThreeColumns.device?.[deviceType] ? gridThreeColumns.device?.[deviceType] : 2 |
| 76 |
}, 1fr)`, |
| 77 |
}, |
| 78 |
}, |
| 79 |
{ |
| 80 |
class: `#${uniqueId} .sp-smart-post-grid-three-contents .sp-smart-post-dynamic-grid-contents.grid-three-layout-four`, |
| 81 |
styles: { |
| 82 |
"grid-template-columns": `repeat( 3, 1fr)`, |
| 83 |
}, |
| 84 |
}, |
| 85 |
{ |
| 86 |
class: `#${uniqueId} .sp-smart-post-static-grid-contents`, |
| 87 |
styles: { |
| 88 |
"column-gap": `${gridThreeHorizontalGap.device?.[deviceType]}${gridThreeHorizontalGap.unit?.[deviceType]}`, |
| 89 |
"row-gap": `${gridThreeVerticalGap.device?.[deviceType]}${gridThreeVerticalGap.unit?.[deviceType]}`, |
| 90 |
}, |
| 91 |
}, |
| 92 |
{ |
| 93 |
class: `#${uniqueId} .sp-smart-post-dynamic-grid-contents`, |
| 94 |
styles: { |
| 95 |
"column-gap": `${gridThreeHorizontalGap.device?.[deviceType]}${gridThreeHorizontalGap.unit?.[deviceType]}`, |
| 96 |
"row-gap": `${gridThreeVerticalGap.device?.[deviceType]}${gridThreeVerticalGap.unit?.[deviceType]}`, |
| 97 |
}, |
| 98 |
}, |
| 99 |
{ |
| 100 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-static-grid-contents:not(.grid-three-layout-four)`, |
| 101 |
styles: { |
| 102 |
height: `${largeItemHeight.device?.[deviceType]}${largeItemHeight.unit?.[deviceType]}`, |
| 103 |
}, |
| 104 |
}, |
| 105 |
{ |
| 106 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-dynamic-grid-contents .sp-smart-post-card`, |
| 107 |
styles: { |
| 108 |
"min-height": equalHeightEnable |
| 109 |
? "auto" |
| 110 |
: `${smallItemHeight.device?.[deviceType]}${smallItemHeight.unit?.[deviceType]}`, |
| 111 |
}, |
| 112 |
}, |
| 113 |
{ |
| 114 |
class: `${largeItemTitleClass}`, |
| 115 |
styles: { |
| 116 |
"font-size": `${largeItemTitleFontSize.device?.[deviceType]}${largeItemTitleFontSize.unit?.[deviceType]} !important`, |
| 117 |
"letter-spacing": `${largeItemTitleLatterSpacing.device?.[deviceType]}${largeItemTitleLatterSpacing.unit?.[deviceType]}`, |
| 118 |
"word-spacing": `${largeItemTitleWordSpacing.device?.[deviceType]}${largeItemTitleWordSpacing.unit?.[deviceType]}`, |
| 119 |
"line-height": `${largeItemTitleLineHeight.device?.[deviceType]} !important`, |
| 120 |
}, |
| 121 |
}, |
| 122 |
{ |
| 123 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-card-content`, |
| 124 |
styles: { |
| 125 |
padding: spacingGenerate(contentAreaPadding, deviceType) |
| 126 |
? spacingGenerate(contentAreaPadding, deviceType) |
| 127 |
: "0 20px 20px 20px", |
| 128 |
}, |
| 129 |
}, |
| 130 |
{ |
| 131 |
class: `#${uniqueId} .grid-three-layout-three .sp-smart-post-category`, |
| 132 |
styles: { |
| 133 |
margin: spacingGenerate(catTabCategoryMargin, deviceType) |
| 134 |
? spacingGenerate(catTabCategoryMargin, deviceType) |
| 135 |
: "10px", |
| 136 |
}, |
| 137 |
}, |
| 138 |
]; |
| 139 |
}; |
| 140 |
|
| 141 |
const gridThreeStyles = [ |
| 142 |
{ |
| 143 |
class: `${largeItemTitleClass}`, |
| 144 |
styles: { |
| 145 |
"font-weight": `${largeItemTitleTypography.typography.fontWeight} !important`, |
| 146 |
"font-style": `${largeItemTitleTypography.typography.style || "normal"}`, |
| 147 |
"text-transform": `${largeItemTitleTypography.typography.transform} !important`, |
| 148 |
"text-decoration": `${largeItemTitleTypography.typography.decoration} !important`, |
| 149 |
}, |
| 150 |
}, |
| 151 |
...removeEmptyCss(largeItemTitleClass, "font-family", largeItemTitleTypography.typography.family, true), |
| 152 |
]; |
| 153 |
|
| 154 |
const desktopCss = [...sharedDesktopCss, ...responsiveCss("Desktop"), ...gridThreeStyles]; |
| 155 |
|
| 156 |
cacheCss.desktop = objectToCssString(desktopCss); |
| 157 |
|
| 158 |
if ("Tablet" === currentDevice || "all" === currentDevice) { |
| 159 |
// Add Tablet styles |
| 160 |
const tabletCss = [...sharedTabletCss, ...responsiveCss("Tablet"), ...gridThreeStyles]; |
| 161 |
cacheCss.tablet = wrapInMediaQuery( |
| 162 |
objectToCssString(tabletCss), |
| 163 |
`only screen and (max-width: ${globalBreakPointData?.tablet}px)` |
| 164 |
); |
| 165 |
} |
| 166 |
if ("Mobile" === currentDevice || "all" === currentDevice) { |
| 167 |
// Add Mobile styles |
| 168 |
const mobileCss = [ |
| 169 |
...sharedMobileCss, |
| 170 |
...gridThreeStyles, |
| 171 |
...responsiveCss("Mobile"), |
| 172 |
{ |
| 173 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-grid-three-contents .sp-smart-post-dynamic-grid-contents`, |
| 174 |
styles: { |
| 175 |
"grid-template-columns": `repeat(${gridThreeColumns.device.Mobile || 1}, 1fr) !important`, |
| 176 |
}, |
| 177 |
}, |
| 178 |
{ |
| 179 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-grid-three-contents .sp-smart-post-static-grid-contents`, |
| 180 |
styles: { |
| 181 |
"grid-template-columns": `repeat(${gridThreeColumns.device.Mobile || 1}, 1fr) !important`, |
| 182 |
}, |
| 183 |
}, |
| 184 |
// { |
| 185 |
// class: `#${ uniqueId } .grid-three-container .sp-smart-post-grid-three-contents .sp-smart-post-static-grid-contents .sp-smart-post-card, #${ uniqueId } .grid-three-container .sp-smart-post-grid-three-contents .sp-smart-post-dynamic-grid-contents .sp-smart-post-card`, |
| 186 |
// styles: { |
| 187 |
// 'grid-column': `1 / 1`, |
| 188 |
// 'grid-row': `auto`, |
| 189 |
// }, |
| 190 |
// }, |
| 191 |
{ |
| 192 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-static-grid-contents`, |
| 193 |
styles: { |
| 194 |
height: "auto !important", |
| 195 |
}, |
| 196 |
}, |
| 197 |
{ |
| 198 |
class: `#${uniqueId} .grid-three-container .sp-smart-post-dynamic-grid-contents .sp-smart-post-card, #${uniqueId} .grid-three-container .sp-smart-post-static-grid-contents .sp-smart-post-card`, |
| 199 |
styles: { |
| 200 |
"min-height": `${smallItemHeight.device.Mobile}${smallItemHeight.unit.Mobile}`, |
| 201 |
}, |
| 202 |
}, |
| 203 |
{ |
| 204 |
class: `${largeItemTitleClass}`, |
| 205 |
styles: { |
| 206 |
"font-size": `${titleFontSize.device.Mobile}${titleFontSize.unit.Mobile} !important`, |
| 207 |
"letter-spacing": `${titleLatterSpacing.device.Mobile}${ |
| 208 |
titleLatterSpacing.device.Mobile ? titleLatterSpacing.unit.Mobile : "" |
| 209 |
}`, |
| 210 |
"word-spacing": `${titleWordSpacing.device.Mobile}${ |
| 211 |
titleWordSpacing.device.Mobile ? titleWordSpacing.unit.Mobile : "" |
| 212 |
}`, |
| 213 |
"line-height": `${titleLineHeight.device.Mobile}${ |
| 214 |
titleLineHeight.device.Mobile ? " !important" : "" |
| 215 |
}`, |
| 216 |
}, |
| 217 |
}, |
| 218 |
{ |
| 219 |
class: `${uniqueId} .grid-three-container .grid-three-layout-four .sp-smart-post-static-grid-contents`, |
| 220 |
styles: { |
| 221 |
display: "none", |
| 222 |
}, |
| 223 |
}, |
| 224 |
]; |
| 225 |
cacheCss.mobile = wrapInMediaQuery( |
| 226 |
objectToCssString(mobileCss), |
| 227 |
`only screen and (max-width: ${globalBreakPointData?.mobile}px)` |
| 228 |
); |
| 229 |
} |
| 230 |
|
| 231 |
return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`; |
| 232 |
}; |
| 233 |
|
| 234 |
export default dynamicCss; |
| 235 |
|