| 1 |
import { |
| 2 |
boxCss, |
| 3 |
checkInArray, |
| 4 |
colorControls, |
| 5 |
objectToCssString, |
| 6 |
removeEmptyCss, |
| 7 |
spacingGenerate, |
| 8 |
wrapInMediaQuery, |
| 9 |
} from "../shared/helpFn"; |
| 10 |
|
| 11 |
const cacheCss = { desktop: "", mobile: "", tablet: "" }; |
| 12 |
|
| 13 |
const dynamicCss = (attributes, page = "frontend", currentDevice = "all") => { |
| 14 |
const { |
| 15 |
uniqueId, |
| 16 |
socialVerticalGap, |
| 17 |
socialHorizontalGap, |
| 18 |
layout, |
| 19 |
columns, |
| 20 |
socialLabelPosition, |
| 21 |
socialLabelEnable, |
| 22 |
socialLabelGap, |
| 23 |
socialSubTextEnable, |
| 24 |
socialSubTextGap, |
| 25 |
socialIconSize, |
| 26 |
socialIconBGSize, |
| 27 |
socialIconCustomColorEnable, |
| 28 |
socialIconColor, |
| 29 |
socialIconBg, |
| 30 |
socialLabelColor, |
| 31 |
socialSubTextColor, |
| 32 |
socialIconBorder, |
| 33 |
socialIconBorderWidth, |
| 34 |
socialIconBorderRadius, |
| 35 |
socialIconBorderHover, |
| 36 |
socialIconBorderWidthHover, |
| 37 |
socialIconBorderRadiusHover, |
| 38 |
socialIconMargin, |
| 39 |
socialLabelTypography, |
| 40 |
socialSubTextTypography, |
| 41 |
socialLabelFontSize, |
| 42 |
socialLabelLetterSpacing, |
| 43 |
socialLabelLineHeight, |
| 44 |
socialSubTextFontSize, |
| 45 |
socialSubTextLetterSpacing, |
| 46 |
socialSubTextLineHeight, |
| 47 |
socialIconBoxShadowEnable, |
| 48 |
socialIconBoxShadowValue, |
| 49 |
socialIconBoxShadowHoverEnable, |
| 50 |
socialIconBoxShadowHoverValue, |
| 51 |
socialContentAreaBG, |
| 52 |
socialContentAreaBorder, |
| 53 |
socialContentAreaBorderHover, |
| 54 |
socialContentAreaBorderWidth, |
| 55 |
socialContentAreaBorderRadius, |
| 56 |
socialContentAreaShadowEnable, |
| 57 |
socialContentAreaShadow, |
| 58 |
socialContentAreaPadding, |
| 59 |
socialContentAreaMargin, |
| 60 |
socialContentAreaBorderWidthHover, |
| 61 |
socialContentAreaBorderRadiusHover, |
| 62 |
socialContentAreaShadowHoverEnable, |
| 63 |
socialContentAreaShadowHover, |
| 64 |
socialIconDividerColor, |
| 65 |
// socialContentAreaBgBlur, |
| 66 |
socialLabelWordSpacing, |
| 67 |
socialSubTextWordSpacing, |
| 68 |
hideOnDesktop, |
| 69 |
hideOnTablet, |
| 70 |
hideOnMobile, |
| 71 |
globalBreakPointData, |
| 72 |
} = attributes; |
| 73 |
|
| 74 |
const layoutGridTemplate = ["social-profiles-layout-one", "social-profiles-layout-two"].includes(layout) |
| 75 |
? "auto" |
| 76 |
: "1fr"; |
| 77 |
|
| 78 |
const responsiveCss = (deviceType) => { |
| 79 |
let responsiveStyle; |
| 80 |
responsiveStyle = [ |
| 81 |
{ |
| 82 |
class: `#${uniqueId} .sp-social-profile-item-icon-wrapper`, |
| 83 |
styles: { |
| 84 |
width: socialIconBGSize.device?.[deviceType] + socialIconBGSize.unit?.[deviceType], |
| 85 |
height: socialIconBGSize.device?.[deviceType] + socialIconBGSize.unit?.[deviceType], |
| 86 |
"border-width": spacingGenerate(socialIconBorderWidth, [deviceType]), |
| 87 |
"border-radius": spacingGenerate(socialIconBorderRadius, [deviceType]), |
| 88 |
"box-shadow": boxCss(socialIconBoxShadowEnable, [deviceType], socialIconBoxShadowValue, "color"), |
| 89 |
"margin-top": socialIconMargin?.device?.[deviceType]?.top + socialIconMargin?.unit?.[deviceType], |
| 90 |
"margin-right": |
| 91 |
socialIconMargin?.device?.[deviceType]?.right + socialIconMargin?.unit?.[deviceType], |
| 92 |
"margin-bottom": |
| 93 |
socialIconMargin?.device?.[deviceType]?.bottom + socialIconMargin?.unit?.[deviceType], |
| 94 |
"margin-left": socialIconMargin?.device?.[deviceType]?.left + socialIconMargin?.unit?.[deviceType], |
| 95 |
}, |
| 96 |
}, |
| 97 |
{ |
| 98 |
class: `#${uniqueId} .sp-social-profile-item-wrapper .sp-social-profile-item .sp-social-profile-item-icon i::before`, |
| 99 |
styles: { |
| 100 |
"font-size": socialIconSize.device?.[deviceType] + socialIconSize.unit?.[deviceType], |
| 101 |
}, |
| 102 |
}, |
| 103 |
{ |
| 104 |
class: `#${uniqueId} .sp-social-profile-item-icon-wrapper:hover`, |
| 105 |
styles: { |
| 106 |
"box-shadow": boxCss( |
| 107 |
socialIconBoxShadowHoverEnable, |
| 108 |
[deviceType], |
| 109 |
socialIconBoxShadowHoverValue, |
| 110 |
"color" |
| 111 |
), |
| 112 |
"border-width": spacingGenerate(socialIconBorderWidthHover, [deviceType]), |
| 113 |
"border-radius": spacingGenerate(socialIconBorderRadiusHover, [deviceType]), |
| 114 |
}, |
| 115 |
}, |
| 116 |
// Social Label |
| 117 |
{ |
| 118 |
class: `#${uniqueId} .sp-social-profile-item-label`, |
| 119 |
styles: { |
| 120 |
"font-size": socialLabelFontSize.device?.[deviceType] + socialLabelFontSize.unit?.[deviceType], |
| 121 |
"line-height": socialLabelLineHeight.device?.[deviceType], |
| 122 |
"letter-spacing": |
| 123 |
socialLabelLetterSpacing.device?.[deviceType] + socialLabelLetterSpacing.unit?.[deviceType], |
| 124 |
"word-spacing": |
| 125 |
socialLabelWordSpacing.device?.[deviceType] + socialLabelWordSpacing.unit?.[deviceType], |
| 126 |
}, |
| 127 |
}, |
| 128 |
{ |
| 129 |
class: `#${uniqueId} .sp-social-profile-item-sub-text`, |
| 130 |
styles: { |
| 131 |
"font-size": socialSubTextFontSize.device?.[deviceType] + socialSubTextFontSize.unit?.[deviceType], |
| 132 |
"line-height": socialSubTextLineHeight.device?.[deviceType], |
| 133 |
"letter-spacing": |
| 134 |
socialSubTextLetterSpacing.device?.[deviceType] + socialSubTextLetterSpacing.unit?.[deviceType], |
| 135 |
"word-spacing": |
| 136 |
socialSubTextWordSpacing.device?.[deviceType] + socialSubTextWordSpacing.unit?.[deviceType], |
| 137 |
}, |
| 138 |
}, |
| 139 |
{ |
| 140 |
class: `#${uniqueId} .sp-social-profile-item-container .sp-social-profile-item-wrapper`, |
| 141 |
styles: { |
| 142 |
"border-width": spacingGenerate(socialContentAreaBorderWidth, [deviceType]), |
| 143 |
"border-radius": spacingGenerate(socialContentAreaBorderRadius, [deviceType]), |
| 144 |
"box-shadow": boxCss(socialContentAreaShadowEnable, [deviceType], socialContentAreaShadow, "color"), |
| 145 |
padding: spacingGenerate(socialContentAreaPadding, [deviceType]), |
| 146 |
margin: spacingGenerate(socialContentAreaMargin, [deviceType]), |
| 147 |
}, |
| 148 |
}, |
| 149 |
{ |
| 150 |
class: `#${uniqueId} .sp-social-profile-item-container:hover .sp-social-profile-item-wrapper`, |
| 151 |
styles: { |
| 152 |
"border-width": spacingGenerate(socialContentAreaBorderWidthHover, [deviceType]), |
| 153 |
"border-radius": spacingGenerate(socialContentAreaBorderRadiusHover, [deviceType]), |
| 154 |
"box-shadow": boxCss( |
| 155 |
socialContentAreaShadowHoverEnable, |
| 156 |
[deviceType], |
| 157 |
socialContentAreaShadowHover, |
| 158 |
"color" |
| 159 |
), |
| 160 |
}, |
| 161 |
}, |
| 162 |
{ |
| 163 |
class: `#${uniqueId} .sp-social-profile-item-container .sp-social-profile-icon-divider`, |
| 164 |
styles: { |
| 165 |
height: socialIconBGSize.device?.[deviceType] * 0.75 + socialIconBGSize.unit?.[deviceType], |
| 166 |
}, |
| 167 |
}, |
| 168 |
]; |
| 169 |
if ("social-profiles-layout-five" === layout) { |
| 170 |
responsiveStyle.push( |
| 171 |
...[ |
| 172 |
{ |
| 173 |
class: `#${uniqueId} .sp-social-profile-item-container`, |
| 174 |
styles: { |
| 175 |
"margin-right": `-${ |
| 176 |
socialContentAreaBorderWidth?.device?.[deviceType]?.right + |
| 177 |
socialContentAreaBorderWidth?.unit?.[deviceType] |
| 178 |
}`, |
| 179 |
"margin-bottom": `-${ |
| 180 |
socialContentAreaBorderWidth?.device?.[deviceType]?.bottom + |
| 181 |
socialContentAreaBorderWidth?.unit?.[deviceType] |
| 182 |
}`, |
| 183 |
}, |
| 184 |
}, |
| 185 |
] |
| 186 |
); |
| 187 |
} |
| 188 |
if (page === "editor") { |
| 189 |
responsiveStyle.push( |
| 190 |
...[ |
| 191 |
{ |
| 192 |
class: `#${uniqueId} .block-editor-block-list__layout`, |
| 193 |
styles: { |
| 194 |
"column-gap": |
| 195 |
layout !== "social-profiles-layout-five" |
| 196 |
? socialHorizontalGap.device?.[deviceType] + socialHorizontalGap.unit?.[deviceType] |
| 197 |
: "0", |
| 198 |
"row-gap": |
| 199 |
layout !== "social-profiles-layout-five" |
| 200 |
? socialVerticalGap.device?.[deviceType] + socialVerticalGap.unit?.[deviceType] |
| 201 |
: "0", |
| 202 |
"grid-template-columns": `repeat(${columns.device?.[deviceType]}, ${layoutGridTemplate})`, |
| 203 |
}, |
| 204 |
}, |
| 205 |
] |
| 206 |
); |
| 207 |
} |
| 208 |
if (page !== "editor") { |
| 209 |
responsiveStyle.push( |
| 210 |
...[ |
| 211 |
{ |
| 212 |
class: `#${uniqueId} .sp-social-profile-wrapper.${layout} .sp-social-profile-wrapper-grid-class`, |
| 213 |
styles: { |
| 214 |
"column-gap": |
| 215 |
layout !== "social-profiles-layout-five" |
| 216 |
? socialHorizontalGap.device?.[deviceType] + socialHorizontalGap.unit?.[deviceType] |
| 217 |
: "0", |
| 218 |
"row-gap": |
| 219 |
layout !== "social-profiles-layout-five" |
| 220 |
? socialVerticalGap.device?.[deviceType] + socialVerticalGap.unit?.[deviceType] |
| 221 |
: "0", |
| 222 |
"grid-template-columns": `repeat(${columns.device?.[deviceType]}, ${layoutGridTemplate})`, |
| 223 |
}, |
| 224 |
}, |
| 225 |
] |
| 226 |
); |
| 227 |
} |
| 228 |
return responsiveStyle; |
| 229 |
}; |
| 230 |
|
| 231 |
const desktopCss = [ |
| 232 |
...responsiveCss("Desktop"), |
| 233 |
{ |
| 234 |
class: `#${uniqueId} .sp-social-profile-item-wrapper .sp-social-profile-item`, |
| 235 |
styles: { |
| 236 |
"flex-direction": checkInArray(layout) |
| 237 |
? socialLabelPosition === "bottom" |
| 238 |
? "column" |
| 239 |
: "column-reverse" |
| 240 |
: socialLabelPosition === "right" |
| 241 |
? "row" |
| 242 |
: "row-reverse", |
| 243 |
gap: |
| 244 |
(socialLabelEnable && socialLabelGap.value + socialLabelGap.unit) || |
| 245 |
(socialSubTextEnable && socialSubTextGap.value + socialSubTextGap.unit) || |
| 246 |
"0", |
| 247 |
}, |
| 248 |
}, |
| 249 |
{ |
| 250 |
class: `#${uniqueId} .sp-social-profile-item-wrapper .sp-social-profile-item .sp-social-profile-item-text`, |
| 251 |
styles: { |
| 252 |
"flex-direction": checkInArray(layout) |
| 253 |
? socialLabelPosition === "bottom" |
| 254 |
? "column" |
| 255 |
: "column-reverse" |
| 256 |
: socialLabelPosition === "right" |
| 257 |
? "row" |
| 258 |
: "row-reverse", |
| 259 |
gap: |
| 260 |
socialSubTextEnable && layout !== "social-profiles-layout-three" |
| 261 |
? socialSubTextGap.value + socialSubTextGap.unit |
| 262 |
: "0", |
| 263 |
}, |
| 264 |
}, |
| 265 |
...removeEmptyCss( |
| 266 |
`#${uniqueId} .sp-social-profile-item-label`, |
| 267 |
"font-family", |
| 268 |
socialLabelTypography?.typography?.family, |
| 269 |
false |
| 270 |
), |
| 271 |
{ |
| 272 |
class: `#${uniqueId} .sp-social-profile-item-label`, |
| 273 |
styles: { |
| 274 |
color: socialLabelColor.color, |
| 275 |
"font-weight": socialLabelTypography?.typography?.fontWeight, |
| 276 |
"font-style": socialLabelTypography?.typography?.style, |
| 277 |
"text-transform": socialLabelTypography?.typography?.transform, |
| 278 |
"text-decoration": socialLabelTypography?.typography?.decoration, |
| 279 |
}, |
| 280 |
}, |
| 281 |
{ |
| 282 |
class: `#${uniqueId} .sp-social-profile-item-container:hover .sp-social-profile-item-label`, |
| 283 |
styles: { |
| 284 |
color: socialLabelColor.hoverColor, |
| 285 |
}, |
| 286 |
}, |
| 287 |
...removeEmptyCss( |
| 288 |
`#${uniqueId} .sp-social-profile-item-sub-text`, |
| 289 |
"font-family", |
| 290 |
socialSubTextTypography?.typography?.family, |
| 291 |
false |
| 292 |
), |
| 293 |
{ |
| 294 |
class: `#${uniqueId} .sp-social-profile-item-sub-text`, |
| 295 |
styles: { |
| 296 |
color: socialSubTextColor.color, |
| 297 |
"font-weight": socialSubTextTypography?.typography?.fontWeight, |
| 298 |
"font-style": socialSubTextTypography?.typography?.style, |
| 299 |
"text-transform": socialSubTextTypography?.typography?.transform, |
| 300 |
"text-decoration": socialSubTextTypography?.typography?.decoration, |
| 301 |
}, |
| 302 |
}, |
| 303 |
{ |
| 304 |
class: `#${uniqueId} .sp-social-profile-item-container:hover .sp-social-profile-item-sub-text`, |
| 305 |
styles: { |
| 306 |
color: socialSubTextColor.hoverColor, |
| 307 |
}, |
| 308 |
}, |
| 309 |
{ |
| 310 |
class: `#${uniqueId} .sp-social-profile-item-icon-wrapper`, |
| 311 |
styles: { |
| 312 |
background: colorControls( |
| 313 |
socialIconBg?.color?.style, |
| 314 |
socialIconBg?.color?.solidColor, |
| 315 |
socialIconBg?.color?.gradient |
| 316 |
), |
| 317 |
"border-style": socialIconBorder.style, |
| 318 |
"border-color": socialIconBorder.color, |
| 319 |
}, |
| 320 |
}, |
| 321 |
{ |
| 322 |
class: `#${uniqueId} .sp-social-profile-item-icon-wrapper:hover`, |
| 323 |
styles: { |
| 324 |
background: colorControls( |
| 325 |
socialIconBg?.hover?.style, |
| 326 |
socialIconBg?.hover?.solidColor, |
| 327 |
socialIconBg?.hover?.gradient |
| 328 |
), |
| 329 |
"border-style": socialIconBorderHover.style, |
| 330 |
"border-color": socialIconBorderHover.color, |
| 331 |
}, |
| 332 |
}, |
| 333 |
{ |
| 334 |
class: `#${uniqueId} .sp-social-profile-item-container .sp-social-profile-item-wrapper`, |
| 335 |
styles: { |
| 336 |
background: colorControls( |
| 337 |
socialContentAreaBG?.color?.style, |
| 338 |
socialContentAreaBG?.color?.solidColor, |
| 339 |
socialContentAreaBG?.color?.gradient |
| 340 |
), |
| 341 |
"border-style": socialContentAreaBorder.style, |
| 342 |
"border-color": socialContentAreaBorder.color, |
| 343 |
}, |
| 344 |
}, |
| 345 |
{ |
| 346 |
class: `#${uniqueId} .sp-social-profile-item-container:hover .sp-social-profile-item-wrapper`, |
| 347 |
styles: { |
| 348 |
background: colorControls( |
| 349 |
socialContentAreaBG?.hover?.style, |
| 350 |
socialContentAreaBG?.hover?.solidColor, |
| 351 |
socialContentAreaBG?.hover?.gradient |
| 352 |
), |
| 353 |
"border-style": socialContentAreaBorderHover.style, |
| 354 |
"border-color": socialContentAreaBorderHover.color, |
| 355 |
}, |
| 356 |
}, |
| 357 |
{ |
| 358 |
class: `#${uniqueId} .sp-social-profile-item-container .sp-social-profile-icon-divider`, |
| 359 |
styles: { |
| 360 |
background: socialIconDividerColor.color, |
| 361 |
}, |
| 362 |
}, |
| 363 |
{ |
| 364 |
class: `#${uniqueId} .sp-social-profile-item-container:hover .sp-social-profile-icon-divider`, |
| 365 |
styles: { |
| 366 |
background: socialIconDividerColor.hover, |
| 367 |
}, |
| 368 |
} |
| 369 |
]; |
| 370 |
if (socialIconCustomColorEnable) { |
| 371 |
desktopCss.push( |
| 372 |
...[ |
| 373 |
{ |
| 374 |
class: `#${uniqueId} .sp-social-profile-item-icon .sp-social-profile-item-icon-class`, |
| 375 |
styles: { |
| 376 |
color: socialIconColor?.color, |
| 377 |
}, |
| 378 |
}, |
| 379 |
{ |
| 380 |
class: `#${uniqueId} .sp-social-profile-item-icon .sp-social-profile-item-icon-class:hover`, |
| 381 |
styles: { |
| 382 |
color: socialIconColor?.color, |
| 383 |
}, |
| 384 |
}, |
| 385 |
] |
| 386 |
); |
| 387 |
} |
| 388 |
cacheCss.desktop = objectToCssString(desktopCss); |
| 389 |
|
| 390 |
if ("Tablet" === currentDevice || "all" === currentDevice) { |
| 391 |
const tabletCss = [ |
| 392 |
...responsiveCss("Tablet") |
| 393 |
]; |
| 394 |
cacheCss.tablet = wrapInMediaQuery( |
| 395 |
objectToCssString(tabletCss), |
| 396 |
`only screen and (max-width: ${globalBreakPointData?.tablet}px)` |
| 397 |
); |
| 398 |
} |
| 399 |
if ("Mobile" === currentDevice || "all" === currentDevice) { |
| 400 |
const mobileCss = [ |
| 401 |
...responsiveCss("Mobile") |
| 402 |
]; |
| 403 |
|
| 404 |
cacheCss.mobile = wrapInMediaQuery( |
| 405 |
objectToCssString(mobileCss), |
| 406 |
`only screen and (max-width: ${globalBreakPointData?.mobile}px)` |
| 407 |
); |
| 408 |
} |
| 409 |
|
| 410 |
return `${cacheCss.desktop} ${cacheCss.tablet} ${cacheCss.mobile}`; |
| 411 |
}; |
| 412 |
|
| 413 |
export default dynamicCss; |
| 414 |
|