Skip to content

Commit 253590a

Browse files
Merge pull request #4 from AquilesOliveiraDev/feature/click-on-the-line
Added click arrow event
2 parents 232ed65 + 02638eb commit 253590a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/components/gantt/gantt.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
6666
onProgressChange,
6767
onDoubleClick,
6868
onClick,
69+
onClickLine,
6970
onDelete,
7071
onSelect,
7172
onExpanderClick,
@@ -433,6 +434,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
433434
onProgressChange,
434435
onDoubleClick,
435436
onClick,
437+
onClickLine,
436438
onDelete,
437439
};
438440

src/components/gantt/task-gantt-content.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
5454
onProgressChange,
5555
onDoubleClick,
5656
onClick,
57+
onClickLine,
5758
onDelete,
5859
}) => {
5960
const point = svg?.current?.createSVGPoint();
@@ -266,7 +267,8 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
266267
{tasks.map(task => {
267268
return task.barChildren.map(child => {
268269
return (
269-
<Arrow
270+
<Arrow
271+
onClickLine={(tasks: BarTask[]) => onClickLine ? onClickLine(tasks) : null}
270272
key={`Arrow from ${task.id} to ${tasks[child.index].id}`}
271273
taskFrom={task}
272274
taskTo={tasks[child.index]}

src/components/other/arrow.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import { BarTask } from "../../types/bar-task";
33
import { Link } from "../../types/public-types";
44

@@ -9,6 +9,7 @@ type ArrowProps = {
99
taskHeight: number;
1010
arrowIndent: number;
1111
rtl: boolean;
12+
onClickLine?: (tasks: BarTask[]) => void;
1213
};
1314
export const Arrow: React.FC<ArrowProps> = ({
1415
taskFrom,
@@ -17,9 +18,13 @@ export const Arrow: React.FC<ArrowProps> = ({
1718
taskHeight,
1819
arrowIndent,
1920
rtl,
21+
onClickLine,
2022
}) => {
2123
let path: string;
2224
let trianglePoints: string;
25+
const strokeWidthDefault = "1.5";
26+
const [strokeWidth, setStrokeWidth] = useState<string>(strokeWidthDefault);
27+
2328
if (rtl) {
2429
[path, trianglePoints] = drownPathAndTriangleRTL(
2530
taskFrom,
@@ -38,9 +43,19 @@ export const Arrow: React.FC<ArrowProps> = ({
3843
);
3944
}
4045

46+
const clickLine = () => {
47+
if (onClickLine) {
48+
onClickLine([taskFrom, taskTo]);
49+
}
50+
}
51+
4152
return (
42-
<g className="arrow">
43-
<path strokeWidth="1.5" d={path} fill="none" />
53+
<g className="arrow"
54+
stroke={strokeWidth}
55+
onMouseEnter={() => setStrokeWidth("2")}
56+
onMouseLeave={() => setStrokeWidth(strokeWidthDefault)}
57+
onClick={clickLine}>
58+
<path strokeWidth={strokeWidth} d={path} fill="none" />
4459
<polygon points={trianglePoints} />
4560
</g>
4661
);

src/types/public-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export interface EventOption {
5757
* Invokes on bar click.
5858
*/
5959
onClick?: (task: Task) => void;
60+
/**
61+
* Invokes on bar click.
62+
*/
63+
onClickLine?: (tasks: Task[]) => void;
6064
/**
6165
* Invokes on end and start time change. Chart undoes operation if method return false or error.
6266
*/

0 commit comments

Comments
 (0)