| 1 |
import { objectToCssString, wrapInMediaQuery, boxCss, spacingGenerate, colorControls } from "../shared/helpFn"; |
| 2 |
|
| 3 |
const dynamicCss = (attributes) => { |
| 4 |
const { |
| 5 |
uniqueId, |
| 6 |
smartListBg, |
| 7 |
iconAlignment, |
| 8 |
borderStyle, |
| 9 |
borderStyleWidth, |
| 10 |
badgePadding, |
| 11 |
borderRadius, |
| 12 |
padding, |
| 13 |
boxShadowEnable, |
| 14 |
listBoxShadow, |
| 15 |
borderHoverStyle, |
| 16 |
borderHoverStyleWidth, |
| 17 |
borderHoverRadius, |
| 18 |
iconHorizontalAlignment, |
| 19 |
titleTypography, |
| 20 |
boxShadowHoverEnable, |
| 21 |
boxShadowHover, |
| 22 |
titleColor, |
| 23 |
titleFontSize, |
| 24 |
titleLineHeight, |
| 25 |
titleLatterSpacing, |
| 26 |
descriptionFontSize, |
| 27 |
descriptionLineHeight, |
| 28 |
descriptionLatterSpacing, |
| 29 |
descriptionColor, |
| 30 |
titleDescriptionGap, |
| 31 |
iconBg, |
| 32 |
badgeMargin, |
| 33 |
badgeBorderStyleWidth, |
| 34 |
iconPadding, |
| 35 |
iconBorderRadius, |
| 36 |
iconHoverBorderRadius, |
| 37 |
iconBorderStyleWidth, |
| 38 |
iconBorderStyle, |
| 39 |
badgeBorderStyle, |
| 40 |
iconSize, |
| 41 |
iconCustomWidth, |
| 42 |
iconCustomHeight, |
| 43 |
iconPosition, |
| 44 |
badgeBgColor, |
| 45 |
badgeLatterSpacing, |
| 46 |
badgeLineHeight, |
| 47 |
iconHoverBorderStyleWidth, |
| 48 |
titleWordSpacing, |
| 49 |
badgeFontSize, |
| 50 |
descriptionWordSpacing, |
| 51 |
descriptionTypography, |
| 52 |
badgeBorderRadius, |
| 53 |
iconColor, |
| 54 |
iconHoverBorderStyle, |
| 55 |
iconBackgroundEnable, |
| 56 |
backgroundShape, |
| 57 |
badgeTypography, |
| 58 |
badgeWordSpacing, |
| 59 |
badgeColor, |
| 60 |
hideOnDesktop, |
| 61 |
hideOnTablet, |
| 62 |
hideOnMobile, |
| 63 |
svgIconName, |
| 64 |
iconSource, |
| 65 |
// listItemWidth, |
| 66 |
} = attributes; |
| 67 |
|
| 68 |
const rangerCss = (attr, device = "Desktop") => { |
| 69 |
const unit = attr?.unit?.[device] || ""; |
| 70 |
return `${attr?.device?.[device]}${unit}`; |
| 71 |
}; |
| 72 |
|
| 73 |
const typographyCss = (attr) => { |
| 74 |
return { |
| 75 |
"font-family": attr.typography.family, |
| 76 |
"font-weight": attr.typography.fontWeight, |
| 77 |
"font-style": attr.typography.style, |
| 78 |
"text-decoration": attr.typography.decoration, |
| 79 |
"text-transform": attr.typography.transform, |
| 80 |
}; |
| 81 |
}; |
| 82 |
|
| 83 |
const getClipPath = (shape) => { |
| 84 |
const shapes = { |
| 85 |
backgroundShapeHexagon: "polygon(0% 25%, 50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%)", |
| 86 |
backgroundShapeDiamond: "polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)", |
| 87 |
backgroundShapeStarburst: |
| 88 |
"polygon(100% 50%, 92% 58%, 98% 68%, 88% 72%, 92% 84%, 82% 82%, 80% 94%, 70% 88%, 66% 100%, 58% 92%, 50% 100%, 42% 92%, 34% 100%, 30% 88%, 20% 94%, 18% 82%, 8% 84%, 12% 72%, 2% 68%, 8% 58%, 0% 50%, 8% 42%, 2% 32%, 12% 28%, 8% 16%, 18% 18%, 20% 6%, 30% 12%, 34% 0%, 42% 8%, 50% 0%, 58% 8%, 66% 0%, 70% 12%, 80% 6%, 82% 18%, 92% 16%, 88% 28%, 98% 32%, 92% 42%)", |
| 89 |
backgroundShapeCircle: "circle(50% at 50% 50%)", |
| 90 |
backgroundShapeSquare: "polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)", |
| 91 |
}; |
| 92 |
|
| 93 |
return shapes[shape] || ""; |
| 94 |
}; |
| 95 |
const generalCSS = () => { |
| 96 |
return [ |
| 97 |
{ |
| 98 |
class: `#${uniqueId} .sp-smart-post-list-link`, |
| 99 |
styles: { |
| 100 |
"border-style": borderStyle.style, |
| 101 |
"border-color": borderStyle.color, |
| 102 |
background: colorControls( |
| 103 |
smartListBg?.color?.style, |
| 104 |
smartListBg?.color?.solidColor, |
| 105 |
smartListBg?.color?.gradient |
| 106 |
), |
| 107 |
}, |
| 108 |
}, |
| 109 |
|
| 110 |
{ |
| 111 |
class: `#${uniqueId} .sp-smart-post-list-link:hover`, |
| 112 |
styles: { |
| 113 |
"border-style": borderHoverStyle.style, |
| 114 |
"border-color": borderHoverStyle.color, |
| 115 |
background: colorControls( |
| 116 |
smartListBg?.hover?.style, |
| 117 |
smartListBg?.hover?.solidColor, |
| 118 |
smartListBg?.hover?.gradient |
| 119 |
), |
| 120 |
}, |
| 121 |
}, |
| 122 |
]; |
| 123 |
}; |
| 124 |
|
| 125 |
const iconImageCSS = () => { |
| 126 |
return [ |
| 127 |
{ |
| 128 |
class: `#${uniqueId} .sp-smart-post-list-link`, |
| 129 |
styles: { |
| 130 |
...(iconPosition !== undefined && |
| 131 |
iconPosition !== null && { |
| 132 |
"flex-direction": iconPosition === "top" ? "column" : "row", |
| 133 |
}), |
| 134 |
}, |
| 135 |
}, |
| 136 |
|
| 137 |
{ |
| 138 |
class: `#${uniqueId} .sp-smart-post-list-icon-wrapper`, |
| 139 |
styles: { |
| 140 |
order: iconPosition !== "top" ? iconPosition : "0", |
| 141 |
"align-self": iconAlignment, |
| 142 |
}, |
| 143 |
}, |
| 144 |
|
| 145 |
{ |
| 146 |
class: `#${uniqueId} .sp-smart-post-list-icon-container`, |
| 147 |
styles: { |
| 148 |
...(iconBackgroundEnable !== undefined && |
| 149 |
iconBackgroundEnable !== null && { |
| 150 |
background: |
| 151 |
iconBackgroundEnable && |
| 152 |
colorControls(iconBg?.color?.style, iconBg?.color?.solidColor, iconBg?.color?.gradient), |
| 153 |
}), |
| 154 |
|
| 155 |
"border-style": iconBorderStyle.style, |
| 156 |
"border-color": iconBorderStyle.color, |
| 157 |
"clip-path": getClipPath(backgroundShape), |
| 158 |
}, |
| 159 |
}, |
| 160 |
|
| 161 |
{ |
| 162 |
class: `#${uniqueId} .sp-smart-post-list-icon-container:hover`, |
| 163 |
styles: { |
| 164 |
background: |
| 165 |
iconBackgroundEnable && |
| 166 |
colorControls(iconBg?.hover?.style, iconBg?.hover?.solidColor, iconBg?.hover?.gradient), |
| 167 |
"border-style": iconHoverBorderStyle.style, |
| 168 |
"border-color": iconHoverBorderStyle.color, |
| 169 |
}, |
| 170 |
}, |
| 171 |
|
| 172 |
{ |
| 173 |
class: `#${uniqueId} .sp-smart-post-list-link .sp-smart-post-list-icon-svg::before `, |
| 174 |
...(svgIconName !== undefined && { |
| 175 |
styles: { |
| 176 |
content: svgIconName === "NumberIcon" ? "counter(list-counter)" : '""', |
| 177 |
color: iconColor.color, |
| 178 |
}, |
| 179 |
}), |
| 180 |
}, |
| 181 |
|
| 182 |
{ |
| 183 |
class: `#${uniqueId} .sp-smart-post-list-link .sp-smart-post-list-icon-container:hover .sp-smart-post-list-icon-svg::before `, |
| 184 |
|
| 185 |
...(svgIconName !== undefined && { |
| 186 |
styles: { |
| 187 |
color: iconColor.hoverColor, |
| 188 |
}, |
| 189 |
}), |
| 190 |
}, |
| 191 |
|
| 192 |
{ |
| 193 |
class: `#${uniqueId} .sp-smart-post-list-icon-svg svg path`, |
| 194 |
styles: { |
| 195 |
fill: `${iconColor.color} !important`, |
| 196 |
}, |
| 197 |
}, |
| 198 |
|
| 199 |
{ |
| 200 |
class: `#${uniqueId} .sp-smart-post-list-link:hover .sp-smart-post-list-icon-svg svg path`, |
| 201 |
styles: { |
| 202 |
fill: `${iconColor.hoverColor} !important`, |
| 203 |
}, |
| 204 |
}, |
| 205 |
|
| 206 |
{ |
| 207 |
class: `#${uniqueId} .sp-smart-post-list-link .sp-smart-post-list-icon `, |
| 208 |
styles: { |
| 209 |
color: iconColor.color, |
| 210 |
}, |
| 211 |
}, |
| 212 |
|
| 213 |
{ |
| 214 |
class: `#${uniqueId} .sp-smart-post-list-link .sp-smart-post-list-icon:hover `, |
| 215 |
styles: { |
| 216 |
color: iconColor.hoverColor, |
| 217 |
}, |
| 218 |
}, |
| 219 |
|
| 220 |
{ |
| 221 |
class: `#${uniqueId} .sp-smart-post-list-icon-img .sp-smart-post-list-overlay`, |
| 222 |
styles: { |
| 223 |
"background-color": iconColor.color, |
| 224 |
}, |
| 225 |
}, |
| 226 |
|
| 227 |
{ |
| 228 |
class: `#${uniqueId} .sp-smart-post-list-icon-img:hover .sp-smart-post-list-overlay`, |
| 229 |
styles: { |
| 230 |
"background-color": iconColor.hoverColor, |
| 231 |
}, |
| 232 |
}, |
| 233 |
|
| 234 |
{ |
| 235 |
class: `.sp-smart-post-smart-lists-wrapper.layout-five #${uniqueId} .sp-smart-post-list-link`, |
| 236 |
styles: { |
| 237 |
"flex-direction": "column", |
| 238 |
"align-items": iconHorizontalAlignment, |
| 239 |
}, |
| 240 |
}, |
| 241 |
]; |
| 242 |
}; |
| 243 |
|
| 244 |
const contentCSS = () => { |
| 245 |
return [ |
| 246 |
{ |
| 247 |
class: `#${uniqueId} .sp-smart-post-list-title`, |
| 248 |
styles: { |
| 249 |
color: titleColor.color, |
| 250 |
...typographyCss(titleTypography), |
| 251 |
}, |
| 252 |
}, |
| 253 |
|
| 254 |
{ |
| 255 |
class: `#${uniqueId} .sp-smart-post-list-link:hover .sp-smart-post-list-title`, |
| 256 |
styles: { |
| 257 |
color: titleColor.hoverColor, |
| 258 |
}, |
| 259 |
}, |
| 260 |
|
| 261 |
{ |
| 262 |
class: `#${uniqueId} .sp-smart-post-list-description`, |
| 263 |
styles: { |
| 264 |
color: descriptionColor.color, |
| 265 |
...typographyCss(descriptionTypography), |
| 266 |
}, |
| 267 |
}, |
| 268 |
|
| 269 |
{ |
| 270 |
class: `#${uniqueId} .sp-smart-post-list-link:hover .sp-smart-post-list-description`, |
| 271 |
styles: { |
| 272 |
color: descriptionColor.hoverColor, |
| 273 |
}, |
| 274 |
}, |
| 275 |
]; |
| 276 |
}; |
| 277 |
|
| 278 |
const badgeCSS = () => { |
| 279 |
return [ |
| 280 |
{ |
| 281 |
class: `#${uniqueId} .sp-smart-post-list-badge`, |
| 282 |
styles: { |
| 283 |
color: badgeColor, |
| 284 |
...typographyCss(badgeTypography), |
| 285 |
background: badgeBgColor, |
| 286 |
"border-style": badgeBorderStyle.style, |
| 287 |
"border-color": badgeBorderStyle.color, |
| 288 |
}, |
| 289 |
}, |
| 290 |
]; |
| 291 |
}; |
| 292 |
|
| 293 |
const responsiveCss = (deviceType) => { |
| 294 |
return [ |
| 295 |
{ |
| 296 |
class: `#${uniqueId} .sp-smart-post-list-link`, |
| 297 |
styles: { |
| 298 |
"box-shadow": boxCss(boxShadowEnable, deviceType, listBoxShadow, "color"), |
| 299 |
"border-width": spacingGenerate(borderStyleWidth, deviceType), |
| 300 |
padding: spacingGenerate(padding, deviceType), |
| 301 |
"border-radius": spacingGenerate(borderRadius, deviceType), |
| 302 |
// width: rangerCss(listItemWidth, deviceType), |
| 303 |
}, |
| 304 |
}, |
| 305 |
|
| 306 |
{ |
| 307 |
class: `#${uniqueId} .sp-smart-post-list-link:hover`, |
| 308 |
styles: { |
| 309 |
"box-shadow": boxCss(boxShadowHoverEnable, deviceType, boxShadowHover, "color"), |
| 310 |
"border-width": spacingGenerate(borderHoverStyleWidth, deviceType), |
| 311 |
"border-radius": spacingGenerate(borderHoverRadius, deviceType), |
| 312 |
}, |
| 313 |
}, |
| 314 |
|
| 315 |
{ |
| 316 |
class: `#${uniqueId} .sp-smart-post-list-icon-container`, |
| 317 |
styles: { |
| 318 |
padding: spacingGenerate(iconPadding, deviceType), |
| 319 |
|
| 320 |
"border-radius": `${ |
| 321 |
backgroundShape && backgroundShape === "backgroundShapeSquare" |
| 322 |
? spacingGenerate(iconBorderRadius, deviceType) |
| 323 |
: backgroundShape && backgroundShape !== "backgroundShapeSquare" |
| 324 |
? "50%" |
| 325 |
: "" |
| 326 |
}`, |
| 327 |
|
| 328 |
"border-width": spacingGenerate(iconBorderStyleWidth, deviceType), |
| 329 |
width: iconSource === "library" ? rangerCss(iconSize, deviceType) : "", |
| 330 |
height: iconSource === "library" ? rangerCss(iconSize, deviceType) : "", |
| 331 |
}, |
| 332 |
}, |
| 333 |
|
| 334 |
{ |
| 335 |
class: `#${uniqueId} .sp-smart-post-list-icon-container:hover`, |
| 336 |
styles: { |
| 337 |
"border-radius": `${ |
| 338 |
backgroundShape === "backgroundShapeSquare" |
| 339 |
? spacingGenerate(iconHoverBorderRadius, deviceType) |
| 340 |
: backgroundShape === "backgroundShapeCircle" |
| 341 |
? "50%" |
| 342 |
: "" |
| 343 |
}`, |
| 344 |
|
| 345 |
"border-width": spacingGenerate(iconHoverBorderStyleWidth, deviceType), |
| 346 |
}, |
| 347 |
}, |
| 348 |
|
| 349 |
{ |
| 350 |
class: `#${uniqueId} .sp-smart-post-list-icon-container .sp-smart-post-list-icon-img img, |
| 351 |
#${uniqueId} .sp-smart-post-list-icon-container .sp-smart-post-list-overlay`, |
| 352 |
styles: { |
| 353 |
"border-radius": `${ |
| 354 |
backgroundShape === "backgroundShapeSquare" |
| 355 |
? spacingGenerate(iconBorderRadius, deviceType) |
| 356 |
: backgroundShape === "backgroundShapeCircle" |
| 357 |
? "50%" |
| 358 |
: "" |
| 359 |
}`, |
| 360 |
}, |
| 361 |
}, |
| 362 |
|
| 363 |
{ |
| 364 |
class: `#${uniqueId} .sp-smart-post-list-link .sp-smart-post-list-icon-svg svg`, |
| 365 |
styles: { |
| 366 |
width: rangerCss(iconSize, deviceType), |
| 367 |
height: rangerCss(iconSize, deviceType), |
| 368 |
}, |
| 369 |
}, |
| 370 |
|
| 371 |
{ |
| 372 |
class: `#${uniqueId} .sp-smart-post-list-link .sp-smart-post-list-icon`, |
| 373 |
styles: { |
| 374 |
"font-size": rangerCss(iconSize, deviceType), |
| 375 |
}, |
| 376 |
}, |
| 377 |
|
| 378 |
{ |
| 379 |
class: `#${uniqueId} .sp-smart-post-list-icon-img img`, |
| 380 |
styles: { |
| 381 |
width: rangerCss(iconCustomWidth, deviceType), |
| 382 |
height: rangerCss(iconCustomHeight, deviceType), |
| 383 |
}, |
| 384 |
}, |
| 385 |
|
| 386 |
{ |
| 387 |
class: `#${uniqueId} .sp-smart-post-list-text`, |
| 388 |
styles: { |
| 389 |
gap: rangerCss(titleDescriptionGap, deviceType), |
| 390 |
}, |
| 391 |
}, |
| 392 |
|
| 393 |
{ |
| 394 |
class: `#${uniqueId} .sp-smart-post-list-title`, |
| 395 |
styles: { |
| 396 |
"font-size": rangerCss(titleFontSize, deviceType), |
| 397 |
"line-height": rangerCss(titleLineHeight, deviceType), |
| 398 |
"letter-spacing": rangerCss(titleLatterSpacing, deviceType), |
| 399 |
"word-spacing": rangerCss(titleWordSpacing, deviceType), |
| 400 |
}, |
| 401 |
}, |
| 402 |
|
| 403 |
{ |
| 404 |
class: `#${uniqueId} .sp-smart-post-list-description`, |
| 405 |
styles: { |
| 406 |
"font-size": rangerCss(descriptionFontSize, deviceType), |
| 407 |
"line-height": rangerCss(descriptionLineHeight, deviceType), |
| 408 |
"letter-spacing": rangerCss(descriptionLatterSpacing, deviceType), |
| 409 |
"word-spacing": rangerCss(descriptionWordSpacing, deviceType), |
| 410 |
}, |
| 411 |
}, |
| 412 |
|
| 413 |
{ |
| 414 |
class: `#${uniqueId} .sp-smart-post-list-badge`, |
| 415 |
styles: { |
| 416 |
"font-size": rangerCss(badgeFontSize, deviceType), |
| 417 |
"line-height": rangerCss(badgeLineHeight, deviceType), |
| 418 |
"letter-spacing": rangerCss(badgeLatterSpacing, deviceType), |
| 419 |
"word-spacing": rangerCss(badgeWordSpacing, deviceType), |
| 420 |
padding: spacingGenerate(badgePadding, deviceType), |
| 421 |
margin: spacingGenerate(badgeMargin, deviceType), |
| 422 |
"border-width": spacingGenerate(badgeBorderStyleWidth, deviceType), |
| 423 |
"border-radius": spacingGenerate(badgeBorderRadius, deviceType), |
| 424 |
}, |
| 425 |
}, |
| 426 |
|
| 427 |
{ |
| 428 |
class: `#${uniqueId} .sp-smart-post-list-icon-svg::before `, |
| 429 |
|
| 430 |
styles: { |
| 431 |
"font-size": rangerCss(iconSize, deviceType), |
| 432 |
...(iconSource === "iconSet" && svgIconName === "NumberIcon" |
| 433 |
? { |
| 434 |
width: rangerCss(iconSize, deviceType), |
| 435 |
height: rangerCss(iconSize, deviceType), |
| 436 |
} |
| 437 |
: {}), |
| 438 |
...(iconSource === "iconSet" && svgIconName !== "NumberIcon" |
| 439 |
? { |
| 440 |
width: "0%", |
| 441 |
height: "0%", |
| 442 |
} |
| 443 |
: {}), |
| 444 |
}, |
| 445 |
}, |
| 446 |
]; |
| 447 |
}; |
| 448 |
|
| 449 |
const desktopCss = [ |
| 450 |
...responsiveCss("Desktop"), |
| 451 |
...generalCSS(), |
| 452 |
...iconImageCSS(), |
| 453 |
...contentCSS(), |
| 454 |
...badgeCSS(), |
| 455 |
{ |
| 456 |
class: `#${uniqueId} `, |
| 457 |
styles: { |
| 458 |
display: hideOnDesktop ? "none" : "block", |
| 459 |
}, |
| 460 |
}, |
| 461 |
]; |
| 462 |
|
| 463 |
const tabletCss = [ |
| 464 |
...responsiveCss("Tablet"), |
| 465 |
{ |
| 466 |
class: `#${uniqueId} `, |
| 467 |
styles: { |
| 468 |
display: hideOnTablet ? "none" : "block", |
| 469 |
}, |
| 470 |
}, |
| 471 |
]; |
| 472 |
|
| 473 |
const mobileCss = [ |
| 474 |
...responsiveCss("Mobile"), |
| 475 |
{ |
| 476 |
class: `#${uniqueId} `, |
| 477 |
styles: { |
| 478 |
display: hideOnMobile ? "none" : "block", |
| 479 |
}, |
| 480 |
}, |
| 481 |
]; |
| 482 |
|
| 483 |
const tabletMediaQueryCss = wrapInMediaQuery(objectToCssString(tabletCss), "only screen and (max-width: 1023px)"); |
| 484 |
const mobileMediaQueryCss = wrapInMediaQuery(objectToCssString(mobileCss), "only screen and (max-width: 599px)"); |
| 485 |
return `${objectToCssString(desktopCss)} ${tabletMediaQueryCss} ${mobileMediaQueryCss}`; |
| 486 |
}; |
| 487 |
|
| 488 |
export default dynamicCss; |
| 489 |
|