Skip to content

Instantly share code, notes, and snippets.

@xavxyz
Created January 10, 2018 10:25
Show Gist options
  • Save xavxyz/19291b66c17829d36c57db1ae9c92378 to your computer and use it in GitHub Desktop.
Save xavxyz/19291b66c17829d36c57db1ae9c92378 to your computer and use it in GitHub Desktop.
const opticalGradient = [
// bottom left rectangle
{x: 0, y: 60, start: 0.5, end: 0 },
// top left rectangle
{x: 0, y: 0, start: 0.5, end: 0.75 },
// top right rectangle
{x: 60, y: 0, start: 0.75, end: 0.9 },
// bottom right rectangle
{x: 60, y: 60, start: 0.9, end: 1 },
];
const OpticalGradient = props => {
return props.definitions.map(
({ x, y, start, end }) => [
<linearGradient id={`gradient-${x}-${y}`} key="gradient">
<stop offset="0%" stopColor="#FFF" stopOpacity={start} />
<stop offset="100%" stopColor="#FFF" stopOpacity={end} />
</linearGradient>,
<rect
key="rectangle"
x={x}
y={y}
width={60}
height={60}
fill={`url(#gradient-${x}-${y})`}
/>
]
);
};
const LoadingSpinner = () => {
return (
<svg>
{/* outer circle */}
<OpticalGradient definitions={definitions} />
{/* arc */}
</svg>
);
};
@newyork-anthonyng
Copy link

@xavcz Thank you for the great article!

I noticed a small typo. I think that line 35 should read:

<OpticalGradient definitions={opticalGradient} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment