Skip to content

Instantly share code, notes, and snippets.

@knowbody
Created April 6, 2017 12:27
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save knowbody/578b35164b69e867ed4913423f6bed30 to your computer and use it in GitHub Desktop.
Save knowbody/578b35164b69e867ed4913423f6bed30 to your computer and use it in GitHub Desktop.
Spinner - using styled-components
import React from 'react';
import styled from 'styled-components';
const Spinner = () => (
<StyledSpinner viewBox="0 0 50 50">
<circle
className="path"
cx="25"
cy="25"
r="20"
fill="none"
strokeWidth="4"
/>
</StyledSpinner>
);
const StyledSpinner = styled.svg`
animation: rotate 2s linear infinite;
margin: -25px 0 0 -25px;
width: 50px;
height: 50px;
& .path {
stroke: #5652BF;
stroke-linecap: round;
animation: dash 1.5s ease-in-out infinite;
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
}
@keyframes dash {
0% {
stroke-dasharray: 1, 150;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -124;
}
}
`;
export default Spinner;
@mackness
Copy link

mackness commented Nov 9, 2018

Awesome thank you.

@mackness
Copy link

mackness commented Nov 9, 2018

Here's a code sandbox if anyone else is interested in what it looks like:

https://codesandbox.io/s/m3v440z36j

@jcuffe
Copy link

jcuffe commented Jul 25, 2019

This is perfect, thanks!

@AJP2511
Copy link

AJP2511 commented Feb 27, 2021

Thank you bro! works perfectly

@Minozzzi
Copy link

Thanks bro! Helped me

@knowbody
Copy link
Author

Happy it helped! 🙌🏻

@reisblucas
Copy link

Thank you! It helped me a lot 🚀

@Typhon0130
Copy link

Awesome

@vaahxx
Copy link

vaahxx commented Jul 23, 2023

Perfect, thanks :)

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