Fix sidebar height & hide ScrollUpButton until scrolled (#384)
This commit is contained in:
parent
d0f47c738b
commit
1cbd273974
|
|
@ -3,11 +3,39 @@ import KeyboardArrowUp from '@material-ui/icons/KeyboardArrowUp';
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
|
|
||||||
class ScrollUpButton extends Component {
|
class ScrollUpButton extends Component {
|
||||||
|
state = {
|
||||||
|
display: 'none',
|
||||||
|
opacity: 0,
|
||||||
|
};
|
||||||
|
componentDidMount() {
|
||||||
|
window.addEventListener('scroll', this.scrollHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
window.removeEventListener('scroll', this.scrollHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollHandler = () => {
|
||||||
|
const currentScrollPos = window.pageYOffset;
|
||||||
|
const opacity = Math.min(currentScrollPos / 500, 1);
|
||||||
|
const nextState = {display: currentScrollPos > 0 ? 'inherit' : 'none', opacity};
|
||||||
|
if (this.state.display !== nextState.display || this.state.opacity !== nextState.opacity) {
|
||||||
|
this.setState(nextState);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<Fab
|
<Fab
|
||||||
color="primary"
|
color="primary"
|
||||||
style={{position: 'fixed', bottom: '30px', right: '30px', zIndex: 100000}}
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
bottom: '30px',
|
||||||
|
right: '30px',
|
||||||
|
zIndex: 100000,
|
||||||
|
display: this.state.display,
|
||||||
|
opacity: this.state.opacity,
|
||||||
|
}}
|
||||||
onClick={this.scrollUp}>
|
onClick={this.scrollUp}>
|
||||||
<KeyboardArrowUp />
|
<KeyboardArrowUp />
|
||||||
</Fab>
|
</Fab>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@ import {Button, Hidden, IconButton, Typography} from '@material-ui/core';
|
||||||
import {DrawerProps} from '@material-ui/core/Drawer/Drawer';
|
import {DrawerProps} from '@material-ui/core/Drawer/Drawer';
|
||||||
import CloseIcon from '@material-ui/icons/Close';
|
import CloseIcon from '@material-ui/icons/Close';
|
||||||
|
|
||||||
const styles = (theme: Theme): StyleRules<'drawerPaper' | 'toolbar' | 'link'> => ({
|
const styles = (theme: Theme): StyleRules<'root' | 'drawerPaper' | 'toolbar' | 'link'> => ({
|
||||||
|
root: {
|
||||||
|
height: '100%',
|
||||||
|
},
|
||||||
drawerPaper: {
|
drawerPaper: {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
width: 250,
|
width: 250,
|
||||||
|
|
@ -26,7 +29,7 @@ const styles = (theme: Theme): StyleRules<'drawerPaper' | 'toolbar' | 'link'> =>
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
type Styles = WithStyles<'drawerPaper' | 'toolbar' | 'link'>;
|
type Styles = WithStyles<'root' | 'drawerPaper' | 'toolbar' | 'link'>;
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
loggedIn: boolean;
|
loggedIn: boolean;
|
||||||
|
|
@ -74,7 +77,7 @@ class Navigation extends Component<
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResponsiveDrawer
|
<ResponsiveDrawer
|
||||||
classes={{paper: classes.drawerPaper}}
|
classes={{root: classes.root, paper: classes.drawerPaper}}
|
||||||
navOpen={navOpen}
|
navOpen={navOpen}
|
||||||
setNavOpen={setNavOpen}
|
setNavOpen={setNavOpen}
|
||||||
id="message-navigation">
|
id="message-navigation">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue