Skip to content

Commit 0b241d2

Browse files
committed
feat(attribution): add react flow attribution
1 parent d285318 commit 0b241d2

5 files changed

Lines changed: 91 additions & 4 deletions

File tree

example/src/Overview/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ const OverviewFlow = () => {
193193
onEdgeMouseLeave={onEdgeMouseLeave}
194194
onEdgeDoubleClick={onEdgeDoubleClick}
195195
fitViewOnInit
196+
attributionPosition="top-right"
196197
>
197198
<MiniMap nodeStrokeColor={nodeStrokeColor} nodeColor={nodeColor} nodeBorderRadius={2} />
198199
<Controls />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import cc from 'classcat';
3+
4+
import { AttributionPosition, ProOptions } from '../../types';
5+
6+
type AttributionProps = {
7+
pro?: ProOptions;
8+
position?: AttributionPosition;
9+
};
10+
11+
function Attribution({ pro, position = 'bottom-right' }: AttributionProps) {
12+
if (pro?.account === 'paid-subscription' && pro?.hideAttribution) {
13+
return null;
14+
}
15+
16+
const positionClasses = `${position}`.split('-');
17+
18+
return (
19+
<div
20+
className={cc(['react-flow__attribution', ...positionClasses])}
21+
data-message="Please only hide this attribution when you have a pro account: reactflow.dev/pro"
22+
>
23+
<a href="https://reactflow.dev" target="_blank" rel="noopener noreferrer">
24+
React Flow
25+
</a>
26+
</div>
27+
);
28+
}
29+
30+
export default Attribution;

src/container/ReactFlow/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import OutputNode from '../../components/Nodes/OutputNode';
1717
import { createNodeTypes } from '../NodeRenderer/utils';
1818
import SelectionListener from '../../components/SelectionListener';
1919
import { BezierEdge, StepEdge, SmoothStepEdge, StraightEdge } from '../../components/Edges';
20+
import Attribution from '../../components/Attribution';
2021
import { createEdgeTypes } from '../EdgeRenderer/utils';
2122
import Wrapper from './Wrapper';
2223
import {
@@ -40,6 +41,8 @@ import {
4041
NodeChange,
4142
EdgeChange,
4243
OnPaneReady,
44+
ProOptions,
45+
AttributionPosition,
4346
} from '../../types';
4447

4548
import '../../style.css';
@@ -135,6 +138,8 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
135138
noPanClassName?: string;
136139
fitViewOnInit?: boolean;
137140
connectOnClick?: boolean;
141+
attributionPosition?: AttributionPosition;
142+
pro?: ProOptions;
138143
}
139144

140145
export type ReactFlowRefType = HTMLDivElement;
@@ -223,6 +228,8 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
223228
noPanClassName = 'nopan',
224229
fitViewOnInit = false,
225230
connectOnClick = true,
231+
attributionPosition,
232+
pro,
226233
...rest
227234
},
228235
ref
@@ -315,6 +322,7 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
315322
/>
316323
{onSelectionChange && <SelectionListener onSelectionChange={onSelectionChange} />}
317324
{children}
325+
<Attribution pro={pro} position={attributionPosition} />
318326
</Wrapper>
319327
</div>
320328
);

src/style.css

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@
144144
.react-flow__controls {
145145
position: absolute;
146146
z-index: 5;
147-
bottom: 10px;
148-
left: 10px;
147+
bottom: 20px;
148+
left: 15px;
149149

150150
&-button {
151151
width: 24px;
@@ -161,6 +161,41 @@
161161
.react-flow__minimap {
162162
position: absolute;
163163
z-index: 5;
164-
bottom: 10px;
165-
right: 10px;
164+
bottom: 20px;
165+
right: 15px;
166+
}
167+
168+
.react-flow__attribution {
169+
font-size: 10px;
170+
position: absolute;
171+
z-index: 1000;
172+
background: rgba(255, 255, 255, 0.5);
173+
padding: 2px 3px;
174+
color: #999;
175+
176+
a {
177+
color: #555;
178+
text-decoration: none;
179+
}
180+
181+
&.top {
182+
top: 0;
183+
}
184+
185+
&.bottom {
186+
bottom: 0;
187+
}
188+
189+
&.left {
190+
left: 0;
191+
}
192+
193+
&.right {
194+
right: 0;
195+
}
196+
197+
&.center {
198+
left: 50%;
199+
transform: translateX(-50%);
200+
}
166201
}

src/types/general.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,16 @@ export type OnSelectionChangeParams = {
210210
};
211211

212212
export type OnSelectionChangeFunc = (params: OnSelectionChangeParams) => void;
213+
214+
export type AttributionPosition =
215+
| 'top-left'
216+
| 'top-center'
217+
| 'top-right'
218+
| 'bottom-left'
219+
| 'bottom-center'
220+
| 'bottom-right';
221+
222+
export type ProOptions = {
223+
account: string;
224+
hideAttribution: boolean;
225+
};

0 commit comments

Comments
 (0)