Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created August 12, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheeaun/625f4050e9d9f068386f42e6068a48d3 to your computer and use it in GitHub Desktop.
Save cheeaun/625f4050e9d9f068386f42e6068a48d3 to your computer and use it in GitHub Desktop.
export default function TimeSymbol({ type = 'wd' }) {
const count = 3;
const size = 6;
const gutter = 1;
const typeHighlights = {
wd: [0, 1, 0],
sat: [0, 0, 1],
sun: [1, 0, 0],
}[type.toLowerCase()];
const typeColor = {
wd: '#007aff',
sat: '#8800FF',
sun: '#00b348',
}[type.toLowerCase()];
const backgrounds = Array(count)
.fill(0)
.map((_, i) => {
const highlight = typeHighlights[i];
const color = highlight ? typeColor : '#ddd';
const radius = size / 2;
const x = radius + i * (size + gutter);
const y = radius;
const style = `radial-gradient(circle at ${x}px ${y}px, ${color}, ${color} ${
radius - 0.5
}px, rgba(255,255,255,0) ${radius}px, rgba(255,255,255,0))`;
return style;
});
return (
<div
style={{
display: 'inline-block',
width: Math.ceil(size * count + gutter * (count - 1)),
height: Math.ceil(size),
backgroundImage: backgrounds.join(','),
backgroundRepeat: 'no-repeat',
verticalAlign: 'middle',
}}
/>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment