Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi , how to have port name ? #140

Open
gjgit opened this issue May 26, 2021 · 1 comment
Open

Hi , how to have port name ? #140

gjgit opened this issue May 26, 2021 · 1 comment

Comments

@gjgit
Copy link

gjgit commented May 26, 2021

how to have the port name in output/input ?

inputs: [
        { id: "custom-port-1", alignment: "left", label: "one" },
        { id: "custom-port-2", alignment: "left", label: "two" },
      ],   
@michaelzusev
Copy link

Hi, this is my (admittedly hacky) solution, extended from the Custom Node example documentation:

import './App.css';
import 'beautiful-react-diagrams/styles.css';

import React from "react";
import Diagram, { createSchema, useSchema } from 'beautiful-react-diagrams';


function App() {
  // the diagram model
  const CustomNode = (props) => {
    const { inputs } = props;
    
    return (
      <div style={{ background: '#717EC3', borderRadius: '10px' }}>
        <div style={{ padding: '10px', color: 'white'  }}>
          Custom Node With Port Names
        </div>
        <div style={{marginTop: '20px'}}>
          {inputs.map((port) => React.cloneElement(port, {
            style: { width: '25px', height: '25px', background: '#1B263B' }
          }, <p style={{marginLeft:'30px'}}>{port.props.name}</p>))}
         
        </div>
      </div>
    );
  };
  
  const initialSchema = createSchema({
    nodes: [
      { 
        id: 'node-1', 
        content: 'Node 1', 
        coordinates: [150, 60], 
        outputs: [ { id: 'port-1', alignment: 'right' } ], 
      },
      { 
        id: 'node-custom', 
        coordinates: [250, 60], 
        render: CustomNode,
        inputs: [ { id: 'custom-port-1',  alignment: 'left', name:'Test' },
                  { id: 'custom-port-2', alignment: 'left', name: 'anothertest'} ],
      },
    ]
  });
  
  const UncontrolledDiagram = () => {
    // create diagrams schema
    const [schema, { onChange }] = useSchema(initialSchema);
  
    return (
      <div style={{ height: '22.5rem' }}>
        <Diagram schema={schema} onChange={onChange} />
      </div>
    );
  };
  return <UncontrolledDiagram />
}

export default App;

Makes this:

2021-08-03 15_24_16-React App

There's probably a better way of doing it though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants