Add node prototype

nodeDev
Klotske 2022-07-14 20:01:46 +00:00
parent 6c5ae38361
commit 21450c0d99
4 changed files with 44 additions and 1 deletions

View File

@ -6,6 +6,9 @@ import ReactFlow, {
ReactFlowInstance,
} from "react-flow-renderer";
import useStore from "../../lib/FlowEditor/FlowEditorStore";
import GenericNode from "./nodes/Node";
const nodeTypes = { generic: GenericNode };
const Flow = () => {
const [reactFlowInstance, setReactFlowInstance] =
@ -24,6 +27,7 @@ const Flow = () => {
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}

View File

@ -0,0 +1,33 @@
import styles from "./Node.module.css";
import { Handle, Position } from "react-flow-renderer";
type GenericNodeProps = {};
const GenericNode = (props: GenericNodeProps) => {
return (
// Базовый класс generic-node - прописана ширина и положение, цвет текста и фона
// Nandle - ручка для коннекта. Можно задать оформление при помощи className, тип (target / source) и позицию
// Label - подпись ноды. Можно стилизовать
// Select - DropDown меню, можно стилизовать. Стоит класс nodrag для предотвращения залипания
<div className="generic-node">
<Handle className="" type="target" position={Position.Top} />
<div className="generic-node-content">
<label htmlFor="select">Выбери своего покемона: </label>
<select className="nodrag">
<option>Гена</option>
<option>Чайка</option>
<option>Бульбазавр</option>
</select>
</div>
<Handle className="" type="source" position={Position.Bottom} />
</div>
);
};
export default GenericNode;

View File

@ -3,7 +3,7 @@ import { Node } from "react-flow-renderer";
const initialNodes: Node[] = [
{
id: "1",
type: "input",
type: "generic",
data: { label: "Старт" },
position: { x: 0, y: 0 },
},

View File

@ -63,4 +63,10 @@
.flow {
}
.generic-node {
@apply flex items-center justify-center
w-[150px] h-auto bg-white
rounded-sm;
}
}