diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-12 01:59:27 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-13 17:16:17 +0300 |
commit | 5744923265ff51e392575edfd6a8182589105dc6 (patch) | |
tree | 9294f30455405ddaecfdd4ecf7eedf6c5c80c872 /src/components | |
parent | 86a946b2b0535829857757eeaa2226e6f0814f3b (diff) | |
download | which-ui-5744923265ff51e392575edfd6a8182589105dc6.tar.gz |
feat: PollCreation page and Fab component
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/Fab/Fab.tsx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/components/Fab/Fab.tsx b/src/components/Fab/Fab.tsx new file mode 100644 index 0000000..335fcba --- /dev/null +++ b/src/components/Fab/Fab.tsx @@ -0,0 +1,55 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom' +import { + Fab as FabBase, + useMediaQuery, + Slide, + useScrollTrigger +} from '@material-ui/core/'; +import { makeStyles } from '@material-ui/core/styles'; +import PlusIcon from '@material-ui/icons/Add'; + +interface PropTypes { + hideOnScroll?: boolean; +} + +const useStyles = makeStyles(theme => ({ + root: { + zIndex: 1200, + position: 'fixed', + + [theme.breakpoints.down('sm')]: { + right: theme.spacing(2), + bottom: theme.spacing(8) + }, + [theme.breakpoints.up('md')]: { + right: theme.spacing(5), + bottom: theme.spacing(5) + } + } +})); + +const Fab: React.FC<PropTypes> = ({ hideOnScroll=false }) => { + const classes = useStyles(); + const history = useHistory(); + const trigger = useScrollTrigger(); + + const handleClick = () => { + history.push('/new'); + }; + + return ( + <Slide appear={false} direction="up" in={(!hideOnScroll) || !trigger}> + <FabBase + onClick={handleClick} + className={classes.root} + color="secondary" + > + <PlusIcon /> + </FabBase> + </Slide> + ); +}; + +export default Fab; + |