MCPcopy Create free account
hub / github.com/gotify/server / ScrollUpButton

Function ScrollUpButton

ui/src/common/ScrollUpButton.tsx:5–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import React from 'react';
4
5const ScrollUpButton = () => {
6 const [state, setState] = React.useState({display: 'none', opacity: 0});
7 React.useEffect(() => {
8 const scrollHandler = () => {
9 const currentScrollPos = Math.max(window.pageYOffset - 1000, 0);
10 const opacity = Math.min(currentScrollPos / 1000, 1);
11 const nextState = {display: currentScrollPos > 0 ? 'inherit' : 'none', opacity};
12 if (state.display !== nextState.display || state.opacity !== nextState.opacity) {
13 setState(nextState);
14 }
15 };
16 window.addEventListener('scroll', scrollHandler);
17 return () => window.removeEventListener('scroll', scrollHandler);
18 }, []);
19
20 return (
21 <Fab
22 color="primary"
23 style={{
24 position: 'fixed',
25 bottom: '30px',
26 right: '30px',
27 zIndex: 100000,
28 display: state.display,
29 opacity: state.opacity,
30 }}
31 onClick={() => window.scrollTo(0, 0)}>
32 <KeyboardArrowUp />
33 </Fab>
34 );
35};
36
37export default ScrollUpButton;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…