| 1 |
import sharedDynamicCss from "../shared/dynamicCss"; |
| 2 |
import { objectToCssString, removeEmptyCss, wrapInMediaQuery } from "../shared/helpFn"; |
| 3 |
|
| 4 |
const cacheCss = { desktop: "", mobile: "", tablet: "" }; |
| 5 |
|
| 6 |
const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => { |
| 7 |
const { |
| 8 |
uniqueId, |
| 9 |
gridFiveColumns, |
| 10 |
gridFiveHorizontalGap, |
| 11 |
gridFiveVerticalGap, |
| 12 |
postGridLayout, |
| 13 |
largeItemTitleFontSize, |
| 14 |
largeItemTitleTypography, |
| 15 |
largeItemTitleLatterSpacing, |
| 16 |
largeItemTitleLineHeight, |
| 17 |
metaLargeFontSize, |
| 18 |
metaLargeFontSpacing, |
| 19 |
metaLargeLineHeight, |
| 20 |
largeItemHeight, |
| 21 |
smallItemHeight, |
| 22 |
equalHeightEnable, |
| 23 |
largeItemTitleWordSpacing, |
| 24 |
metaLargeWordSpacing, |
| 25 |
globalBreakPointData, |
| 26 |
} = attributes; |
| 27 |
|
| 28 |
const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page); |
| 29 |
|
| 30 |
const imagePosition = { |
| 31 |
"grid-five-layout-one": 1, |
| 32 |
"grid-five-layout-two": 2, |
| 33 |
"grid-five-layout-three": 3, |
| 34 |
"grid-five-layout-four": 1, |
| 35 |
"grid-five-layout-five": 1, |
| 36 |
"grid-five-layout-six": 3, |
| 37 |
"grid-five-layout-seven": 4, |
| 38 |
"grid-five-layout-eight": 2, |
| 39 |
"grid-five-layout-nine": 4, |
| 40 |
}; |
| 41 |
|
| 42 |
const responsiveCss = (deviceType) => { |
| 43 |
return [ |
| 44 |
{ |
| 45 |
class: `#${uniqueId} .sp-smart-post-grid-five-static-contents:has(.sp-smart-post-card )`, |
| 46 |
styles: { |
| 47 |
"grid-template-columns": `repeat(${gridFiveColumns.device?.[deviceType]}, 1fr)`, |
| 48 |
"column-gap": `${gridFiveHorizontalGap.device?.[deviceType]}${gridFiveHorizontalGap.unit?.[deviceType]}`, |
| 49 |
"row-gap": `${gridFiveVerticalGap.device?.[deviceType]}${gridFiveVerticalGap.unit?.[deviceType]}`, |
| 50 |
"margin-top": `${gridFiveVerticalGap.device?.[deviceType]}${gridFiveVerticalGap.unit?.[deviceType]}`, |
| 51 |
}, |
| 52 |
}, |
| 53 |
{ |
| 54 |
class: `#${uniqueId} .grid-five-container .sp-smart-post-grid-five-dynamic-contents`, |
| 55 |
styles: { |
| 56 |
height: `${largeItemHeight.device?.[deviceType]}${largeItemHeight.unit?.[deviceType]}`, |
| 57 |
}, |
| 58 |
}, |
| 59 |
{ |
| 60 |
class: `#${uniqueId} .grid-five-container .sp-smart-post-grid-five-static-contents .sp-smart-post-card`, |
| 61 |
styles: { |
| 62 |
"min-height": equalHeightEnable |
| 63 |
? "auto" |
| 64 |
: `${smallItemHeight.device?.[deviceType]}${smallItemHeight.unit?.[deviceType]}`, |
| 65 |
}, |
| 66 |
}, |
| 67 |
{ |
| 68 |
class: `#${uniqueId} .sp-smart-post-grid-five-dynamic-contents`, |
| 69 |
styles: { |
| 70 |
"column-gap": `${gridFiveHorizontalGap.device?.[deviceType]}${gridFiveHorizontalGap.unit?.[deviceType]}`, |
| 71 |
"row-gap": `${gridFiveVerticalGap.device?.[deviceType]}${gridFiveVerticalGap.unit?.[deviceType]}`, |
| 72 |
}, |
| 73 |
}, |
| 74 |
{ |
| 75 |
class: `#${uniqueId} .sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-title`, |
| 76 |
styles: { |
| 77 |
"font-size": |
| 78 |
largeItemTitleFontSize.device?.[deviceType] + |
| 79 |
largeItemTitleFontSize.unit?.[deviceType] + |
| 80 |
" !important", |
| 81 |
"letter-spacing": |
| 82 |
largeItemTitleLatterSpacing.device?.[deviceType] + |
| 83 |
largeItemTitleLatterSpacing.unit?.[deviceType], |
| 84 |
"word-spacing": |
| 85 |
largeItemTitleWordSpacing.device?.[deviceType] + largeItemTitleWordSpacing.unit?.[deviceType], |
| 86 |
"line-height": largeItemTitleLineHeight.device?.[deviceType] + " !important", |
| 87 |
}, |
| 88 |
}, |
| 89 |
// Metadata Large items Typography. |
| 90 |
{ |
| 91 |
class: `#${uniqueId} .sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-author .sp-smart-post-author-name, |
| 92 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-date span, |
| 93 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-post-show-comment span, |
| 94 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-view span, |
| 95 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-like span, |
| 96 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-like i, |
| 97 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-reading-time span`, |
| 98 |
styles: { |
| 99 |
"font-size": `${metaLargeFontSize.device?.[deviceType]}${metaLargeFontSize.unit?.[deviceType]} !important`, |
| 100 |
"letter-spacing": `${metaLargeFontSpacing.device?.[deviceType]}${metaLargeFontSpacing.unit?.[deviceType]}`, |
| 101 |
"word-spacing": `${metaLargeWordSpacing.device?.[deviceType]}${metaLargeWordSpacing.unit?.[deviceType]}`, |
| 102 |
"line-height": `${metaLargeLineHeight.device?.[deviceType]} !important`, |
| 103 |
display: "flex", |
| 104 |
"align-items": "center", |
| 105 |
}, |
| 106 |
}, |
| 107 |
{ |
| 108 |
class: `#${uniqueId} .sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-author svg, |
| 109 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-date .sp-smart-post-release-date, |
| 110 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-post-show-comment span, |
| 111 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-view span:first-of-type, |
| 112 |
.sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-reading-time span:first-of-type`, |
| 113 |
styles: { |
| 114 |
height: `${metaLargeFontSize.device?.[deviceType]}${metaLargeFontSize.unit?.[deviceType]} !important`, |
| 115 |
width: `${metaLargeFontSize.device?.[deviceType]}${metaLargeFontSize.unit?.[deviceType]} !important`, |
| 116 |
display: "flex", |
| 117 |
"align-items": "center", |
| 118 |
}, |
| 119 |
}, |
| 120 |
]; |
| 121 |
}; |
| 122 |
|
| 123 |
const desktopCss = [ |
| 124 |
...sharedDesktopCss, |
| 125 |
...responsiveCss("Desktop"), |
| 126 |
{ |
| 127 |
class: `#${uniqueId} .sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-title`, |
| 128 |
styles: { |
| 129 |
"font-style": largeItemTitleTypography.typography.style || "normal", |
| 130 |
"text-decoration": largeItemTitleTypography.typography.decoration + " !important", |
| 131 |
"text-transform": largeItemTitleTypography.typography.transform + " !important", |
| 132 |
}, |
| 133 |
}, |
| 134 |
...removeEmptyCss( |
| 135 |
`#${uniqueId} .sp-smart-post-grid-five-dynamic-contents > div:nth-of-type(${imagePosition[postGridLayout]}) .sp-smart-post-card-content .sp-smart-post-title`, |
| 136 |
"font-family", |
| 137 |
largeItemTitleTypography.typography.family, |
| 138 |
true |
| 139 |
), |
| 140 |
]; |
| 141 |
cacheCss.desktop = objectToCssString(desktopCss); |
| 142 |
|
| 143 |
if ("Tablet" === currentDevice || "all" === currentDevice) { |
| 144 |
// Tablet CSS styles. |
| 145 |
const tabletCss = [...sharedTabletCss, ...responsiveCss("Tablet")]; |
| 146 |
cacheCss.tablet = wrapInMediaQuery( |
| 147 |
objectToCssString(tabletCss), |
| 148 |
`only screen and (max-width: ${globalBreakPointData?.tablet}px)` |
| 149 |
); |
| 150 |
} |
| 151 |
if ("Mobile" === currentDevice || "all" === currentDevice) { |
| 152 |
// Mobile CSS styles. |
| 153 |
const mobileCss = [ |
| 154 |
...sharedMobileCss, |
| 155 |
...responsiveCss("Mobile"), |
| 156 |
{ |
| 157 |
class: `#${uniqueId} .sp-smart-post-grid-five-static-contents, #${uniqueId} .grid-five-container .sp-smart-post-grid-five-dynamic-contents `, |
| 158 |
styles: { |
| 159 |
"grid-template-areas": `"post1" "post2" "post3"`, |
| 160 |
"grid-template-columns": `repeat(${gridFiveColumns.device.Mobile || 1}, 1fr)`, |
| 161 |
}, |
| 162 |
}, |
| 163 |
{ |
| 164 |
class: `#${uniqueId} .grid-five-container .sp-smart-post-grid-five-dynamic-contents .sp-smart-post-card `, |
| 165 |
styles: { |
| 166 |
// 'grid-column': '1 / 1', |
| 167 |
// 'grid-row': 'auto', |
| 168 |
height: `${smallItemHeight.device.Mobile}${smallItemHeight.unit.Mobile} !important`, |
| 169 |
}, |
| 170 |
}, |
| 171 |
{ |
| 172 |
class: `#${uniqueId} .grid-five-container .sp-smart-post-grid-five-dynamic-contents`, |
| 173 |
styles: { |
| 174 |
height: "auto !important", |
| 175 |
}, |
| 176 |
}, |
| 177 |
]; |
| 178 |
cacheCss.mobile = wrapInMediaQuery( |
| 179 |
objectToCssString(mobileCss), |
| 180 |
`only screen and (max-width: ${globalBreakPointData?.mobile}px)` |
| 181 |
); |
| 182 |
} |
| 183 |
|
| 184 |
return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`; |
| 185 |
}; |
| 186 |
|
| 187 |
export default dynamicCss; |
| 188 |
|