Skip to content

Commit 93c6847

Browse files
committed
chore/COMPASS-9493 export typed diagram hook
1 parent 081d176 commit 93c6847

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/components/controls/controls.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Icon from '@leafygreen-ui/icon';
2-
import { ControlButton, Controls as ReactFlowControls, useReactFlow, useViewport } from '@xyflow/react';
2+
import { ControlButton, Controls as ReactFlowControls, useViewport } from '@xyflow/react';
33
import { palette } from '@leafygreen-ui/palette';
44
import { fontFamilies, spacing } from '@leafygreen-ui/tokens';
55
import styled from '@emotion/styled';
66

7+
import { useDiagram } from '@/hooks/use-diagram';
8+
79
const zoomTransitionOption = { duration: 500 };
810

911
const ControlsWrapper = styled(ReactFlowControls)`
@@ -43,7 +45,7 @@ interface DiagramControlsProps {
4345
}
4446

4547
export const Controls = ({ title }: DiagramControlsProps) => {
46-
const { zoomIn, zoomOut, fitView } = useReactFlow();
48+
const { zoomIn, zoomOut, fitView } = useDiagram();
4749
const { zoom } = useViewport();
4850

4951
return (

src/hooks/use-diagram.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { useReactFlow, type ReactFlowInstance } from '@xyflow/react';
2+
3+
import type { InternalEdge, InternalNode } from '@/types/internal';
4+
5+
export type DiagramInstance = ReactFlowInstance<InternalNode, InternalEdge>;
6+
export function useDiagram() {
7+
return useReactFlow<InternalNode, InternalEdge>();
8+
}

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ export { convertToExternalEdge as mapEdgeToDiagramEdge } from '@/utilities/conve
44
export { convertToExternalNode as mapNodeToDiagramNode } from '@/utilities/convert-nodes';
55
export * from '@/utilities/add-nodes-within-bounds';
66
export * from '@/types';
7+
export { useDiagram, type DiagramInstance } from '@/hooks/use-diagram';
78
export {
89
ReactFlowProvider as DiagramProvider,
9-
useReactFlow as useDiagram,
1010
useOnSelectionChange,
1111
getNodesBounds,
1212
getViewportForBounds,
13-
type ReactFlowInstance as DiagramInstance,
1413
} from '@xyflow/react';

0 commit comments

Comments
 (0)