From c0392529834ceb1718f4bef0dea9674bc007e283 Mon Sep 17 00:00:00 2001 From: AykutSarac Date: Tue, 1 Feb 2022 23:47:41 +0300 Subject: [PATCH] create react-flow custom node --- src/pages/editor/LiveEditor/Node.tsx | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/pages/editor/LiveEditor/Node.tsx diff --git a/src/pages/editor/LiveEditor/Node.tsx b/src/pages/editor/LiveEditor/Node.tsx new file mode 100644 index 0000000..fbc1ed2 --- /dev/null +++ b/src/pages/editor/LiveEditor/Node.tsx @@ -0,0 +1,59 @@ +import React from "react"; +import { Handle, Position } from "react-flow-renderer"; +import styled from "styled-components"; + +const StyledWrapper = styled.div<{ isArray?: boolean }>` + background: ${({ theme }) => theme.BLACK_SECONDARY}; + border-radius: 5px; + padding: 16px; + color: ${({ theme, isArray }) => isArray && theme.SEAGREEN}; + width: auto; + min-width: 100px; + text-align: ${({ isArray }) => isArray && "center"}; +`; + +const StyledKey = styled.span` + color: ${({ theme }) => theme.BLURPLE}; +`; + +export const CustomNodeComponent: React.FC<{ data: any; id: string }> = ({ + id, + data, +}) => { + const { label: json } = data; + + if (typeof json === "string") { + return ( + + {json} + + + + ); + } + + if (typeof json === "object") { + const keyPairs = Object.entries(json); + + return ( + + {keyPairs.map((entries) => { + const isValidValue = + typeof entries[1] === "string" || typeof entries[1] === "number"; + + return ( +
+ {entries[0]}: + {isValidValue && entries[1]} +
+ ); + })} + + + +
+ ); + } + + return null; +};