| 1 |
import { |
| 2 |
generateDimensionsAttributes, |
| 3 |
generateDimensionsControlStyles, |
| 4 |
} from "./dimensionHelpers"; |
| 5 |
|
| 6 |
// Important: the following "generateBorderShadowAttributes" function must be declared below the "generateDimensionsAttributes" function declaration |
| 7 |
// function to generate BorderShadow control's attributes |
| 8 |
export const generateBorderShadowAttributes = (controlName, defaults = {}) => { |
| 9 |
const { |
| 10 |
bdrDefaults = { |
| 11 |
top: 1, |
| 12 |
right: 1, |
| 13 |
bottom: 1, |
| 14 |
left: 1, |
| 15 |
}, |
| 16 |
rdsDefaults = {}, |
| 17 |
noBorder = false, |
| 18 |
noShadow = false, |
| 19 |
defaultBdrColor = false, |
| 20 |
defaultBdrStyle = false, |
| 21 |
noBdrHover = false, |
| 22 |
noShdowHover = false, |
| 23 |
} = defaults; |
| 24 |
|
| 25 |
const bdrColor = defaultBdrColor |
| 26 |
? { |
| 27 |
[`${controlName}borderColor`]: { |
| 28 |
type: "string", |
| 29 |
default: defaultBdrColor, |
| 30 |
}, |
| 31 |
} |
| 32 |
: { |
| 33 |
[`${controlName}borderColor`]: { |
| 34 |
type: "string", |
| 35 |
}, |
| 36 |
}; |
| 37 |
|
| 38 |
const bdrStyle = defaultBdrStyle |
| 39 |
? { |
| 40 |
[`${controlName}borderStyle`]: { |
| 41 |
type: "string", |
| 42 |
default: defaultBdrStyle, |
| 43 |
}, |
| 44 |
} |
| 45 |
: { |
| 46 |
[`${controlName}borderStyle`]: { |
| 47 |
type: "string", |
| 48 |
default: "none", |
| 49 |
}, |
| 50 |
}; |
| 51 |
|
| 52 |
const bdrAttrs = { |
| 53 |
// border attributes ⬇ |
| 54 |
|
| 55 |
...bdrColor, |
| 56 |
...bdrStyle, |
| 57 |
...generateDimensionsAttributes(`${controlName}Bdr_`, bdrDefaults), |
| 58 |
...generateDimensionsAttributes(`${controlName}Rds_`, rdsDefaults), |
| 59 |
}; |
| 60 |
|
| 61 |
const hvBdrAttrs = { |
| 62 |
[`${controlName}BorderType`]: { |
| 63 |
type: "string", |
| 64 |
default: "normal", |
| 65 |
}, |
| 66 |
[`${controlName}HborderColor`]: { |
| 67 |
type: "string", |
| 68 |
}, |
| 69 |
[`${controlName}HborderStyle`]: { |
| 70 |
type: "string", |
| 71 |
default: "none", |
| 72 |
}, |
| 73 |
...generateDimensionsAttributes(`${controlName}HBdr_`), |
| 74 |
...generateDimensionsAttributes(`${controlName}HRds_`), |
| 75 |
}; |
| 76 |
|
| 77 |
const shdAttrs = { |
| 78 |
// shadow attributes ⬇ |
| 79 |
[`${controlName}hOffset`]: { |
| 80 |
type: "number", |
| 81 |
}, |
| 82 |
[`${controlName}vOffset`]: { |
| 83 |
type: "number", |
| 84 |
}, |
| 85 |
[`${controlName}blur`]: { |
| 86 |
type: "number", |
| 87 |
}, |
| 88 |
[`${controlName}spread`]: { |
| 89 |
type: "number", |
| 90 |
}, |
| 91 |
[`${controlName}shadowColor`]: { |
| 92 |
type: "string", |
| 93 |
}, |
| 94 |
[`${controlName}inset`]: { |
| 95 |
type: "boolean", |
| 96 |
default: false, |
| 97 |
}, |
| 98 |
}; |
| 99 |
|
| 100 |
const hvShdAttrs = { |
| 101 |
[`${controlName}shadowType`]: { |
| 102 |
type: "string", |
| 103 |
default: "normal", |
| 104 |
}, |
| 105 |
[`${controlName}hoverHOffset`]: { |
| 106 |
type: "number", |
| 107 |
}, |
| 108 |
[`${controlName}hoverVOffset`]: { |
| 109 |
type: "number", |
| 110 |
}, |
| 111 |
[`${controlName}hoverBlur`]: { |
| 112 |
type: "number", |
| 113 |
}, |
| 114 |
[`${controlName}hoverSpread`]: { |
| 115 |
type: "number", |
| 116 |
}, |
| 117 |
[`${controlName}hoverShadowColor`]: { |
| 118 |
type: "string", |
| 119 |
}, |
| 120 |
[`${controlName}hoverInset`]: { |
| 121 |
type: "boolean", |
| 122 |
default: false, |
| 123 |
}, |
| 124 |
}; |
| 125 |
|
| 126 |
const transitionAttrs = { |
| 127 |
[`${controlName}borderTransition`]: { |
| 128 |
type: "number", |
| 129 |
default: 0.5, |
| 130 |
}, |
| 131 |
[`${controlName}radiusTransition`]: { |
| 132 |
type: "number", |
| 133 |
default: 0.5, |
| 134 |
}, |
| 135 |
[`${controlName}shadowTransition`]: { |
| 136 |
type: "number", |
| 137 |
default: 0.5, |
| 138 |
}, |
| 139 |
}; |
| 140 |
|
| 141 |
if (noBorder === true) { |
| 142 |
if (noShdowHover) { |
| 143 |
return { |
| 144 |
...shdAttrs, |
| 145 |
}; |
| 146 |
} else { |
| 147 |
return { |
| 148 |
...shdAttrs, |
| 149 |
...hvShdAttrs, |
| 150 |
...transitionAttrs, |
| 151 |
}; |
| 152 |
} |
| 153 |
} else if (noShadow === true) { |
| 154 |
if (noBdrHover) { |
| 155 |
return { |
| 156 |
...bdrAttrs, |
| 157 |
}; |
| 158 |
} else { |
| 159 |
return { |
| 160 |
...bdrAttrs, |
| 161 |
...hvBdrAttrs, |
| 162 |
...transitionAttrs, |
| 163 |
}; |
| 164 |
} |
| 165 |
} else { |
| 166 |
let result = {}; |
| 167 |
|
| 168 |
if (noShdowHover && noBdrHover) { |
| 169 |
result = { |
| 170 |
...bdrAttrs, |
| 171 |
...shdAttrs, |
| 172 |
}; |
| 173 |
} else if (noShdowHover && !noBdrHover) { |
| 174 |
result = { |
| 175 |
...bdrAttrs, |
| 176 |
...hvBdrAttrs, |
| 177 |
...transitionAttrs, |
| 178 |
...shdAttrs, |
| 179 |
}; |
| 180 |
} else if (!noShdowHover && noBdrHover) { |
| 181 |
result = { |
| 182 |
...shdAttrs, |
| 183 |
...hvShdAttrs, |
| 184 |
...transitionAttrs, |
| 185 |
...bdrAttrs, |
| 186 |
}; |
| 187 |
} else if (!noShdowHover && !noBdrHover) { |
| 188 |
result = { |
| 189 |
...bdrAttrs, |
| 190 |
...shdAttrs, |
| 191 |
...hvShdAttrs, |
| 192 |
...hvBdrAttrs, |
| 193 |
...transitionAttrs, |
| 194 |
}; |
| 195 |
} |
| 196 |
|
| 197 |
return result; |
| 198 |
} |
| 199 |
}; |
| 200 |
|
| 201 |
// Important: the following "generateBorderShadowStyles" function must be declared below the "generateDimensionsControlStyles" function declaration |
| 202 |
// function to generate BorderShadow control's Styles for an element based on it's controlName(prefix) |
| 203 |
export const generateBorderShadowStyles = ({ |
| 204 |
controlName, |
| 205 |
attributes, |
| 206 |
noBorder, |
| 207 |
noShadow, |
| 208 |
}) => { |
| 209 |
let borderStylesDesktop = ""; |
| 210 |
let borderStylesTab = ""; |
| 211 |
let borderStylesMobile = ""; |
| 212 |
let radiusStylesDesktop = ""; |
| 213 |
let radiusStylesTab = ""; |
| 214 |
let radiusStylesMobile = ""; |
| 215 |
let HborderStylesDesktop = ""; |
| 216 |
let HborderStylesTab = ""; |
| 217 |
let HborderStylesMobile = ""; |
| 218 |
let HradiusStylesDesktop = ""; |
| 219 |
let HradiusStylesTab = ""; |
| 220 |
let HradiusStylesMobile = ""; |
| 221 |
|
| 222 |
if (noBorder !== true) { |
| 223 |
const { |
| 224 |
dimensionStylesDesktop: F_borderStylesDesktop, |
| 225 |
dimensionStylesTab: F_borderStylesTab, |
| 226 |
dimensionStylesMobile: F_borderStylesMobile, |
| 227 |
} = generateDimensionsControlStyles({ |
| 228 |
controlName: `${controlName}Bdr_`, |
| 229 |
styleFor: "border", |
| 230 |
attributes, |
| 231 |
}); |
| 232 |
|
| 233 |
const { |
| 234 |
dimensionStylesDesktop: F_radiusStylesDesktop, |
| 235 |
dimensionStylesTab: F_radiusStylesTab, |
| 236 |
dimensionStylesMobile: F_radiusStylesMobile, |
| 237 |
} = generateDimensionsControlStyles({ |
| 238 |
controlName: `${controlName}Rds_`, |
| 239 |
styleFor: "border-radius", |
| 240 |
attributes, |
| 241 |
}); |
| 242 |
|
| 243 |
const { |
| 244 |
dimensionStylesDesktop: F_HborderStylesDesktop, |
| 245 |
dimensionStylesTab: F_HborderStylesTab, |
| 246 |
dimensionStylesMobile: F_HborderStylesMobile, |
| 247 |
} = generateDimensionsControlStyles({ |
| 248 |
controlName: `${controlName}HBdr_`, |
| 249 |
styleFor: "border", |
| 250 |
attributes, |
| 251 |
}); |
| 252 |
|
| 253 |
const { |
| 254 |
dimensionStylesDesktop: F_HradiusStylesDesktop, |
| 255 |
dimensionStylesTab: F_HradiusStylesTab, |
| 256 |
dimensionStylesMobile: F_HradiusStylesMobile, |
| 257 |
} = generateDimensionsControlStyles({ |
| 258 |
controlName: `${controlName}HRds_`, |
| 259 |
styleFor: "border-radius", |
| 260 |
attributes, |
| 261 |
}); |
| 262 |
|
| 263 |
borderStylesDesktop = F_borderStylesDesktop; |
| 264 |
borderStylesTab = F_borderStylesTab; |
| 265 |
borderStylesMobile = F_borderStylesMobile; |
| 266 |
radiusStylesDesktop = F_radiusStylesDesktop; |
| 267 |
radiusStylesTab = F_radiusStylesTab; |
| 268 |
radiusStylesMobile = F_radiusStylesMobile; |
| 269 |
HborderStylesDesktop = F_HborderStylesDesktop; |
| 270 |
HborderStylesTab = F_HborderStylesTab; |
| 271 |
HborderStylesMobile = F_HborderStylesMobile; |
| 272 |
HradiusStylesDesktop = F_HradiusStylesDesktop; |
| 273 |
HradiusStylesTab = F_HradiusStylesTab; |
| 274 |
HradiusStylesMobile = F_HradiusStylesMobile; |
| 275 |
} |
| 276 |
|
| 277 |
// const { |
| 278 |
// dimensionStylesDesktop: borderStylesDesktop, |
| 279 |
// dimensionStylesTab: borderStylesTab, |
| 280 |
// dimensionStylesMobile: borderStylesMobile, |
| 281 |
// } = generateDimensionsControlStyles({ |
| 282 |
// controlName: `${controlName}Bdr_`, |
| 283 |
// styleFor: "border", |
| 284 |
// attributes, |
| 285 |
// }); |
| 286 |
|
| 287 |
// const { |
| 288 |
// dimensionStylesDesktop: radiusStylesDesktop, |
| 289 |
// dimensionStylesTab: radiusStylesTab, |
| 290 |
// dimensionStylesMobile: radiusStylesMobile, |
| 291 |
// } = generateDimensionsControlStyles({ |
| 292 |
// controlName: `${controlName}Rds_`, |
| 293 |
// styleFor: "border-radius", |
| 294 |
// attributes, |
| 295 |
// }); |
| 296 |
|
| 297 |
// const { |
| 298 |
// dimensionStylesDesktop: HborderStylesDesktop, |
| 299 |
// dimensionStylesTab: HborderStylesTab, |
| 300 |
// dimensionStylesMobile: HborderStylesMobile, |
| 301 |
// } = generateDimensionsControlStyles({ |
| 302 |
// controlName: `${controlName}HBdr_`, |
| 303 |
// styleFor: "border", |
| 304 |
// attributes, |
| 305 |
// }); |
| 306 |
|
| 307 |
// const { |
| 308 |
// dimensionStylesDesktop: HradiusStylesDesktop, |
| 309 |
// dimensionStylesTab: HradiusStylesTab, |
| 310 |
// dimensionStylesMobile: HradiusStylesMobile, |
| 311 |
// } = generateDimensionsControlStyles({ |
| 312 |
// controlName: `${controlName}HRds_`, |
| 313 |
// styleFor: "border-radius", |
| 314 |
// attributes, |
| 315 |
// }); |
| 316 |
|
| 317 |
const { |
| 318 |
// [`${controlName}BorderType`]: BorderType, |
| 319 |
[`${controlName}borderStyle`]: borderStyle, |
| 320 |
[`${controlName}borderColor`]: borderColor, |
| 321 |
[`${controlName}HborderStyle`]: HborderStyle, |
| 322 |
[`${controlName}HborderColor`]: HborderColor, |
| 323 |
|
| 324 |
[`${controlName}shadowColor`]: shadowColor, |
| 325 |
[`${controlName}hOffset`]: hOffset = 0, |
| 326 |
[`${controlName}vOffset`]: vOffset = 0, |
| 327 |
[`${controlName}blur`]: blur = 0, |
| 328 |
[`${controlName}spread`]: spread = 0, |
| 329 |
[`${controlName}inset`]: inset, |
| 330 |
|
| 331 |
[`${controlName}hoverShadowColor`]: hoverShadowColor = shadowColor, |
| 332 |
[`${controlName}hoverHOffset`]: hoverHOffset = hOffset, |
| 333 |
[`${controlName}hoverVOffset`]: hoverVOffset = vOffset, |
| 334 |
[`${controlName}hoverBlur`]: hoverBlur = blur, |
| 335 |
[`${controlName}hoverSpread`]: hoverSpread = spread, |
| 336 |
|
| 337 |
[`${controlName}borderTransition`]: borderTransition, |
| 338 |
[`${controlName}radiusTransition`]: radiusTransition, |
| 339 |
[`${controlName}shadowTransition`]: shadowTransition, |
| 340 |
} = attributes; |
| 341 |
|
| 342 |
const stylesDesktop = ` |
| 343 |
${ |
| 344 |
noBorder !== true |
| 345 |
? ` |
| 346 |
${radiusStylesDesktop} |
| 347 |
${ |
| 348 |
borderStyle !== "none" && borderColor |
| 349 |
? ` |
| 350 |
${borderStylesDesktop} |
| 351 |
border-color: ${borderColor}; |
| 352 |
border-style: ${borderStyle}; |
| 353 |
` |
| 354 |
: " " |
| 355 |
} |
| 356 |
` |
| 357 |
: " " |
| 358 |
} |
| 359 |
|
| 360 |
${ |
| 361 |
noShadow !== true |
| 362 |
? shadowColor |
| 363 |
? `box-shadow: ${shadowColor} ${hOffset}px ${vOffset}px ${blur}px ${spread}px ${ |
| 364 |
inset ? "inset" : "" |
| 365 |
};` |
| 366 |
: " " |
| 367 |
: " " |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
`; |
| 372 |
|
| 373 |
const stylesTab = ` |
| 374 |
${ |
| 375 |
noBorder !== true |
| 376 |
? ` |
| 377 |
${borderColor ? borderStylesTab : " "} |
| 378 |
${radiusStylesTab} |
| 379 |
` |
| 380 |
: " " |
| 381 |
} |
| 382 |
|
| 383 |
`; |
| 384 |
|
| 385 |
const stylesMobile = ` |
| 386 |
${ |
| 387 |
noBorder !== true |
| 388 |
? ` |
| 389 |
${borderColor ? borderStylesMobile : " "} |
| 390 |
${radiusStylesMobile} |
| 391 |
` |
| 392 |
: " " |
| 393 |
} |
| 394 |
`; |
| 395 |
|
| 396 |
const stylesHoverDesktop = ` |
| 397 |
${ |
| 398 |
noBorder !== true |
| 399 |
? ` |
| 400 |
${ |
| 401 |
HborderStyle !== "none" |
| 402 |
? ` |
| 403 |
${ |
| 404 |
HborderColor !== borderColor |
| 405 |
? `border-color: ${HborderColor};` |
| 406 |
: " " |
| 407 |
} |
| 408 |
${ |
| 409 |
HborderStyle !== borderStyle |
| 410 |
? `border-style: ${HborderStyle};` |
| 411 |
: " " |
| 412 |
} |
| 413 |
${HborderStylesDesktop} |
| 414 |
` |
| 415 |
: " " |
| 416 |
} |
| 417 |
|
| 418 |
${HradiusStylesDesktop} |
| 419 |
` |
| 420 |
: " " |
| 421 |
} |
| 422 |
|
| 423 |
${ |
| 424 |
noShadow !== true |
| 425 |
? hoverShadowColor |
| 426 |
? `box-shadow: ${hoverShadowColor} ${hoverHOffset}px ${hoverVOffset}px ${hoverBlur}px ${hoverSpread}px ${ |
| 427 |
inset ? "inset" : " " |
| 428 |
};` |
| 429 |
: " " |
| 430 |
: " " |
| 431 |
} |
| 432 |
|
| 433 |
`; |
| 434 |
|
| 435 |
const stylesHoverTab = ` |
| 436 |
${ |
| 437 |
noBorder !== true |
| 438 |
? ` |
| 439 |
${HborderStyle !== "none" ? HborderStylesTab : " "} |
| 440 |
${HradiusStylesTab} |
| 441 |
` |
| 442 |
: " " |
| 443 |
} |
| 444 |
`; |
| 445 |
|
| 446 |
const stylesHoverMobile = ` |
| 447 |
${ |
| 448 |
noBorder !== true |
| 449 |
? ` |
| 450 |
${HborderStyle !== "none" ? HborderStylesMobile : " "} |
| 451 |
${HradiusStylesMobile} |
| 452 |
` |
| 453 |
: " " |
| 454 |
} |
| 455 |
|
| 456 |
`; |
| 457 |
|
| 458 |
const transitionStyle = ` |
| 459 |
border ${borderTransition || 0}s, border-radius ${ |
| 460 |
radiusTransition || 0 |
| 461 |
}s, box-shadow ${shadowTransition || 0}s |
| 462 |
`; |
| 463 |
|
| 464 |
return { |
| 465 |
stylesDesktop, |
| 466 |
stylesTab, |
| 467 |
stylesMobile, |
| 468 |
stylesHoverDesktop, |
| 469 |
stylesHoverTab, |
| 470 |
stylesHoverMobile, |
| 471 |
transitionStyle, |
| 472 |
}; |
| 473 |
}; |
| 474 |
|