2020-08-05 08:14:22 +03:00
|
|
|
import React, { useRef, useEffect, useState } from "react";
|
|
|
|
|
import { Task } from "../../types/public-types";
|
|
|
|
|
import styles from "./tooltip.module.css";
|
|
|
|
|
|
2020-07-22 20:50:43 +03:00
|
|
|
export type TooltipProps = {
|
|
|
|
|
x: number;
|
|
|
|
|
y: number;
|
|
|
|
|
task: Task;
|
|
|
|
|
fontSize: string;
|
|
|
|
|
fontFamily: string;
|
|
|
|
|
getTooltipContent?: (
|
|
|
|
|
task: Task,
|
|
|
|
|
fontSize: string,
|
|
|
|
|
fontFamily: string
|
|
|
|
|
) => JSX.Element;
|
|
|
|
|
};
|
|
|
|
|
export const Tooltip: React.FC<TooltipProps> = ({
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
task,
|
|
|
|
|
fontSize,
|
|
|
|
|
fontFamily,
|
|
|
|
|
|
|
|
|
|
getTooltipContent = getStandardTooltipContent,
|
|
|
|
|
}) => {
|
|
|
|
|
const tooltipRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const [toolWidth, setToolWidth] = useState(1000);
|
|
|
|
|
const [relatedY, setRelatedY] = useState(y);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (tooltipRef.current) {
|
|
|
|
|
const height =
|
|
|
|
|
tooltipRef.current.offsetHeight +
|
|
|
|
|
tooltipRef.current.offsetHeight * 0.15;
|
|
|
|
|
setRelatedY(y - height);
|
|
|
|
|
setToolWidth(tooltipRef.current.scrollWidth * 1.1);
|
|
|
|
|
}
|
|
|
|
|
}, [tooltipRef, y]);
|
|
|
|
|
return (
|
|
|
|
|
<foreignObject x={x} y={relatedY} width={toolWidth} height={1000}>
|
2020-08-05 08:14:22 +03:00
|
|
|
<div ref={tooltipRef} className={styles.tooltipDetailsContainer}>
|
2020-07-22 20:50:43 +03:00
|
|
|
{getTooltipContent(task, fontSize, fontFamily)}
|
|
|
|
|
</div>
|
|
|
|
|
</foreignObject>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getStandardTooltipContent = (
|
|
|
|
|
task: Task,
|
|
|
|
|
fontSize: string,
|
|
|
|
|
fontFamily: string
|
|
|
|
|
) => {
|
|
|
|
|
const style = {
|
|
|
|
|
fontSize,
|
|
|
|
|
fontFamily,
|
|
|
|
|
};
|
|
|
|
|
return (
|
2020-08-05 08:14:22 +03:00
|
|
|
<div className={styles.tooltipDefaultContainer} style={style}>
|
2020-07-22 20:50:43 +03:00
|
|
|
<b style={{ fontSize: fontSize + 6 }}>{`${
|
|
|
|
|
task.name
|
2020-08-05 08:14:22 +03:00
|
|
|
}: ${task.start.getDate()}-${
|
|
|
|
|
task.start.getMonth() + 1
|
|
|
|
|
}-${task.start.getFullYear()} - ${task.end.getDate()}-${
|
|
|
|
|
task.end.getMonth() + 1
|
|
|
|
|
}-${task.end.getFullYear()}`}</b>
|
|
|
|
|
<p className={styles.tooltipDefaultContainerParagraph}>{`Duration: ${~~(
|
2020-07-22 20:50:43 +03:00
|
|
|
(task.end.getTime() - task.start.getTime()) /
|
|
|
|
|
(1000 * 60 * 60 * 24)
|
|
|
|
|
)} day(s)`}</p>
|
2020-08-05 08:14:22 +03:00
|
|
|
<p
|
|
|
|
|
className={styles.tooltipDefaultContainerParagraph}
|
|
|
|
|
>{`Progress: ${task.progress} %`}</p>
|
2020-07-22 20:50:43 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|