@@ -6,47 +6,47 @@ import { ThemeContext } from '../../contexts/ThemeContext';
66import './BackToTop.css' ;
77
88function BackToTop ( ) {
9- const [ visible , setVisible ] = useState ( false ) ;
10-
11- const { theme } = useContext ( ThemeContext ) ;
12-
13- const toggleVisible = ( ) => {
14- const scrolled = document . documentElement . scrollTop ;
15- if ( scrolled > 300 ) {
16- setVisible ( true ) ;
17- } else if ( scrolled <= 300 ) {
18- setVisible ( false ) ;
19- }
20- } ;
21-
22- const scrollToTop = ( ) => {
23- window . scrollTo ( {
24- top : 0 ,
25- behavior : 'smooth' ,
26- } ) ;
27- } ;
28-
29- window . addEventListener ( 'scroll' , toggleVisible ) ;
30-
31- const useStyles = makeStyles ( ( ) => ( {
32- icon : {
33- fontSize : '3rem' ,
34- color : theme . tertiary ,
35- } ,
36- } ) ) ;
37-
38- const classes = useStyles ( ) ;
39-
40- return (
41- < div
42- style = { { display : visible ? 'inline' : 'none' } }
43- className = 'backToTop'
44- >
45- < button onClick = { scrollToTop } aria-label = 'Back to top' >
46- < IoIosArrowDropupCircle className = { classes . icon } />
47- </ button >
48- </ div >
49- ) ;
9+ const [ visible , setVisible ] = useState ( false ) ;
10+
11+ const { theme } = useContext ( ThemeContext ) ;
12+
13+ const toggleVisible = ( ) => {
14+ const scrolled = document . documentElement . scrollTop ;
15+ if ( scrolled > 300 ) {
16+ setVisible ( true ) ;
17+ } else if ( scrolled <= 300 ) {
18+ setVisible ( false ) ;
19+ }
20+ } ;
21+
22+ const scrollToTop = ( ) => {
23+ window . scrollTo ( {
24+ top : 0 ,
25+ behavior : 'smooth' ,
26+ } ) ;
27+ } ;
28+
29+ window . addEventListener ( 'scroll' , toggleVisible ) ;
30+
31+ const useStyles = makeStyles ( ( ) => ( {
32+ icon : {
33+ fontSize : '3rem' ,
34+ color : theme . tertiary ,
35+ } ,
36+ } ) ) ;
37+
38+ const classes = useStyles ( ) ;
39+
40+ return (
41+ < div
42+ style = { { display : visible ? 'inline' : 'none' } }
43+ className = 'backToTop'
44+ >
45+ < button onClick = { scrollToTop } aria-label = 'Back to top' >
46+ < IoIosArrowDropupCircle className = { classes . icon } />
47+ </ button >
48+ </ div >
49+ ) ;
5050}
5151
5252export default BackToTop ;
0 commit comments