Advertisement
Guest User

Untitled

a guest
Nov 12th, 2020
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Diagram, { createSchema, useSchema } from "beautiful-react-diagrams";
  2. import "beautiful-react-diagrams/styles.css";
  3. import React from "react";
  4. import Background from "./usb.png";
  5.  
  6. const CustomNode = (props) => {
  7.   const { outputs } = props;
  8.  
  9.   return (
  10.     <div
  11.       style={{
  12.         backgroundImage: "url(" + Background + ")",
  13.         height: "100px",
  14.         width: "100px",
  15.         borderRadius: "30px",
  16.         backgroundColor: "#FFF5CC",
  17.       }}
  18.     >
  19.       <div style={{ padding: "10px", color: "white" }}></div>
  20.       <div style={{ marginTop: "10px" }}>
  21.         {outputs.map((port) =>
  22.           React.cloneElement(port, {
  23.             style: {
  24.               width: "5px",
  25.               height: "40px",
  26.               background: "#1B263B",
  27.               borderRadius: "0% 100% 100% 0%",
  28.             },
  29.           })
  30.         )}
  31.       </div>
  32.     </div>
  33.   );
  34. };
  35.  
  36. const initialSchema = createSchema({
  37.   nodes: [
  38.     {
  39.       id: 'node-1',
  40.       content: 'Node 1',
  41.       coordinates: [150, 60],
  42.       outputs: [ { id: 'port-1', alignment: 'right' } ],
  43.     },
  44.     {
  45.       id: "node-custom",
  46.       coordinates: [350, 250],
  47.       render: CustomNode,
  48.       outputs: [{ id: 'img-port', alignment: 'right' }],
  49.     },
  50.   ],
  51. });
  52.  
  53. const UncontrolledDiagram = () => {
  54.   // create diagrams schema
  55.   const [schema, { onChange }] = useSchema(initialSchema);
  56.  
  57.   return (
  58.     <div style={{ height: "80rem" }}>
  59.       <Diagram schema={schema} onChange={onChange} />
  60.     </div>
  61.   );
  62. };
  63.  
  64. export default function App() {
  65.   return (
  66.     <div>
  67.       <UncontrolledDiagram />
  68.     </div>
  69.   );
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement