| 1 |
import sharedDynamicCss from "../shared/dynamicCss"; |
| 2 |
import { objectToCssString, rangerCss, 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 |
postSliderTwoHeight, |
| 9 |
imageWidth, |
| 10 |
imagePosition, |
| 11 |
contentAreaWidth, |
| 12 |
contentAreaHeight, |
| 13 |
contentAreaBorder, |
| 14 |
contentAreaBorderWidth, |
| 15 |
contentAreaBorderRadius, |
| 16 |
globalBreakPointData, |
| 17 |
} = attributes; |
| 18 |
|
| 19 |
const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page); |
| 20 |
|
| 21 |
const responsiveCss = (deviceType) => { |
| 22 |
const imageWidthLayoutThree = imageWidth.device?.[deviceType] |
| 23 |
? imageWidth.device?.[deviceType] + imageWidth.unit?.[deviceType] |
| 24 |
: "67%"; |
| 25 |
|
| 26 |
return [ |
| 27 |
{ |
| 28 |
class: `#${uniqueId} .sp-smart-post-slider-two .sp-smart-post-swiper .swiper-slide .sp-smart-post-card`, |
| 29 |
styles: { |
| 30 |
height: rangerCss(postSliderTwoHeight, deviceType), |
| 31 |
}, |
| 32 |
}, |
| 33 |
// { |
| 34 |
// class: `#${ uniqueId } .sp-smart-post-swiper:not(.post-slider-two-layout-three) + .sp-smart-post-swiper-nav-arrow`, |
| 35 |
// styles: { |
| 36 |
// top: |
| 37 |
// carouselArrowVertical.device[ deviceType ] === '' |
| 38 |
// ? '50%' |
| 39 |
// : carouselArrowVertical.device[ deviceType ] + |
| 40 |
// carouselArrowVertical.unit[ deviceType ], |
| 41 |
// left: |
| 42 |
// carouselArrowHorizontal.device[ deviceType ] === '' |
| 43 |
// ? '32px' |
| 44 |
// : carouselArrowHorizontal.device[ deviceType ] + |
| 45 |
// carouselArrowHorizontal.unit[ deviceType ], |
| 46 |
// right: |
| 47 |
// carouselArrowSpaceBetween.device[ deviceType ] === '' |
| 48 |
// ? carouselArrowHorizontal.device[ deviceType ] === |
| 49 |
// '' |
| 50 |
// ? '32px' |
| 51 |
// : carouselArrowHorizontal.device[ deviceType ] + |
| 52 |
// carouselArrowHorizontal.unit[ deviceType ] |
| 53 |
// : '0', |
| 54 |
// }, |
| 55 |
// }, |
| 56 |
// Post Slider Two Layout Three image and its overlay position. |
| 57 |
{ |
| 58 |
class: `#${uniqueId} .post-slider-two-layout-three .sp-smart-post-card .sp-smart-post-card-image, |
| 59 |
#${uniqueId} .post-slider-two-layout-three .sp-smart-post-card .image-overlay`, |
| 60 |
styles: { |
| 61 |
"max-width": imageWidthLayoutThree, |
| 62 |
left: imagePosition === "left" ? "0" : "unset", |
| 63 |
right: imagePosition === "right" ? "0" : "unset", |
| 64 |
}, |
| 65 |
}, |
| 66 |
// Post Slider Two Layout Three categories position. |
| 67 |
{ |
| 68 |
class: `#${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-top-left, #${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-bottom-left`, |
| 69 |
styles: { |
| 70 |
left: imagePosition === "right" ? `calc(100% - ${imageWidthLayoutThree})` : "0", |
| 71 |
}, |
| 72 |
}, |
| 73 |
{ |
| 74 |
class: `#${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-top-right, #${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-bottom-right`, |
| 75 |
styles: { |
| 76 |
right: imagePosition === "left" ? `calc(100% - ${imageWidthLayoutThree})` : "0", |
| 77 |
}, |
| 78 |
}, |
| 79 |
{ |
| 80 |
class: `#${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-center-top, #${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-center-bottom`, |
| 81 |
styles: { |
| 82 |
left: |
| 83 |
imagePosition === "left" |
| 84 |
? `calc(${imageWidthLayoutThree} / 2)` |
| 85 |
: `calc(100% - ${imageWidthLayoutThree} / 2)`, |
| 86 |
transform: `translateX(-calc(${imageWidthLayoutThree} / 2 ))`, |
| 87 |
}, |
| 88 |
}, |
| 89 |
{ |
| 90 |
class: `#${uniqueId} .post-slider-two-layout-three .sp-smart-post-category.sp-position-center-center`, |
| 91 |
styles: { |
| 92 |
top: "50%", |
| 93 |
left: |
| 94 |
imagePosition === "left" |
| 95 |
? `calc(${imageWidthLayoutThree} / 2)` |
| 96 |
: `calc(100% - ${imageWidthLayoutThree} / 2)`, |
| 97 |
}, |
| 98 |
}, |
| 99 |
{ |
| 100 |
class: `#${uniqueId} .sp-smart-post-template-one-content .sp-smart-post-card-content`, |
| 101 |
styles: { |
| 102 |
width: contentAreaWidth.device?.[deviceType] + contentAreaWidth.unit?.[deviceType], |
| 103 |
height: contentAreaHeight.device?.[deviceType] + contentAreaHeight.unit?.[deviceType], |
| 104 |
"border-width": spacingGenerate(contentAreaBorderWidth, deviceType), |
| 105 |
"border-radius": spacingGenerate(contentAreaBorderRadius, deviceType), |
| 106 |
}, |
| 107 |
}, |
| 108 |
]; |
| 109 |
}; |
| 110 |
|
| 111 |
const desktopCss = [ |
| 112 |
...responsiveCss("Desktop"), |
| 113 |
...sharedDesktopCss, |
| 114 |
{ |
| 115 |
class: `#${uniqueId} .sp-smart-post-slider-two .sp-smart-post-swiper:not(.post-slider-two-layout-three) .sp-smart-post-card .image-overlay`, |
| 116 |
styles: { |
| 117 |
left: 0, |
| 118 |
}, |
| 119 |
}, |
| 120 |
{ |
| 121 |
class: `#${uniqueId} .sp-smart-post-slider-two .category-container.category-image`, |
| 122 |
styles: { |
| 123 |
height: "auto", |
| 124 |
}, |
| 125 |
}, |
| 126 |
{ |
| 127 |
class: `#${uniqueId} .post-slider-two-layout-three .sp-smart-post-card .sp-smart-post-template-one-content.overlay-*`, |
| 128 |
styles: { |
| 129 |
Background: "none", |
| 130 |
}, |
| 131 |
}, |
| 132 |
{ |
| 133 |
class: `#${uniqueId} .sp-smart-post-template-one-content .sp-smart-post-card-content`, |
| 134 |
styles: { |
| 135 |
"border-style": contentAreaBorder.style, |
| 136 |
"border-color": contentAreaBorder.color, |
| 137 |
}, |
| 138 |
}, |
| 139 |
{ |
| 140 |
class: `#${uniqueId} .sp-smart-post-template-one-content .sp-smart-post-card-content:hover`, |
| 141 |
styles: { |
| 142 |
"border-color": contentAreaBorder.hoverColor, |
| 143 |
}, |
| 144 |
}, |
| 145 |
]; |
| 146 |
|
| 147 |
cacheCss.desktop = objectToCssString(desktopCss); |
| 148 |
|
| 149 |
if ("Tablet" === currentDevice || "all" === currentDevice) { |
| 150 |
const tabletCss = [...responsiveCss("Tablet"), ...sharedTabletCss]; |
| 151 |
|
| 152 |
cacheCss.tablet = wrapInMediaQuery( |
| 153 |
objectToCssString(tabletCss), |
| 154 |
`only screen and (max-width: ${globalBreakPointData?.tablet}px)` |
| 155 |
); |
| 156 |
} |
| 157 |
if ("Mobile" === currentDevice || "all" === currentDevice) { |
| 158 |
const mobileCss = [...responsiveCss("Mobile"), ...sharedMobileCss]; |
| 159 |
|
| 160 |
cacheCss.mobile = wrapInMediaQuery( |
| 161 |
objectToCssString(mobileCss), |
| 162 |
`only screen and (max-width: ${globalBreakPointData?.mobile}px)` |
| 163 |
); |
| 164 |
} |
| 165 |
|
| 166 |
return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`; |
| 167 |
}; |
| 168 |
|
| 169 |
export default dynamicCss; |
| 170 |
|