* Add custom popup * Render popup window with react portal * Handle scroll * Handle pointer scroll * Refactor types * Add useOutsideClick * Restore button styles * Update types * Add tests * Set multiple refs * Cleanup * Cleanup * Move offset const to the utils * Add useCallback in useScroll * Remove empty lines in useElementPosition * Change styled components to functional * Make sure popup window stays in view * Highlight trigger button when popup is open * Add uesPopupWindow hook * Make triangle larger * Use full trigger height * Apply new lint rules Co-authored-by: Jaco Greeff <jacogr@gmail.com>
24 lines
604 B
TypeScript
24 lines
604 B
TypeScript
// Copyright 2017-2021 @polkadot/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
export function useScroll (): number {
|
|
const [scrollY, setScrollY] = useState(window.pageYOffset);
|
|
const setYOffset = useCallback((): void => setScrollY(window.pageYOffset), []);
|
|
|
|
useEffect(() => {
|
|
function watchScroll () {
|
|
window.addEventListener('scroll', setYOffset);
|
|
}
|
|
|
|
watchScroll();
|
|
|
|
return () => {
|
|
window.removeEventListener('scroll', setYOffset);
|
|
};
|
|
}, [setYOffset]);
|
|
|
|
return scrollY;
|
|
}
|