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

[Stepper] Expose connector index to <StepConnector /> #13079

Merged
merged 2 commits into from
Oct 2, 2018

Conversation

dannycochran
Copy link
Contributor

When defining the connector prop for a <Stepper />, it's helpful for that component to know about its index relative to the steps. For instance, if I want the connector between two completed steps to be green.

e.g.:

class CustomConnector extends React.Component {
  render() {
    const { completedSteps, index } = this.props;
    const classes = classNames({
      completed: completedSteps.includes(index) && completedSteps.includes(index - 1)
    });
    return <StepConnector classNames={classes} />;
  }
}

class MyStepper extends React.Component {
  render() {
    return <Stepper connector={<CustomConnector completedSteps={[0, 1, 2]}/>} />;
  }
}

This PR passes along the appropriate index of the connector to the <StepConnector /> to make this possible.

@oliviertassinari
Copy link
Member

@dannycochran The completed property is already provided. What do you need the index for?

@dannycochran
Copy link
Contributor Author

dannycochran commented Oct 2, 2018

@oliviertassinari I actually don't add the completed property to any of my steps, as I handle the completed styling differently than the default behavior.

Even still, there are other states that I may want to represent in the <StepConnector />, such as an error or warning state. If I have three steps, and the third one has an error, I'd extend the example I showed you above to look like this:

class CustomConnector extends React.Component {
  render() {
    const { completedSteps, failedSteps, index } = this.props;
    const classes = classNames({
      completed: completedSteps.includes(index) && completedSteps.includes(index - 1),
      error: failedSteps.includes(index)
    });
    return <StepConnector classNames={classes} />;
  }
}

class MyStepper extends React.Component {
  render() {
    return <Stepper connector={<CustomConnector completedSteps={[0, 1, 2]}/> failedSteps={[2]} />;
  }
}
```jsx

In addition to the use cases above, you could also imagine that `index` would be useful if you wanted to shorten the length of the connector depending on the index. It affords all the flexibility you need to render the `<StepConnector />` however you want. Currently, there's not enough information to do much with the `connector` property.

@oliviertassinari oliviertassinari added new feature New feature or request component: stepper This is the name of the generic UI component, not the React module! labels Oct 2, 2018
@oliviertassinari oliviertassinari changed the title expose connector index to <StepConnector /> [Stepper] Expose connector index to <StepConnector /> Oct 2, 2018
@oliviertassinari oliviertassinari merged commit a0cdfbf into mui:master Oct 2, 2018
@oliviertassinari
Copy link
Member

@dannycochran It's a great first pull request on Material-UI 👌🏻. Thank you for working on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: stepper This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants