forked from fossasia/susi.ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes 2994 - Implementation of Scroll to top Floating Action Button (f…
- Loading branch information
1 parent
9e87b0b
commit 7676307
Showing
10 changed files
with
91 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import Fab from '@material-ui/core/Fab'; | ||
import { animateScroll as scroll } from 'react-scroll'; | ||
import KeyboardArrowUpIcon from '@material-ui/icons/KeyboardArrowUp'; | ||
import styled from 'styled-components'; | ||
import Fade from '@material-ui/core/Fade'; | ||
|
||
const ScrollTopFab = styled(Fab)` | ||
position: fixed; | ||
top: ${props => props.height - 95 + 'px'}; | ||
right: ${props => (props.width < 1100 ? '70px' : '100px')}; | ||
margin: 15px; | ||
`; | ||
|
||
class ScrollTopButton extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
height: window.innerHeight, | ||
width: window.innerWidth, | ||
shouldDisplayButton: false, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
window.addEventListener('resize', this.updateDimensions); | ||
window.addEventListener('scroll', this.updateButtonStatus); | ||
} | ||
|
||
componentWillUnmount() { | ||
window.removeEventListener('resize', this.updateDimensions); | ||
window.removeEventListener('scroll', this.updateStatus); | ||
} | ||
|
||
scrollToTop = () => { | ||
scroll.scrollToTop(); | ||
}; | ||
|
||
updateButtonStatus = () => { | ||
if (window.pageYOffset > 500) { | ||
this.setState({ | ||
shouldDisplayButton: true, | ||
}); | ||
} else { | ||
this.setState({ | ||
shouldDisplayButton: false, | ||
}); | ||
} | ||
}; | ||
|
||
updateDimensions = () => { | ||
this.setState({ width: window.innerWidth, height: window.innerHeight }); | ||
}; | ||
|
||
render() { | ||
const { height, width, shouldDisplayButton } = this.state; | ||
return ( | ||
<Fade in={shouldDisplayButton}> | ||
<ScrollTopFab | ||
color="primary" | ||
aria-label="scroll top" | ||
onClick={this.scrollToTop} | ||
height={height} | ||
width={width} | ||
> | ||
<KeyboardArrowUpIcon /> | ||
</ScrollTopFab> | ||
</Fade> | ||
); | ||
} | ||
} | ||
|
||
export default ScrollTopButton; |