blob: f6b85e504b43e7691e8ccabc432b9d2c51bb8938 (
plain)
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
|
import React from 'react';
import { useLocation, Link } from 'react-router-dom';
import { Fab as FabBase, 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: 1000,
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 location = useLocation();
const trigger = useScrollTrigger();
return (
<Slide appear={false} direction="up" in={(!hideOnScroll) || !trigger}>
<Link to={{ pathname: '/new', state: { background: location } }}>
<FabBase
className={classes.root}
color="secondary"
>
<PlusIcon />
</FabBase>
</Link>
</Slide>
);
};
export default Fab;
|