-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgressBar.tsx
More file actions
68 lines (60 loc) · 1.69 KB
/
ProgressBar.tsx
File metadata and controls
68 lines (60 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable react/prop-types */
import React, { useEffect } from 'react'
import NProgress from 'nprogress'
import { useHistory } from 'react-router-dom'
// react-router-dom
// @mui
import { useTheme } from '@mui/material/styles'
import GlobalStyles from '@mui/material/GlobalStyles'
// ----------------------------------------------------------------------
function ProgressBar() {
const theme = useTheme()
const history = useHistory()
NProgress.configure({ showSpinner: false })
useEffect(() => {
const handleStart = () => {
NProgress.start()
}
const handleStop = () => {
NProgress.done()
}
history.listen((location, action) => {
if (action === 'PUSH') handleStart()
else handleStop()
})
return () => {
history.listen(() => {})
}
}, [history])
return (
<GlobalStyles
styles={{
'#nprogress': {
pointerEvents: 'none',
'& .bar': {
top: 0,
left: 0,
height: 2,
width: '100%',
position: 'fixed',
zIndex: theme.zIndex.snackbar,
backgroundColor: theme.palette.primary.main,
boxShadow: `0 0 2px ${theme.palette.primary.main}`,
},
'& .peg': {
right: 0,
opacity: 1,
width: 100,
height: '100%',
display: 'block',
position: 'absolute',
transform: 'rotate(3deg) translate(0px, -4px)',
boxShadow: `0 0 10px ${theme.palette.primary.main}, 0 0 5px ${theme.palette.primary.main}`,
},
},
}}
/>
)
}
export default ProgressBar