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

new more "functional" api #19

Closed
sghall opened this issue Apr 30, 2017 · 1 comment
Closed

new more "functional" api #19

sghall opened this issue Apr 30, 2017 · 1 comment
Assignees

Comments

@sghall
Copy link
Owner

sghall commented Apr 30, 2017

It would be a lot cleaner to export a NodeGroup component that accepts functions for deriving the starting state and rendering. Clears up some conceptual issues with passing a "node" component and reduces the total lines needed to code a transition group. Just much cleaner.

Would look like this...

<NodeGroup
  data={this.state.data}
  keyAccessor={(d) => d.name}

  start={(node, index) => ({ // starting state
    opacity: 1e-6,
    x: 1e-6,
    fill: 'green',
    width: scale.bandwidth(),
  })}

  enter={(node, index) => ({
    opacity: [0.5],
    x: [scale(node.name)],
    timing: { duration: 1500 },
  })}

  update={(node, index) => ({
    opacity: [0.5],
    x: [scale(node.name)],
    fill: 'blue',
    width: [scale.bandwidth()],
    timing: { duration: 1500 },
  })}

  leave={(node, index, remove) => ({
    opacity: [1e-6],
    x: [scale.range()[1]],
    fill: 'red',
    timing: { duration: 1500 },
    events: { end: remove },
  })}

  render={(node, state, index) => {
    const { x, ...rest } = state;

    return (
      <g transform={`translate(${x},0)`}>
        <rect
          height={dims[1]}
          {...rest}
        />
        <text
          x="0"
          y="20"
          fill="white"
          transform="rotate(90 5,20)"
        >{`x: ${x}`}</text>
        <text
          x="0"
          y="5"
          fill="white"
          transform="rotate(90 5,20)"
        >{`name: ${node.name}`}</text>
      </g>
    );
  }}
/>
@sghall sghall self-assigned this Apr 30, 2017
@sghall
Copy link
Owner Author

sghall commented May 9, 2017

Done in 0.8.0!

@sghall sghall closed this as completed May 9, 2017
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

1 participant