import React, { useRef, useEffect, useState } from "react"; import { Task } from "../../types/public-types"; import { BarTask } from "../../types/bar-task"; import styles from "./tooltip.module.css"; export type TooltipProps = { x: number; svgHeight: number; rowHeight: number; task: BarTask; fontSize: string; fontFamily: string; TooltipContent: React.FC<{ task: Task; fontSize: string; fontFamily: string; }>; }; export const Tooltip: React.FC = ({ x, rowHeight, svgHeight, task, fontSize, fontFamily, TooltipContent, }) => { const tooltipRef = useRef(null); const [toolWidth, setToolWidth] = useState(1000); const [relatedY, setRelatedY] = useState((task.index - 1) * rowHeight); useEffect(() => { if (tooltipRef.current) { const tooltipHeight = tooltipRef.current.offsetHeight; const tooltipY = task.index * rowHeight + rowHeight; if (tooltipHeight > tooltipY) { setRelatedY(tooltipHeight * 0.5); } else if (tooltipY + tooltipHeight > svgHeight) { setRelatedY(svgHeight - tooltipHeight * 1.05); } setToolWidth(tooltipRef.current.scrollWidth * 1.1); } }, [tooltipRef, task]); return (
); }; export const StandardTooltipContent: React.FC<{ task: Task; fontSize: string; fontFamily: string; }> = ({ task, fontSize, fontFamily }) => { const style = { fontSize, fontFamily, }; return (
{`${ task.name }: ${task.start.getDate()}-${ task.start.getMonth() + 1 }-${task.start.getFullYear()} - ${task.end.getDate()}-${ task.end.getMonth() + 1 }-${task.end.getFullYear()}`}

{`Duration: ${~~( (task.end.getTime() - task.start.getTime()) / (1000 * 60 * 60 * 24) )} day(s)`}

{!!task.progress && `Progress: ${task.progress} %`}

); };