feat(attribution): add react flow attribution

This commit is contained in:
moklick
2022-01-05 16:45:04 +01:00
parent d2853182f4
commit 0b241d27c1
5 changed files with 91 additions and 4 deletions
+1
View File
@@ -193,6 +193,7 @@ const OverviewFlow = () => {
onEdgeMouseLeave={onEdgeMouseLeave} onEdgeMouseLeave={onEdgeMouseLeave}
onEdgeDoubleClick={onEdgeDoubleClick} onEdgeDoubleClick={onEdgeDoubleClick}
fitViewOnInit fitViewOnInit
attributionPosition="top-right"
> >
<MiniMap nodeStrokeColor={nodeStrokeColor} nodeColor={nodeColor} nodeBorderRadius={2} /> <MiniMap nodeStrokeColor={nodeStrokeColor} nodeColor={nodeColor} nodeBorderRadius={2} />
<Controls /> <Controls />
+30
View File
@@ -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
View File
@@ -17,6 +17,7 @@ import OutputNode from '../../components/Nodes/OutputNode';
import { createNodeTypes } from '../NodeRenderer/utils'; import { createNodeTypes } from '../NodeRenderer/utils';
import SelectionListener from '../../components/SelectionListener'; import SelectionListener from '../../components/SelectionListener';
import { BezierEdge, StepEdge, SmoothStepEdge, StraightEdge } from '../../components/Edges'; import { BezierEdge, StepEdge, SmoothStepEdge, StraightEdge } from '../../components/Edges';
import Attribution from '../../components/Attribution';
import { createEdgeTypes } from '../EdgeRenderer/utils'; import { createEdgeTypes } from '../EdgeRenderer/utils';
import Wrapper from './Wrapper'; import Wrapper from './Wrapper';
import { import {
@@ -40,6 +41,8 @@ import {
NodeChange, NodeChange,
EdgeChange, EdgeChange,
OnPaneReady, OnPaneReady,
ProOptions,
AttributionPosition,
} from '../../types'; } from '../../types';
import '../../style.css'; import '../../style.css';
@@ -135,6 +138,8 @@ export interface ReactFlowProps extends Omit<HTMLAttributes<HTMLDivElement>, 'on
noPanClassName?: string; noPanClassName?: string;
fitViewOnInit?: boolean; fitViewOnInit?: boolean;
connectOnClick?: boolean; connectOnClick?: boolean;
attributionPosition?: AttributionPosition;
pro?: ProOptions;
} }
export type ReactFlowRefType = HTMLDivElement; export type ReactFlowRefType = HTMLDivElement;
@@ -223,6 +228,8 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
noPanClassName = 'nopan', noPanClassName = 'nopan',
fitViewOnInit = false, fitViewOnInit = false,
connectOnClick = true, connectOnClick = true,
attributionPosition,
pro,
...rest ...rest
}, },
ref ref
@@ -315,6 +322,7 @@ const ReactFlow: FunctionComponent<ReactFlowProps> = forwardRef<ReactFlowRefType
/> />
{onSelectionChange && <SelectionListener onSelectionChange={onSelectionChange} />} {onSelectionChange && <SelectionListener onSelectionChange={onSelectionChange} />}
{children} {children}
<Attribution pro={pro} position={attributionPosition} />
</Wrapper> </Wrapper>
</div> </div>
); );
+39 -4
View File
@@ -144,8 +144,8 @@
.react-flow__controls { .react-flow__controls {
position: absolute; position: absolute;
z-index: 5; z-index: 5;
bottom: 10px; bottom: 20px;
left: 10px; left: 15px;
&-button { &-button {
width: 24px; width: 24px;
@@ -161,6 +161,41 @@
.react-flow__minimap { .react-flow__minimap {
position: absolute; position: absolute;
z-index: 5; z-index: 5;
bottom: 10px; bottom: 20px;
right: 10px; 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
View File
@@ -210,3 +210,16 @@ export type OnSelectionChangeParams = {
}; };
export type OnSelectionChangeFunc = (params: OnSelectionChangeParams) => void; 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;
};