({
animate = true,
backgroundColor = '#f5f6f7',
backgroundOpacity = 1,
baseUrl = '',
children,
foregroundColor = '#eee',
foregroundOpacity = 1,
gradientRatio = 2,
uniqueKey,
rtl = false,
speed = 1.2,
style = {},
title = 'Loading...',
beforeMask = null,
...props
})
| 3 | import { IContentLoaderProps } from './' |
| 4 | |
| 5 | const SVG: React.FC<IContentLoaderProps> = ({ |
| 6 | animate = true, |
| 7 | backgroundColor = '#f5f6f7', |
| 8 | backgroundOpacity = 1, |
| 9 | baseUrl = '', |
| 10 | children, |
| 11 | foregroundColor = '#eee', |
| 12 | foregroundOpacity = 1, |
| 13 | gradientRatio = 2, |
| 14 | uniqueKey, |
| 15 | rtl = false, |
| 16 | speed = 1.2, |
| 17 | style = {}, |
| 18 | title = 'Loading...', |
| 19 | beforeMask = null, |
| 20 | ...props |
| 21 | }) => { |
| 22 | let fixedId = React.useId() |
| 23 | if (uniqueKey) fixedId = uniqueKey |
| 24 | const idClip = `${fixedId}-diff` |
| 25 | const idGradient = `${fixedId}-animated-diff` |
| 26 | const idAria = `${fixedId}-aria` |
| 27 | |
| 28 | const rtlStyle = rtl ? { transform: 'scaleX(-1)' } : null |
| 29 | const dur = `${speed}s` |
| 30 | |
| 31 | const from = `${gradientRatio * -1} 0` |
| 32 | const to = `${gradientRatio} 0` |
| 33 | |
| 34 | return ( |
| 35 | <svg |
| 36 | aria-labelledby={idAria} |
| 37 | role="img" |
| 38 | style={{ ...style, ...rtlStyle }} |
| 39 | {...props} |
| 40 | > |
| 41 | {title ? <title id={idAria}>{title}</title> : null} |
| 42 | {beforeMask && React.isValidElement(beforeMask) ? beforeMask : null} |
| 43 | <rect |
| 44 | role="presentation" |
| 45 | x="0" |
| 46 | y="0" |
| 47 | width="100%" |
| 48 | height="100%" |
| 49 | clipPath={`url(${baseUrl}#${idClip})`} |
| 50 | style={{ fill: `url(${baseUrl}#${idGradient})` }} |
| 51 | /> |
| 52 | |
| 53 | <defs> |
| 54 | <clipPath id={idClip}>{children}</clipPath> |
| 55 | |
| 56 | <linearGradient |
| 57 | id={idGradient} |
| 58 | gradientTransform={`translate(${from})`} |
| 59 | > |
| 60 | <stop |
| 61 | offset="0%" |
| 62 | stopColor={backgroundColor} |
nothing calls this directly
no outgoing calls
no test coverage detected