Skip to content

Commit b888b14

Browse files
committed
492: Add loading component
1 parent 5aa0d7e commit b888b14

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from "react";
2+
import {
3+
Box,
4+
Backdrop,
5+
CircularProgress,
6+
Typography,
7+
} from "@material-ui/core";
8+
9+
export default function Loading({ text, speed = 300 }) {
10+
const [content, setContent] = React.useState(text);
11+
12+
React.useEffect(() => {
13+
const id = window.setInterval(() => {
14+
setContent((content) => {
15+
return content === `${text}...` ? text : `${content}.`;
16+
});
17+
}, speed);
18+
19+
return () => window.clearInterval(id);
20+
}, [text, speed]);
21+
22+
return (
23+
<Backdrop open={true}>
24+
<Box
25+
display="flex"
26+
flexDirection="column"
27+
justifyContent="center"
28+
alignItems="center"
29+
>
30+
<CircularProgress size={60} />
31+
{text &&
32+
<Box paddingTop="16px">
33+
<Typography>
34+
{content}
35+
</Typography>
36+
</Box>
37+
}
38+
</Box>
39+
</Backdrop>
40+
);
41+
}

0 commit comments

Comments
 (0)