import React, { useState } from "react"; import { Task } from "../../types/public-types"; import { BarProgressHandle } from "./bar-progress-handle"; import { BarDateHandle } from "./bar-date-handle"; import { BarDisplay } from "./bar-display"; import { BarTask } from "../../types/bar-task"; import { BarAction } from "../Gantt/gantt-content"; import { progressWithByParams, getProgressPoint, } from "../../helpers/bar-helper"; import styles from "./bar.module.css"; export type BarProps = { task: BarTask; arrowIndent: number; onDoubleClick?: (task: Task) => any; isProgressChangeable: boolean; isDateChangeable: boolean; handleMouseEvents: ( event: | React.MouseEvent | React.MouseEvent | React.MouseEvent, eventType: BarAction, task: BarTask ) => void; handleButtonSVGEvents: ( event: React.KeyboardEvent, task: BarTask ) => void; }; export const Bar: React.FC = ({ task, arrowIndent, onDoubleClick, isProgressChangeable, isDateChangeable, handleMouseEvents, handleButtonSVGEvents, }) => { const [isSelected, setIsSelected] = useState(false); const progressWidth = progressWithByParams(task.x1, task.x2, task.progress); const progressPoint = getProgressPoint( progressWidth + task.x1, task.y, task.height ); return ( { !!onDoubleClick && onDoubleClick(task); }} tabIndex={0} onKeyDown={e => { handleButtonSVGEvents(e, task); }} onMouseEnter={e => { handleMouseEvents(e, "mouseenter", task); }} onMouseLeave={e => { handleMouseEvents(e, "mouseleave", task); }} onFocus={() => setIsSelected(true)} onBlur={() => setIsSelected(false)} > 0} arrowIndent={arrowIndent} styles={task.styles} isSelected={isSelected} onMouseDown={e => { isDateChangeable && handleMouseEvents(e, "move", task); }} /> {isDateChangeable && ( {/* left */} { handleMouseEvents(e, "start", task); }} /> {/* right */} { handleMouseEvents(e, "end", task); }} /> )} {isProgressChangeable && ( { handleMouseEvents(e, "progress", task); }} /> )} ); };