eriknyk / bpmn-js-react-properties-panel-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(!) Note

This is a fork of https://github.com/bpmn-io/bpmn-js-example-react-properties-panel with latest version of react, bpmn-js, and app functional component


React Properties Panel for bpmn-js

This example demonstrates a custom properties panel for bpmn-js written in React.

Demo Screenshot

About

The component PropertiesView implements the properties panel.

The component is mounted via standard React utilities and receives the BPMN modeler instance as props:

  <PropertiesView modeler={ modeler } />

As part of its life-cycle hooks it hooks up with bpmn-js change and selection events to react to editor changes:

class PropertiesView extends React.Component {

  ...
  
  componentDidMount() {
  
    const {
       modeler
    } = this.props;
    
    modeler.on('selection.changed', (e) => {
      this.setElement(e.newSelection[0]);
    });

    modeler.on('element.changed', (e) => {
      this.setElement(e.element);
    });
  }

}

Rendering the component we may display element properties and apply changes:

class PropertiesView extends React.Component {
  
  ...
  
  render() {
  
    const {
      element
    } = this.state;
    
    return (
      <div>
        <fieldset>
          <label>id</label>
          <span>{ element.id }</span>
        </fieldset>

        <fieldset>
          <label>name</label>
          <input value={ element.businessObject.name || '' } onChange={ (event) => {
            this.updateName(event.target.value);
          } } />
        </fieldset>
      </div>
    );
  }
  
  updateName(newName) {
  
    const {
      element
    } = this.state;
    
    const { 
      modeler
    } = this.props;
    
    const modeling = modeler.get('modeling');
    
    modeling.updateLabel(element, newName);
  }
}

License

MIT

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

The page will reload when you make changes.
You may also see any lint errors in the console.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

npm run build fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

About


Languages

Language:JavaScript 74.8%Language:HTML 15.3%Language:CSS 10.0%