import Expander from "@/components/Expander"; import { Task } from "@/components/interfaces"; import GanttElasticContext from "@/GanttElasticContext"; import { emitEvent } from "@/GanttElasticEvents"; import React, { useCallback, useContext, useMemo } from "react"; import { invariant } from "ts-invariant"; import ProgressBar from "../ProgressBar"; import ChartText from "../Text"; export interface MilestoneProps { task: Task; } const ChartMilestone: React.FC = ({ task }) => { const { style, options } = useContext(GanttElasticContext); /** * Emit event * * @param {string} eventName * @param {Event} event */ const onEmitEvent = useCallback( event => { invariant.warn(event.type, task); emitEvent.emit(`chart-${task.type}-${event.type}`, { event, data: task }); task.events && task.events[event.type] && task.events[event.type](event, task); }, [task] ); /** * Get points */ const points = useMemo(() => { const fifty = task.height / 2; let offset = fifty; if (task.width / 2 - offset < 0) { offset = task.width / 2; } return `0,${fifty} ${offset},0 ${task.width - offset},0 ${task.width},${fifty} ${task.width - offset},${task.height} ${offset},${task.height}`; }, [task.height, task.width]); return useMemo(() => { const clipPathId = `gantt-elastic__milestone-clip-path-${task.id}`; const displayExpander = options.chart.expander.display || (options.chart.expander.displayIfTaskListHidden && !options.taskList.display); return ( {displayExpander && ( )} {options.chart.text.display && } ); }, [ onEmitEvent, options.chart.expander.display, options.chart.expander.displayIfTaskListHidden, options.chart.expander.offset, options.chart.expander.size, options.chart.expander.type, options.chart.text.display, options.row.height, options.taskList.display, points, style, task ]); }; export default ChartMilestone;