umami/components/helpers/StickyHeader.js

18 lines
479 B
JavaScript
Raw Normal View History

import classNames from 'classnames';
2023-02-09 08:14:11 +01:00
import useSticky from 'hooks/useSticky';
2023-02-09 08:14:11 +01:00
export default function StickyHeader({ className, stickyClassName, stickyStyle, children }) {
const { ref, isSticky } = useSticky();
return (
<div
ref={ref}
2023-02-09 08:14:11 +01:00
data-sticky={isSticky}
className={classNames(className, { [stickyClassName]: isSticky })}
style={isSticky ? { ...stickyStyle, width: ref?.current?.clientWidth } : null}
>
{children}
</div>
);
}