Skip to content

Commit 938ff54

Browse files
committed
fixup: update comments, share handler typing
1 parent e44dbe3 commit 938ff54

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/hooks/use-field-selection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { createContext, useContext, useMemo, ReactNode } from 'react';
22

3-
import { FieldId } from '@/types';
3+
import { OnFieldClickHandler } from '@/types';
44

55
interface FieldSelectionContextType {
66
enabled: boolean;
77
fieldProps:
88
| {
9-
onClick: (event: React.MouseEvent, params: { id: FieldId; nodeId: string }) => void;
9+
onClick: OnFieldClickHandler;
1010
}
1111
| undefined;
1212
}
@@ -15,7 +15,7 @@ const FieldSelectionContext = createContext<FieldSelectionContextType | undefine
1515

1616
interface FieldSelectionProviderProps {
1717
children: ReactNode;
18-
onFieldClick?: (event: React.MouseEvent, params: { id: FieldId; nodeId: string }) => void;
18+
onFieldClick?: OnFieldClickHandler;
1919
}
2020

2121
export const FieldSelectionProvider: React.FC<FieldSelectionProviderProps> = ({ children, onFieldClick }) => {

src/types/component-props.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import { NodeProps, FieldId } from '@/types/node';
99
*/
1010
export type OnConnectHandler = (connection: Connection) => void;
1111

12+
/**
13+
* Called when a selectable field is clicked.
14+
*/
15+
export type OnFieldClickHandler = (
16+
event: ReactMouseEvent,
17+
params: {
18+
id: FieldId;
19+
nodeId: string;
20+
},
21+
) => void;
22+
1223
/**
1324
* Called when the canvas (pane) is clicked.
1425
*/
@@ -151,13 +162,7 @@ export interface DiagramProps {
151162
/**
152163
* Callback when the user clicks on a selectable field.
153164
*/
154-
onFieldClick?: (
155-
event: ReactMouseEvent,
156-
params: {
157-
id: FieldId;
158-
nodeId: string;
159-
},
160-
) => void;
165+
onFieldClick?: OnFieldClickHandler;
161166

162167
/**
163168
* Whether the diagram should pan when dragging elements.

src/types/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ export interface NodeField {
174174
hoverVariant?: NodeFieldHoverVariant;
175175

176176
/**
177-
* Indicates if the node can be selected.
177+
* Indicates if the field can be selected.
178178
*/
179179
selectable?: boolean;
180180

181181
/**
182-
* Indicates if the node is currently selected.
182+
* Indicates if the field is currently selected.
183183
*/
184184
selected?: boolean;
185185
}

0 commit comments

Comments
 (0)