1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-13 05:45:31 -04:00
Files
jarv.is/assets/js/src/components/loading.js
Jake Jarvis b755b66d19 use preact for common components across site (#663)
* convert GitHub cards grid from lit-html to preact

* give hit counter the preact treatment

* extract loading spinner component to a shared location

* move *some* loading spinner styles to its JSX

* Update .percy.yml

* pick up images in JS w/ webpack

* pull star/fork icons straight from @primer/octicons

* a bit of cleanup

* check `typeof window !== "undefined"` before rendering

* bump misc. deps

* silence missing license warnings for preact-hooks and preact-compat

* add source-map-loader

* Update loading.js
2021-11-24 13:51:29 -05:00

44 lines
1.1 KiB
JavaScript

import { h } from "preact";
const Loading = (props) => {
// allow a custom number of pulsing boxes (defaults to 3)
const boxes = props.boxes || 3;
// each individual box's animation has a staggered start in corresponding order
const animationTiming = props.timing || 0.1; // seconds
// each box is just an empty div
const divs = [];
for (let i = 0; i < boxes; i++) {
divs.push(
<div
style={{
// width of each box correlates with number of boxes (with a little padding)
width: `${props.width / (boxes + 1)}px`,
height: "100%",
display: "inline-block",
// see assets/sass/components/_animation.scss:
animation: "loading 1.5s infinite ease-in-out both",
"animation-delay": `${i * animationTiming}s`,
}}
/>
);
}
return (
<div
class="loading"
style={{
width: `${props.width}px`,
height: `${props.width / 2}px`,
display: "inline-block",
"text-align": "center",
...props.style,
}}
>
{divs}
</div>
);
};
export default Loading;