Skip to content

Commit e0a400f

Browse files
committed
Add commit onMessageCommit handler
1 parent 1731e66 commit e0a400f

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

packages/gitgraph-core/src/commit.ts

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface CommitOptions {
1313
parents?: string[];
1414
innerText?: string;
1515
onClick?: (commit: Commit) => void;
16+
onMessageClick?: (commit: Commit) => void;
1617
onMouseOver?: (commit: Commit) => void;
1718
onMouseOut?: (commit: Commit) => void;
1819
}
@@ -141,6 +142,10 @@ export class Commit {
141142
* Callback to execute on click.
142143
*/
143144
public onClick: () => void;
145+
/**
146+
* Callback to execute on click on the commit message.
147+
*/
148+
public onMessageClick: () => void;
144149
/**
145150
* Callback to execute on mouse over.
146151
*/
@@ -186,6 +191,8 @@ export class Commit {
186191

187192
// Set callbacks
188193
this.onClick = () => (options.onClick ? options.onClick(this) : undefined);
194+
this.onMessageClick = () =>
195+
options.onMessageClick ? options.onMessageClick(this) : undefined;
189196
this.onMouseOver = () =>
190197
options.onMouseOver ? options.onMouseOver(this) : undefined;
191198
this.onMouseOut = () =>

packages/gitgraph-core/src/gitgraph.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface GitgraphCommitOptions {
6161
innerText?: string;
6262
tag?: string;
6363
onClick?: (commit: Commit) => void;
64+
onMessageClick?: (commit: Commit) => void;
6465
onMouseOver?: (commit: Commit) => void;
6566
onMouseOut?: (commit: Commit) => void;
6667
}

packages/gitgraph-react/src/Gitgraph.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export class Gitgraph extends React.Component<GitgraphProps, GitgraphState> {
125125
alignmentBaseline="central"
126126
fill={commit.style.message.color}
127127
style={{ font: commit.style.message.font }}
128+
onClick={commit.onMessageClick}
128129
>
129130
{this.getMessage(commit)}
130131
</text>

packages/gitgraph-react/src/stories/events.stories.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Gitgraph } from "gitgraph-react/src/Gitgraph";
55
import { Commit } from "gitgraph-core";
66

77
storiesOf("Gitgraph events", module)
8-
.add("on commit click", () => (
8+
.add("on commit dot click", () => (
99
<Gitgraph>
1010
{(gitgraph) => {
1111
function onClick(commit: Commit) {
@@ -26,6 +26,27 @@ storiesOf("Gitgraph events", module)
2626
}}
2727
</Gitgraph>
2828
))
29+
.add("on commit message click", () => (
30+
<Gitgraph>
31+
{(gitgraph) => {
32+
function onMessageClick(commit: Commit) {
33+
alert(`Commit ${commit.hashAbbrev} clicked: "${commit.subject}"`);
34+
}
35+
36+
const master = gitgraph.branch("master");
37+
master.commit({
38+
subject: "Hello",
39+
body: "First commit",
40+
onMessageClick,
41+
});
42+
master.commit({
43+
subject: "World",
44+
body: "Second commit",
45+
onMessageClick,
46+
});
47+
}}
48+
</Gitgraph>
49+
))
2950
.add("on commit mouseover", () => (
3051
<Gitgraph>
3152
{(gitgraph) => {

0 commit comments

Comments
 (0)