Skip to content

Instantly share code, notes, and snippets.

@GGrassiant
Created September 1, 2020 22:30
Show Gist options
  • Save GGrassiant/2ee199f4d2f3d469c9efb3dce6f7a842 to your computer and use it in GitHub Desktop.
Save GGrassiant/2ee199f4d2f3d469c9efb3dce6f7a842 to your computer and use it in GitHub Desktop.
React Skeleton loader from Tom Phillips
.App {
margin: 40px auto;
max-width: 400px;
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
import React from "react";
import "./App.css";
import { Skeleton } from "./Skeleton";
function App() {
return (
<div className="App">
<Skeleton circle />
<Skeleton />
</div>
);
}
export default App;
import React from "react";
import "./style.css";
export const Skeleton = ({ circle }) => {
return (
<div
className={`skeleton-wrapper${
circle ? " skeleton-wrapper-circle" : ""
}`}
>
<div className="skeleton">
<div className="skeleton-indicator" />
</div>
</div>
);
};
@keyframes leftToRight {
from {
transform: translate(0);
}
to {
transform: translate(100%);
}
}
.skeleton-wrapper {
background: #ddd;
height: 40px;
width: 100%;
overflow: hidden;
}
.skeleton-wrapper-circle {
height: 200px;
width: 200px;
border-radius: 50%;
}
.skeleton {
height: 100%;
transform: translate(100%);
animation: 3s leftToRight linear infinite;
}
.skeleton-indicator {
width: 5px;
background: #bbb;
height: 100%;
box-shadow: 0 0 5px 5px #bbb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment