Skip to content

Commit

Permalink
feat: add a Spinner component
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Sep 26, 2020
1 parent 578659d commit e576ad1
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/components/Spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import PropTypes from 'prop-types';
import { css, keyframes } from '@emotion/core';

const spin = keyframes`
to {
transform: rotate(1turn);
}
`;

const Spinner = ({ inline }) => (
<div
aria-label="Loading"
aria-busy
css={css`
--spinner-size: 1rem;
display: inline-block;
position: relative;
height: ${inline ? 'var(--spinner-size)' : '100%'};
width: ${inline ? 'var(--spinner-size)' : '100%'};
&:after {
animation: ${spin} 0.5s linear infinite;
border-radius: 50%;
border-right: 1px solid transparent;
border-top: 1px solid;
content: '';
left: calc(50% + 1px);
margin-left: calc(var(--spinner-size) / 2 * -1);
margin-top: calc(var(--spinner-size) / 2 * -1);
position: absolute;
top: calc(50% + 1px);
width: var(--spinner-size);
height: var(--spinner-size);
}
`}
/>
);

Spinner.propTypes = {
inline: PropTypes.bool,
};

Spinner.defaultProps = {
inline: false,
};

export default Spinner;

0 comments on commit e576ad1

Please sign in to comment.