Skip to content

Commit

Permalink
feat(attribution): add react flow attribution
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Jan 5, 2022
1 parent d285318 commit 0b241d2
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
1 change: 1 addition & 0 deletions example/src/Overview/index.tsx
Expand Up @@ -193,6 +193,7 @@ const OverviewFlow = () => {
onEdgeMouseLeave={onEdgeMouseLeave}
onEdgeDoubleClick={onEdgeDoubleClick}
fitViewOnInit
attributionPosition="top-right"
>
<MiniMap nodeStrokeColor={nodeStrokeColor} nodeColor={nodeColor} nodeBorderRadius={2} />
<Controls />
Expand Down
30 changes: 30 additions & 0 deletions src/components/Attribution/index.tsx
@@ -0,0 +1,30 @@
import React from 'react';
import cc from 'classcat';

import { AttributionPosition, ProOptions } from '../../types';

type AttributionProps = {
pro?: ProOptions;
position?: AttributionPosition;
};

function Attribution({ pro, position = 'bottom-right' }: AttributionProps) {
if (pro?.account === 'paid-subscription' && pro?.hideAttribution) {
return null;
}

const positionClasses = `${position}`.split('-');

return (
<div
className={cc(['react-flow__attribution', ...positionClasses])}
data-message="Please only hide this attribution when you have a pro account: reactflow.dev/pro"
>
<a href="https://reactflow.dev" target="_blank" rel="noopener noreferrer">
React Flow
</a>
</div>
);
}

export default Attribution;
8 changes: 8 additions & 0 deletions src/container/ReactFlow/index.tsx
Expand Up @@ -17,6 +17,7 @@ import OutputNode from '../../components/Nodes/OutputNode';
import { createNodeTypes } from '../NodeRenderer/utils';
import SelectionListener from '../../components/SelectionListener';
import { BezierEdge, StepEdge, SmoothStepEdge, StraightEdge } from '../../components/Edges';
import Attribution from '../../components/Attribution';
import { createEdgeTypes } from '../EdgeRenderer/utils';
import Wrapper from './Wrapper';
import {
Expand All @@ -40,6 +41,8 @@ import {
NodeChange,
EdgeChange,
OnPaneReady,
ProOptions,
AttributionPosition,
} from '../../types';

import '../../style.css';
Expand Down Expand Up @@ -135,6 +138,8 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
noPanClassName?: string;
fitViewOnInit?: boolean;
connectOnClick?: boolean;
attributionPosition?: AttributionPosition;
pro?: ProOptions;
}

export type ReactFlowRefType = HTMLDivElement;
Expand Down Expand Up @@ -223,6 +228,8 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
noPanClassName = 'nopan',
fitViewOnInit = false,
connectOnClick = true,
attributionPosition,
pro,
...rest
},
ref
Expand Down Expand Up @@ -315,6 +322,7 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
/>
{onSelectionChange && <SelectionListener onSelectionChange={onSelectionChange} />}
{children}
<Attribution pro={pro} position={attributionPosition} />
</Wrapper>
</div>
);
Expand Down
43 changes: 39 additions & 4 deletions src/style.css
Expand Up @@ -144,8 +144,8 @@
.react-flow__controls {
position: absolute;
z-index: 5;
bottom: 10px;
left: 10px;
bottom: 20px;
left: 15px;

&-button {
width: 24px;
Expand All @@ -161,6 +161,41 @@
.react-flow__minimap {
position: absolute;
z-index: 5;
bottom: 10px;
right: 10px;
bottom: 20px;
right: 15px;
}

.react-flow__attribution {
font-size: 10px;
position: absolute;
z-index: 1000;
background: rgba(255, 255, 255, 0.5);
padding: 2px 3px;
color: #999;

a {
color: #555;
text-decoration: none;
}

&.top {
top: 0;
}

&.bottom {
bottom: 0;
}

&.left {
left: 0;
}

&.right {
right: 0;
}

&.center {
left: 50%;
transform: translateX(-50%);
}
}
13 changes: 13 additions & 0 deletions src/types/general.ts
Expand Up @@ -210,3 +210,16 @@ export type OnSelectionChangeParams = {
};

export type OnSelectionChangeFunc = (params: OnSelectionChangeParams) => void;

export type AttributionPosition =
| 'top-left'
| 'top-center'
| 'top-right'
| 'bottom-left'
| 'bottom-center'
| 'bottom-right';

export type ProOptions = {
account: string;
hideAttribution: boolean;
};

0 comments on commit 0b241d2

Please sign in to comment.