refactor(styling): dont inject styles

This commit is contained in:
moklick
2022-08-09 18:42:12 +02:00
parent a541eb99a5
commit 94463cd0be
42 changed files with 1481 additions and 524 deletions
@@ -149,6 +149,7 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
selected,
selectable: isSelectable,
parent: isParent,
dragging,
},
])}
ref={nodeRef}
@@ -0,0 +1,34 @@
import { MouseEvent } from 'react';
import cc from 'classcat';
import { useStore } from '../../hooks/useStore';
import { containerStyle } from '../../styles';
import type { ReactFlowState } from '../../types';
import type { FlowRendererProps } from '.';
type PaneProps = Pick<FlowRendererProps, 'onClick' | 'onContextMenu' | 'onWheel'> & {
onMouseEnter?: (event: MouseEvent) => void;
onMouseMove?: (event: MouseEvent) => void;
onMouseLeave?: (event: MouseEvent) => void;
};
const selector = (s: ReactFlowState) => s.paneDragging;
function Pane({ onClick, onMouseEnter, onMouseMove, onMouseLeave, onContextMenu, onWheel }: PaneProps) {
const dragging = useStore(selector);
return (
<div
className={cc(['react-flow__pane', { dragging }])}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseMove={onMouseMove}
onMouseLeave={onMouseLeave}
onContextMenu={onContextMenu}
onWheel={onWheel}
style={containerStyle}
/>
);
}
export default Pane;
@@ -7,9 +7,9 @@ import { GraphViewProps } from '../GraphView';
import ZoomPane from '../ZoomPane';
import UserSelection from '../../components/UserSelection';
import NodesSelection from '../../components/NodesSelection';
import Pane from './Pane';
import { ReactFlowState } from '../../types';
import { containerStyle } from '../../styles';
export type FlowRendererProps = Omit<
GraphViewProps,
@@ -110,15 +110,13 @@ const FlowRenderer = ({
disableKeyboardA11y={disableKeyboardA11y}
/>
)}
<div
className="react-flow__pane"
<Pane
onClick={onClick}
onMouseEnter={onPaneMouseEnter}
onMouseMove={onPaneMouseMove}
onMouseLeave={onPaneMouseLeave}
onContextMenu={onContextMenu}
onWheel={onWheel}
style={containerStyle}
/>
</ZoomPane>
);
@@ -1,6 +1,5 @@
import { CSSProperties, forwardRef, useId } from 'react';
import cc from 'classcat';
import { injectStyle } from '@react-flow/css-utils';
import Attribution from '../../components/Attribution';
import { BezierEdge, SmoothStepEdge, StepEdge, StraightEdge, SimpleBezierEdge } from '../../components/Edges';
@@ -9,9 +8,6 @@ import InputNode from '../../components/Nodes/InputNode';
import OutputNode from '../../components/Nodes/OutputNode';
import SelectionListener from '../../components/SelectionListener';
import StoreUpdater from '../../components/StoreUpdater';
import baseStyle from '../../styles/base';
injectStyle(baseStyle);
import {
ConnectionLineType,
@@ -169,7 +169,9 @@ const ZoomPane = ({
if (d3Zoom) {
d3Zoom.on('start', (event: D3ZoomEvent<HTMLDivElement, any>) => {
isZoomingOrPanning.current = true;
if (event.sourceEvent?.type === 'mousedown') {
store.setState({ paneDragging: true });
}
if (onMoveStart) {
const flowTransform = eventToFlowTransform(event.transform);
prevTransform.current = flowTransform;
@@ -184,6 +186,7 @@ const ZoomPane = ({
if (d3Zoom) {
d3Zoom.on('end', (event: D3ZoomEvent<HTMLDivElement, any>) => {
isZoomingOrPanning.current = false;
store.setState({ paneDragging: false });
if (onMoveEnd && viewChanged(prevTransform.current, event.transform)) {
const flowTransform = eventToFlowTransform(event.transform);
+1
View File
@@ -30,6 +30,7 @@ const initialState: ReactFlowStore = {
connectionPosition: { x: 0, y: 0 },
connectionMode: ConnectionMode.Strict,
domNode: null,
paneDragging: false,
snapGrid: [15, 15],
snapToGrid: false,
+25
View File
@@ -0,0 +1,25 @@
/* these are very simple styles so that it doesnt look broken */
@import './init.css';
.react-flow__handle {
background-color: #333;
}
.react-flow__node {
border-width: 1px;
border-style: solid;
border-color: #bbb;
&.selected,
&:focus,
&:focus-visible {
outline: none;
border: 1px solid #555;
}
}
.react-flow__nodesselection-rect,
.react-flow__selection {
background: rgba(150, 150, 180, 0.1);
border: 1px dotted rgba(155, 155, 155, 0.8);
}
-226
View File
@@ -1,226 +0,0 @@
const style = `
.react-flow__container {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.react-flow__pane {
z-index: 1;
}
.react-flow__viewport {
transform-origin: 0 0;
z-index: 2;
pointer-events: none;
}
.react-flow__renderer {
z-index: 4;
}
.react-flow__selectionpane {
z-index: 5;
}
.react-flow__nodesselection-rect,
.react-flow__selection {
background: rgba(150, 150, 180, 0.1);
border: 1px dotted rgba(155, 155, 155, 0.8);
}
.react-flow__nodesselection-rect:focus,
.react-flow__nodesselection-rect:focus-visible {
outline: none;
}
.react-flow .react-flow__edges {
pointer-events: none;
overflow: visible;
}
.react-flow__connection {
pointer-events: none;
}
.react-flow__connection.animated {
stroke-dasharray: 5;
animation: dashdraw 0.5s linear infinite;
}
.react-flow .react-flow__connectionline {
z-index: 1001;
}
.react-flow__connectionline path, .react-flow__edge path {
fill: none;
}
.react-flow__edge-path, .react-flow__connection-path {
stroke: #b1b1b7;
stroke-width: 1;
}
.react-flow__edge {
pointer-events: visibleStroke;
}
.react-flow__edge.animated path {
stroke-dasharray: 5;
animation: dashdraw 0.5s linear infinite;
}
.react-flow__edge.inactive {
pointer-events: none;
}
.react-flow__edge.selected, .react-flow__edge:focus, .react-flow__edge:focus-visible {
outline: none;
}
.react-flow__edge.selected .react-flow__edge-path,
.react-flow__edge:focus .react-flow__edge-path,
.react-flow__edge:focus-visible .react-flow__edge-path {
stroke: #555;
}
@keyframes dashdraw {
from {
stroke-dashoffset: 10;
}
}
.react-flow__edge-textwrapper {
pointer-events: all;
}
.react-flow__edge-text {
pointer-events: none;
user-select: none;
}
.react-flow__edge-textbg {
fill: white;
}
.react-flow__nodes {
pointer-events: none;
transform-origin: 0 0;
}
.react-flow__node {
position: absolute;
user-select: none;
pointer-events: all;
transform-origin: 0 0;
box-sizing: border-box;
background-color: white;
cursor: grab;
border: 1px solid #bbb;
}
.react-flow__node.selected,
.react-flow__node:focus,
.react-flow__node:focus-visible {
outline: none;
border: 1px solid #555;
}
.react-flow__nodesselection {
z-index: 3;
transform-origin: left top;
pointer-events: none;
}
.react-flow__nodesselection-rect {
position: absolute;
pointer-events: all;
cursor: grab;
}
.react-flow__handle {
position: absolute;
pointer-events: none;
min-width: 5px;
min-height: 5px;
background-color: #333;
}
.react-flow__handle.connectable {
pointer-events: all;
}
.react-flow__handle-bottom {
top: auto;
left: 50%;
bottom: -4px;
transform: translate(-50%, 0);
}
.react-flow__handle-top {
left: 50%;
top: -4px;
transform: translate(-50%, 0);
}
.react-flow__handle-left {
top: 50%;
left: -4px;
transform: translate(0, -50%);
}
.react-flow__handle-right {
right: -4px;
top: 50%;
transform: translate(0, -50%);
}
.react-flow__edgeupdater {
cursor: move;
pointer-events: all;
}
.react-flow__panel {
position: absolute;
z-index: 1000;
margin: 15px;
}
.react-flow__panel.top {
top: 0;
}
.react-flow__panel.bottom {
bottom: 0;
}
.react-flow__panel.left {
left: 0;
}
.react-flow__panel.right {
right: 0;
}
.react-flow__panel.center {
left: 50%;
transform: translateX(-50%);
}
.react-flow__attribution {
font-size: 10px;
background: rgba(255, 255, 255, 0.5);
padding: 2px 3px;
color: #999;
margin: 0;
}
.react-flow__attribution a {
color: #555;
text-decoration: none;
}
`;
export default style;
+216
View File
@@ -0,0 +1,216 @@
/* these are the necessary styles for React Flow */
.react-flow__container {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
.react-flow__pane {
z-index: 1;
cursor: grab;
&.dragging {
cursor: grabbing;
}
}
.react-flow__viewport {
transform-origin: 0 0;
z-index: 2;
pointer-events: none;
}
.react-flow__renderer {
z-index: 4;
}
.react-flow__selectionpane {
z-index: 5;
}
.react-flow__nodesselection-rect:focus,
.react-flow__nodesselection-rect:focus-visible {
outline: none;
}
.react-flow .react-flow__edges {
pointer-events: none;
overflow: visible;
}
.react-flow__edge-path,
.react-flow__connection-path {
stroke: #b1b1b7;
stroke-width: 1;
}
.react-flow__edge {
pointer-events: visibleStroke;
cursor: pointer;
&.animated path {
stroke-dasharray: 5;
animation: dashdraw 0.5s linear infinite;
}
&.inactive {
pointer-events: none;
}
&.selected,
&:focus,
&:focus-visible {
outline: none;
}
&.selected .react-flow__edge-path,
&:focus .react-flow__edge-path,
&:focus-visible .react-flow__edge-path {
stroke: #555;
}
&-textwrapper {
pointer-events: all;
}
&-textbg {
fill: white;
}
.react-flow__edge-text {
pointer-events: none;
user-select: none;
}
}
.react-flow__connection {
pointer-events: none;
&.animated {
stroke-dasharray: 5;
animation: dashdraw 0.5s linear infinite;
}
}
.react-flow__connectionline {
z-index: 1001;
}
.react-flow__nodes {
pointer-events: none;
transform-origin: 0 0;
}
.react-flow__node {
position: absolute;
user-select: none;
pointer-events: all;
transform-origin: 0 0;
box-sizing: border-box;
background-color: white;
cursor: grab;
&.dragging {
cursor: grabbing;
}
}
.react-flow__nodesselection {
z-index: 3;
transform-origin: left top;
pointer-events: none;
&-rect {
position: absolute;
pointer-events: all;
cursor: grab;
}
}
.react-flow__handle {
position: absolute;
pointer-events: none;
min-width: 5px;
min-height: 5px;
&.connectable {
pointer-events: all;
}
&-bottom {
top: auto;
left: 50%;
bottom: -4px;
transform: translate(-50%, 0);
}
&-top {
left: 50%;
top: -4px;
transform: translate(-50%, 0);
}
&-left {
top: 50%;
left: -4px;
transform: translate(0, -50%);
}
&-right {
right: -4px;
top: 50%;
transform: translate(0, -50%);
}
}
.react-flow__edgeupdater {
cursor: move;
pointer-events: all;
}
.react-flow__panel {
position: absolute;
z-index: 1000;
margin: 15px;
&.top {
top: 0;
}
&.bottom {
bottom: 0;
}
&.left {
left: 0;
}
&.right {
right: 0;
}
&.center {
left: 50%;
transform: translateX(-50%);
}
}
.react-flow__attribution {
font-size: 10px;
background: rgba(255, 255, 255, 0.5);
padding: 2px 3px;
margin: 0;
a {
text-decoration: none;
color: #999;
}
}
@keyframes dashdraw {
from {
stroke-dashoffset: 10;
}
}
+66
View File
@@ -0,0 +1,66 @@
@import './init.css';
.react-flow__edge {
&.updating {
.react-flow__edge-path {
stroke: #777;
}
}
&-text {
font-size: 10px;
}
}
.react-flow__node {
padding: 10px;
border-radius: 3px;
width: 150px;
font-size: 12px;
color: #222;
text-align: center;
border-width: 1px;
border-style: solid;
border-color: #1a192b;
&.selectable {
&:hover {
box-shadow: 0 1px 4px 1px rgba(0, 0, 0, 0.08);
}
&.selected,
&:focus,
&:focus-visible {
box-shadow: 0 0 0 0.5px #1a192b;
outline: none;
}
}
&-group {
background: rgba(240, 240, 240, 0.25);
border-color: #1a192b;
}
}
.react-flow__nodesselection-rect,
.react-flow__selection {
background: rgba(0, 89, 220, 0.08);
border: 1px dotted rgba(0, 89, 220, 0.8);
&:focus,
&:focus-visible {
outline: none;
}
}
.react-flow__handle {
width: 6px;
height: 6px;
background: #1a192b;
border: 1px solid white;
border-radius: 100%;
&.connectable {
cursor: crosshair;
}
}
@@ -1,83 +0,0 @@
.react-flow__edge {
&.updating {
.react-flow__edge-path {
stroke: #777;
}
}
}
.react-flow__edge-text {
font-size: 10px;
}
.react-flow__node-default,
.react-flow__node-input,
.react-flow__node-output,
.react-flow__node-group {
padding: 10px;
border-radius: 3px;
width: 150px;
font-size: 12px;
color: #222;
text-align: center;
border-width: 1px;
border-style: solid;
border-color: #1a192b;
&.selected,
&:focus,
&:focus-visible {
border: none;
box-shadow: 0 0 0 0.5px #1a192b;
outline: none;
}
.react-flow__handle {
background: #1a192b;
}
}
.react-flow__node-default.selectable,
.react-flow__node-input.selectable,
.react-flow__node-output.selectable,
.react-flow__node-group.selectable {
&:hover {
box-shadow: 0 1px 4px 1px rgba(0, 0, 0, 0.08);
}
&.selected,
&:focus,
&:focus-visible {
border: none;
box-shadow: 0 0 0 0.5px #1a192b;
outline: none;
}
}
.react-flow__node-group {
background: rgba(240, 240, 240, 0.25);
border-color: #1a192b;
}
.react-flow__nodesselection-rect,
.react-flow__selection {
background: rgba(0, 89, 220, 0.08);
border: 1px dotted rgba(0, 89, 220, 0.8);
&:focus,
&:focus-visible {
outline: none;
}
}
.react-flow__handle {
width: 6px;
height: 6px;
background: #555;
border: 1px solid white;
border-radius: 100%;
&.connectable {
cursor: crosshair;
}
}
+1
View File
@@ -137,6 +137,7 @@ export type ReactFlowStore = {
hasDefaultNodes: boolean;
hasDefaultEdges: boolean;
domNode: HTMLDivElement | null;
paneDragging: boolean;
d3Zoom: ZoomBehavior<Element, unknown> | null;
d3Selection: D3Selection<Element, unknown, null, undefined> | null;