30 lines
786 B
TypeScript
30 lines
786 B
TypeScript
import React, { SyntheticEvent, useRef, useEffect } from "react";
|
|
import styles from "./scroll.module.css";
|
|
|
|
export const Scroll: React.FC<{
|
|
scroll: number;
|
|
ganttHeight: number;
|
|
ganttFullHeight: number;
|
|
headerHeight: number;
|
|
onScroll: (event: SyntheticEvent<HTMLDivElement>) => void;
|
|
}> = ({ scroll, ganttHeight, ganttFullHeight, headerHeight, onScroll }) => {
|
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (scrollRef.current) {
|
|
scrollRef.current.scrollTop = scroll;
|
|
}
|
|
}, [scroll]);
|
|
|
|
return (
|
|
<div
|
|
style={{ height: ganttHeight, marginTop: headerHeight }}
|
|
className={styles.scroll}
|
|
onScroll={onScroll}
|
|
ref={scrollRef}
|
|
>
|
|
<div style={{ height: ganttFullHeight, width: 1 }} />
|
|
</div>
|
|
);
|
|
};
|