From 2a83b58e40d60dc058f385440a3125c60fb90026 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 4 Jul 2020 00:05:33 +0300 Subject: refactor: improve scrollTopArrow --- src/components/ScrollTopArrow/ScrollTopArrow.tsx | 40 ++++++++++++++---------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/components/ScrollTopArrow/ScrollTopArrow.tsx b/src/components/ScrollTopArrow/ScrollTopArrow.tsx index 6b9d5c9..dfa573f 100644 --- a/src/components/ScrollTopArrow/ScrollTopArrow.tsx +++ b/src/components/ScrollTopArrow/ScrollTopArrow.tsx @@ -1,26 +1,33 @@ import React, { useState } from 'react'; -import { FaArrowCircleUp } from 'react-icons/fa'; -import { makeStyles } from '@material-ui/core'; -import teal from '@material-ui/core/colors/teal'; +import { makeStyles, useTheme } from '@material-ui/core/styles'; +import { useMediaQuery } from '@material-ui/core'; +import ArrowUpwardIcon from '@material-ui/icons/ArrowUpward'; -const useStyles = makeStyles(() => ({ - scrollTop: { +const useStyles = makeStyles(theme => ({ + root: { position: 'fixed', - width: 50, - bottom: 50, - left: 50, + bottom: theme.spacing(10), + left: theme.spacing(10), zIndex: 1000, cursor: 'pointer', - opacity: 0.5, + opacity: 0.4, '&:hover': { - opacity: '1' - } + opacity: 1 + }, + background: theme.palette.primary.main, + borderRadius: '50%' + }, + icon: { + fontSize: 80, + color: 'white' } })); -const ScrollTopArrow:React.FC = () => { +const ScrollTopArrow: React.FC = () => { const [showScroll, setShowScroll] = useState(false); + const theme = useTheme(); const classes = useStyles(); + const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const checkScrollTop = () => { if (!showScroll && window.pageYOffset > 400) { @@ -37,11 +44,10 @@ const ScrollTopArrow:React.FC = () => { window.addEventListener('scroll', checkScrollTop); return ( - +
+ {showScroll && !isMobile && + } +
); }; -- cgit v1.2.3