| 1 |
import sharedDynamicCss from "../shared/dynamicCss"; |
| 2 |
import { bgColor, objectToCssString, spacingGenerate, wrapInMediaQuery } from "../shared/helpFn"; |
| 3 |
|
| 4 |
const cacheCss = { desktop: "", mobile: "", tablet: "" }; |
| 5 |
const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => { |
| 6 |
const { |
| 7 |
uniqueId, |
| 8 |
verticalGap, |
| 9 |
enableSeparator, |
| 10 |
separatorStyle, |
| 11 |
separatorHeight, |
| 12 |
separatorColor, |
| 13 |
spaceBetweenListItems, |
| 14 |
contentVerticalPosition, |
| 15 |
dividerHeight, |
| 16 |
dividerBorderStyle, |
| 17 |
dividerBg, |
| 18 |
dividerAlignment, |
| 19 |
dividerWidth, |
| 20 |
showHideDivider, |
| 21 |
imageHeight, |
| 22 |
imageSize, |
| 23 |
contentAreaBorder, |
| 24 |
contentAreaBorderRadius, |
| 25 |
contentAreaBorderWidth, |
| 26 |
postListLayout, |
| 27 |
globalBreakPointData, |
| 28 |
} = attributes; |
| 29 |
|
| 30 |
const responsiveCss = (attr, device) => { |
| 31 |
const unit = attr?.unit?.[device]; |
| 32 |
return `${attr?.device?.[device]}${unit}`; |
| 33 |
}; |
| 34 |
|
| 35 |
const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page); |
| 36 |
|
| 37 |
const getSeparatorStyles = (device) => { |
| 38 |
if (enableSeparator) { |
| 39 |
return { |
| 40 |
class: `#${uniqueId} .sp-smart-post-show-separator`, |
| 41 |
styles: { |
| 42 |
"border-bottom-style": separatorStyle, |
| 43 |
"border-bottom-color": separatorColor, |
| 44 |
"border-bottom-width": separatorHeight.device?.[device] + separatorHeight.unit?.[device], |
| 45 |
margin: `${spaceBetweenListItems.device?.[device] + spaceBetweenListItems.unit?.[device]} 0px`, |
| 46 |
}, |
| 47 |
}; |
| 48 |
} |
| 49 |
return {}; |
| 50 |
}; |
| 51 |
|
| 52 |
const flexAlignment = { |
| 53 |
top: "start", |
| 54 |
center: "center", |
| 55 |
bottom: "end", |
| 56 |
}; |
| 57 |
|
| 58 |
let dividerStyle = []; |
| 59 |
|
| 60 |
if (showHideDivider) { |
| 61 |
const marginAlignment = { |
| 62 |
center: { |
| 63 |
margin: "auto", |
| 64 |
}, |
| 65 |
right: { |
| 66 |
"margin-left": "auto", |
| 67 |
}, |
| 68 |
left: {}, |
| 69 |
}; |
| 70 |
|
| 71 |
dividerStyle = [ |
| 72 |
{ |
| 73 |
class: `#${uniqueId} .sp-smart-post-list-divider`, |
| 74 |
styles: { |
| 75 |
"border-top": `${responsiveCss(dividerHeight, "Desktop")} ${dividerBorderStyle}`, |
| 76 |
"border-color": "bgColor" === dividerBg.color.style ? bgColor(dividerBg) : "", |
| 77 |
"border-image-source": "gradient" === dividerBg.color.style ? bgColor(dividerBg) : "", |
| 78 |
width: `${responsiveCss(dividerWidth, "Desktop")}`, |
| 79 |
...marginAlignment[dividerAlignment], |
| 80 |
}, |
| 81 |
}, |
| 82 |
]; |
| 83 |
} |
| 84 |
|
| 85 |
const responsiveCssFun = (deviceType) => { |
| 86 |
return [ |
| 87 |
{ |
| 88 |
class: `#${uniqueId} .sp-smart-post-card .sp-smart-post-card-content`, |
| 89 |
styles: { |
| 90 |
...(["list-one-layout-three", "list-one-layout-four"].includes(postListLayout) && { |
| 91 |
"border-style": contentAreaBorder.style, |
| 92 |
"border-color": contentAreaBorder.color, |
| 93 |
"border-width": spacingGenerate(contentAreaBorderWidth, deviceType), |
| 94 |
"border-radius": spacingGenerate(contentAreaBorderRadius, deviceType), |
| 95 |
}), |
| 96 |
}, |
| 97 |
}, |
| 98 |
]; |
| 99 |
}; |
| 100 |
|
| 101 |
const desktopCss = [ |
| 102 |
...sharedDesktopCss, |
| 103 |
...dividerStyle, |
| 104 |
...responsiveCssFun("Desktop"), |
| 105 |
{ |
| 106 |
class: `#${uniqueId} .sp-smart-post-list-one-container`, |
| 107 |
styles: { |
| 108 |
gap: verticalGap.device.Desktop + verticalGap.unit.Desktop, |
| 109 |
}, |
| 110 |
}, |
| 111 |
{ |
| 112 |
class: `#${uniqueId} .list-one-layout-three .sp-smart-post-card, |
| 113 |
#${uniqueId} .list-one-layout-four .sp-smart-post-card`, |
| 114 |
styles: { |
| 115 |
background: "transparent", |
| 116 |
}, |
| 117 |
}, |
| 118 |
{ |
| 119 |
class: `#${uniqueId} .sp-smart-post-card .sp-smart-post-card-image`, |
| 120 |
styles: { |
| 121 |
height: "custom" === imageSize ? `${imageHeight.device.Desktop}${imageHeight.unit.Desktop}` : "", |
| 122 |
}, |
| 123 |
}, |
| 124 |
|
| 125 |
{ |
| 126 |
class: `#${uniqueId} .sp-smart-post-list-one-container .sp-smart-post-card`, |
| 127 |
styles: { |
| 128 |
"align-items": flexAlignment[contentVerticalPosition], |
| 129 |
}, |
| 130 |
}, |
| 131 |
getSeparatorStyles("Desktop"), |
| 132 |
]; |
| 133 |
|
| 134 |
cacheCss.desktop = objectToCssString(desktopCss); |
| 135 |
|
| 136 |
if ("Tablet" === currentDevice || "all" === currentDevice) { |
| 137 |
const tabletCss = [ |
| 138 |
...sharedTabletCss, |
| 139 |
...responsiveCssFun("Tablet"), |
| 140 |
{ |
| 141 |
class: `#${uniqueId} .sp-smart-post-list-one-container`, |
| 142 |
styles: { |
| 143 |
gap: verticalGap.device.Tablet + verticalGap.unit.Tablet, |
| 144 |
}, |
| 145 |
}, |
| 146 |
getSeparatorStyles("Tablet"), |
| 147 |
]; |
| 148 |
cacheCss.tablet = wrapInMediaQuery( |
| 149 |
objectToCssString(tabletCss), |
| 150 |
`only screen and (max-width: ${globalBreakPointData?.tablet}px)` |
| 151 |
); |
| 152 |
} |
| 153 |
if ("Mobile" === currentDevice || "all" === currentDevice) { |
| 154 |
const mobileCss = [ |
| 155 |
...sharedMobileCss, |
| 156 |
...responsiveCssFun("Mobile"), |
| 157 |
{ |
| 158 |
class: `#${uniqueId} .sp-smart-post-list-one-container`, |
| 159 |
styles: { |
| 160 |
gap: verticalGap.device.Mobile + verticalGap.unit.Mobile, |
| 161 |
}, |
| 162 |
}, |
| 163 |
getSeparatorStyles("Mobile"), |
| 164 |
]; |
| 165 |
cacheCss.mobile = wrapInMediaQuery( |
| 166 |
objectToCssString(mobileCss), |
| 167 |
`only screen and (max-width: ${globalBreakPointData?.mobile}px)` |
| 168 |
); |
| 169 |
} |
| 170 |
|
| 171 |
return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`; |
| 172 |
}; |
| 173 |
|
| 174 |
export default dynamicCss; |
| 175 |
|