Skip to content

Instantly share code, notes, and snippets.

@smddzcy
Created November 1, 2018 10:32
Show Gist options
  • Save smddzcy/e05860c47178044f4ca973f343bee8a6 to your computer and use it in GitHub Desktop.
Save smddzcy/e05860c47178044f4ca973f343bee8a6 to your computer and use it in GitHub Desktop.
A basic loading indicator
import React from 'react';
import PropTypes from 'prop-types';
function Loading({ size, fullScreen, isGold }) {
const style = {
borderWidth: `${size / 10}px`,
width: `${size}px`,
height: `${size}px`,
};
if (fullScreen) {
return (
<div className="center-absolute">
<div className="loader" style={style} />
</div>
);
}
return <div className="loader" style={style} />;
}
Loading.propTypes = {
size: PropTypes.number,
fullScreen: PropTypes.bool,
isGold: PropTypes.bool,
};
Loading.defaultProps = {
size: 50,
fullScreen: false,
};
export default Loading;
@smddzcy
Copy link
Author

smddzcy commented Nov 1, 2018

Required CSS:

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.gpu {
  backface-visibility: hidden;
  perspective: 1000;
  transform: translateZ(0);
}

.center-absolute {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader {
  border-style: solid;
  border-color: #f3f3f3;
  animation: spin 1s linear infinite;
  border-top-color: #555;
  border-radius: 50%;
}

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