MrBlenny / react-flow-chart

🌊 A flexible, stateless, declarative flow chart library for react.
https://mrblenny.github.io/react-flow-chart/index.html
MIT License
1.46k stars 307 forks source link

Custom node compatibility with base javascript #110

Closed chriskonopka closed 4 years ago

chriskonopka commented 4 years ago

I am attempting to utilize your library in a react project that is written in plain javascript files. While I can get the most basic examples imported and rendered I am having trouble converting the type script use cases for a custom node.

  1. is there a javascript only example?

  2. if not is it possible to have custom javascript nodes built on the typescript based nodes? 2a. if it is possible, what is the best way to convert the createNode function seen here to javascript? https://github.com/MrBlenny/react-flow-chart/blob/master/stories/CustomNode.tsx#L33

chriskonopka commented 4 years ago

regarding 2a, my current idea is something like this: import { FlowChartWithState, INodeDefaultProps } from '@mrblenny/react-flow-chart'; ...

  createNode = () => {
      const temp = INodeDefaultProps;
      const { node, children, ref,  ...otherProps } = temp;
      if (node.type === 'output-only') {
        return (
          <DarkBox ref={ref} {...otherProps}>
            {children}
          </DarkBox>
        )
      } else {
        return (
          <Circle ref={ref} {...otherProps}>
            {children}
          </Circle>
        )
      }
    };

but the reason I am questioning the possibility is I keep getting 'Element not Accessable' errors for INodeDefaultProps, and I'm wondering if it's not importable to base js.

rumanhassan commented 4 years ago

INodeDefaultProps is an interface. javascript doesn't support interfaces by default. You need to have typescript to start using it.

MrBlenny commented 4 years ago

You should be able to use custom components without typescript. As rumanhassan said, just make sure you don't import any interfaces/types.