| 1 |
import sharedDynamicCss from "../shared/dynamicCss"; |
| 2 |
import { convertToClassName, objectToCssString, wrapInMediaQuery } from "../shared/helpFn"; |
| 3 |
|
| 4 |
const cacheCss = { desktop: "", mobile: "", tablet: "" }; |
| 5 |
const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => { |
| 6 |
const { |
| 7 |
uniqueId, |
| 8 |
gapBetweenPosts, |
| 9 |
equalHeightEnable, |
| 10 |
timelineIndicatorColor, |
| 11 |
timelineCircleBgColor, |
| 12 |
timelineConnectorBorder, |
| 13 |
timelineLayout, |
| 14 |
advancedPadding, |
| 15 |
globalBreakPointData, |
| 16 |
} = attributes; |
| 17 |
|
| 18 |
const { sharedDesktopCss, sharedTabletCss, sharedMobileCss } = sharedDynamicCss(attributes, page); |
| 19 |
|
| 20 |
const responsiveCss = (deviceType) => { |
| 21 |
return [ |
| 22 |
{ |
| 23 |
class: `#${uniqueId}:has(.post-timeline-one)`, |
| 24 |
styles: { |
| 25 |
"padding-left": advancedPadding.device?.[deviceType].left |
| 26 |
? advancedPadding.device?.[deviceType].left + advancedPadding.unit?.[deviceType] + " !important" |
| 27 |
: "", |
| 28 |
"padding-right": advancedPadding.device?.[deviceType].right |
| 29 |
? advancedPadding.device?.[deviceType].right + |
| 30 |
advancedPadding.unit?.[deviceType] + |
| 31 |
" !important" |
| 32 |
: "", |
| 33 |
}, |
| 34 |
}, |
| 35 |
]; |
| 36 |
}; |
| 37 |
|
| 38 |
const timelineCss = [ |
| 39 |
{ |
| 40 |
class: `#${uniqueId} .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container .sp-smart-indicator-circle.active`, |
| 41 |
styles: { |
| 42 |
"Background-color": `${timelineCircleBgColor.active} !important`, |
| 43 |
"border-color": `${timelineConnectorBorder.activeColor} !important`, |
| 44 |
}, |
| 45 |
}, |
| 46 |
{ |
| 47 |
class: `#${uniqueId} .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container .sp-smart-indicator-arrow.active`, |
| 48 |
styles: { |
| 49 |
"border-left-color": `${timelineIndicatorColor.active} !important`, |
| 50 |
"border-right-color": `${timelineIndicatorColor.active} !important`, |
| 51 |
}, |
| 52 |
}, |
| 53 |
{ |
| 54 |
class: ` |
| 55 |
#${uniqueId} .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:first-child .sp-smart-indicator-circle`, |
| 56 |
styles: { |
| 57 |
"Background-color": `${timelineCircleBgColor.active} !important`, |
| 58 |
"border-color": `${timelineConnectorBorder.activeColor} !important`, |
| 59 |
}, |
| 60 |
}, |
| 61 |
{ |
| 62 |
class: `#${uniqueId} .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:first-child .sp-smart-indicator-arrow`, |
| 63 |
styles: { |
| 64 |
"border-left-color": `${timelineIndicatorColor.active} !important`, |
| 65 |
"border-right-color": `${timelineIndicatorColor.active} !important`, |
| 66 |
}, |
| 67 |
}, |
| 68 |
]; |
| 69 |
|
| 70 |
const desktopCss = [ |
| 71 |
...sharedDesktopCss, |
| 72 |
...timelineCss, |
| 73 |
...responsiveCss("Desktop"), |
| 74 |
{ |
| 75 |
class: `.sp-gap-${convertToClassName(gapBetweenPosts.device.Desktop + gapBetweenPosts.unit.Desktop)}`, |
| 76 |
property: "row-gap", |
| 77 |
value: gapBetweenPosts.device.Desktop + gapBetweenPosts.unit.Desktop, |
| 78 |
}, |
| 79 |
{ |
| 80 |
class: `#${uniqueId} .sp-smart-post-timeline-one-post-container .sp-smart-post-card`, |
| 81 |
styles: { |
| 82 |
height: equalHeightEnable ? "100%" : "auto", |
| 83 |
}, |
| 84 |
}, |
| 85 |
{ |
| 86 |
class: `#${uniqueId} .post-timeline-one .sp-smart-post-timeline-container`, |
| 87 |
styles: { |
| 88 |
"row-gap": gapBetweenPosts.device.Desktop + gapBetweenPosts.unit.Desktop, |
| 89 |
}, |
| 90 |
}, |
| 91 |
]; |
| 92 |
|
| 93 |
cacheCss.desktop = objectToCssString(desktopCss); |
| 94 |
|
| 95 |
if ("Tablet" === currentDevice || "all" === currentDevice) { |
| 96 |
const tabletCss = [...sharedTabletCss, ...timelineCss, ...responsiveCss("Tablet")]; |
| 97 |
cacheCss.tablet = wrapInMediaQuery( |
| 98 |
objectToCssString(tabletCss), |
| 99 |
`only screen and (max-width: ${globalBreakPointData?.tablet}px)` |
| 100 |
); |
| 101 |
} |
| 102 |
if ("Mobile" === currentDevice || "all" === currentDevice) { |
| 103 |
const mobileCss = [ |
| 104 |
...sharedMobileCss, |
| 105 |
...timelineCss, |
| 106 |
...responsiveCss("Mobile"), |
| 107 |
// Timeline bubble speech ( indicator ) |
| 108 |
{ |
| 109 |
class: `#${uniqueId} .post-timeline-one .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:nth-of-type(odd) .sp-smart-indicator-arrow, #${uniqueId} .post-timeline-two .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:nth-of-type(odd) .sp-smart-indicator-arrow, #${uniqueId} .post-timeline-one .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:nth-of-type(even) .sp-smart-indicator-arrow, #${uniqueId} .post-timeline-two .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:nth-of-type(even) .sp-smart-indicator-arrow`, |
| 110 |
styles: { |
| 111 |
border: `medium solid ${timelineIndicatorColor.color}`, |
| 112 |
"border-color": `${ |
| 113 |
timelineLayout !== "timeline-one-layout-six" |
| 114 |
? "transparent transparent transparent " + timelineIndicatorColor.color |
| 115 |
: "transparent " + timelineIndicatorColor.color + " transparent transparent" |
| 116 |
}`, |
| 117 |
"border-width": `${ |
| 118 |
timelineLayout !== "timeline-one-layout-six" ? "15px 0 15px 15px" : "15px 15px 15px 0" |
| 119 |
}`, |
| 120 |
}, |
| 121 |
}, |
| 122 |
// { |
| 123 |
// class: `#${ uniqueId } .post-timeline-one .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:nth-of-type(even) .sp-smart-indicator-arrow, #${ uniqueId } .post-timeline-two .sp-smart-post-timeline-container .sp-smart-post-timeline-one-post-container:nth-of-type(even) .sp-smart-indicator-arrow`, |
| 124 |
// styles: { |
| 125 |
// border: `medium solid ${ timelineIndicatorColor.color }`, |
| 126 |
// 'border-color': `${ |
| 127 |
// timelineLayout !== 'timeline-one-layout-five' |
| 128 |
// ? 'transparent ' + |
| 129 |
// timelineIndicatorColor.color + |
| 130 |
// ' transparent transparent' |
| 131 |
// : 'transparent transparent transparent ' + |
| 132 |
// timelineIndicatorColor.color |
| 133 |
// } `, |
| 134 |
// 'border-width': `${ |
| 135 |
// timelineLayout !== 'timeline-one-layout-five' |
| 136 |
// ? '15px 15px 15px 0' |
| 137 |
// : '15px 0 15px 15px' |
| 138 |
// }`, |
| 139 |
// }, |
| 140 |
// }, |
| 141 |
]; |
| 142 |
cacheCss.mobile = wrapInMediaQuery( |
| 143 |
objectToCssString(mobileCss), |
| 144 |
`only screen and (max-width: ${globalBreakPointData?.mobile}px)` |
| 145 |
); |
| 146 |
} |
| 147 |
|
| 148 |
return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`; |
| 149 |
}; |
| 150 |
|
| 151 |
export default dynamicCss; |
| 152 |
|