mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 05:37:20 +01:00
Updated sticky header logic.
This commit is contained in:
parent
45c13da262
commit
f062cdbed2
8 changed files with 31 additions and 24 deletions
|
|
@ -1,15 +1,21 @@
|
|||
import { useEffect, useRef } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import useSticky from 'hooks/useSticky';
|
||||
|
||||
export default function StickyHeader({ className, stickyClassName, stickyStyle, children }) {
|
||||
const { ref, isSticky } = useSticky();
|
||||
const initialWidth = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
initialWidth.current = ref.current.clientWidth;
|
||||
}, [ref]);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
data-sticky={isSticky}
|
||||
className={classNames(className, { [stickyClassName]: isSticky })}
|
||||
style={isSticky ? { ...stickyStyle, width: ref?.current?.clientWidth } : null}
|
||||
style={isSticky ? { ...stickyStyle, width: initialWidth.current } : null}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue