diff --git a/src/components/task-item/bar/bar-small.tsx b/src/components/task-item/bar/bar-small.tsx new file mode 100644 index 0000000..69354f7 --- /dev/null +++ b/src/components/task-item/bar/bar-small.tsx @@ -0,0 +1,51 @@ +import React from "react"; +import { + progressWithByParams, + getProgressPoint, +} from "../../../helpers/bar-helper"; +import { BarDisplay } from "./bar-display"; +import { BarProgressHandle } from "./bar-progress-handle"; +import { TaskItemProps } from "../task-item"; +import styles from "./bar.module.css"; + +export const BarSmall: React.FC = ({ + task, + isProgressChangeable, + isDateChangeable, + onEventStart, + isSelected, +}) => { + const progressWidth = progressWithByParams(task.x1, task.x2, task.progress); + const progressPoint = getProgressPoint( + progressWidth + task.x1, + task.y, + task.height + ); + return ( + + { + isDateChangeable && onEventStart("move", task, e); + }} + /> + + {isProgressChangeable && ( + { + onEventStart("progress", task, e); + }} + /> + )} + + + ); +}; diff --git a/src/components/task-item/task-item.tsx b/src/components/task-item/task-item.tsx index 50d5f89..3314bbb 100644 --- a/src/components/task-item/task-item.tsx +++ b/src/components/task-item/task-item.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from "react"; import { BarTask } from "../../types/bar-task"; import { GanttContentMoveAction } from "../../types/gantt-task-actions"; import { Bar } from "./bar/bar"; +import { BarSmall } from "./bar/bar-small"; import { Milestone } from "./milestone/milestone"; import { Project } from "./project/project"; import style from "./task-list.module.css"; @@ -37,13 +38,16 @@ export const TaskItem: React.FC = props => { const [isTextInside, setIsTextInside] = useState(true); useEffect(() => { - switch (task.type) { + switch (task.typeInternal) { case "milestone": setTaskItem(); break; case "project": setTaskItem(); break; + case "smalltask": + setTaskItem(); + break; default: setTaskItem(); break; diff --git a/src/helpers/bar-helper.ts b/src/helpers/bar-helper.ts index f8be058..2fbf94b 100644 --- a/src/helpers/bar-helper.ts +++ b/src/helpers/bar-helper.ts @@ -1,5 +1,5 @@ import { Task } from "../types/public-types"; -import { BarTask } from "../types/bar-task"; +import { BarTask, TaskTypeInternal } from "../types/bar-task"; import { BarMoveAction } from "../types/gantt-task-actions"; export const convertToBarTasks = ( @@ -158,7 +158,7 @@ const convertToBar = ( ): BarTask => { debugger; const x1 = taskXCoordinate(task.start, dates, dateDelta, columnWidth); - const x2 = taskXCoordinate(task.end, dates, dateDelta, columnWidth); + let x2 = taskXCoordinate(task.end, dates, dateDelta, columnWidth); const y = taskYCoordinate(index, rowHeight, taskHeight); const styles = { @@ -168,8 +168,14 @@ const convertToBar = ( progressSelectedColor: barProgressSelectedColor, ...task.styles, }; + let typeInternal: TaskTypeInternal = task.type; + if (typeInternal === "task" && x2 - x1 < handleWidth * 2) { + typeInternal = "smalltask"; + x2 = x1 + handleWidth * 2; + } return { ...task, + typeInternal, x1, x2, y, @@ -218,6 +224,7 @@ const convertToMilestone = ( index, barCornerRadius, handleWidth, + typeInternal: task.type, progress: 0, height: rotatedHeight, barChildren: [], diff --git a/src/types/bar-task.ts b/src/types/bar-task.ts index ee793df..1b45371 100644 --- a/src/types/bar-task.ts +++ b/src/types/bar-task.ts @@ -1,7 +1,8 @@ -import { Task } from "./public-types"; +import { Task, TaskType } from "./public-types"; export interface BarTask extends Task { index: number; + typeInternal: TaskTypeInternal; x1: number; x2: number; y: number; @@ -16,3 +17,5 @@ export interface BarTask extends Task { progressSelectedColor: string; }; } + +export type TaskTypeInternal = TaskType | "smalltask";