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

[StepConnector] Customize connector based on internal states #13023

Merged
merged 9 commits into from
Sep 29, 2018

Conversation

spirosikmd
Copy link
Contributor

@spirosikmd spirosikmd commented Sep 27, 2018

Closes #13010

This can be accomplished with the following example:

<Stepper
  connector={
    <StepConnector
      classes={{ lineActive: classes.lineActive, lineCompleted: classes.lineCompleted }}
    />
  }
>
{/* ... */}
</Stepper>

or with using createMuiTheme:

createMuiTheme({
  overrides: {
    MuiStepConnector: {
      completed: {
        '& span': {
          borderColor: indigo[500],
        },
      },
    },
  },
});

Before

screen shot 2018-09-27 at 21 36 21

After

screen shot 2018-09-27 at 21 35 13

@@ -38,10 +38,25 @@ export const styles = theme => ({
borderLeftWidth: 1,
minHeight: 24,
},
/* Styles applied to the line element if `active={true}`. */
lineActive: {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of moving the state variant to the root element so people can write advanced logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by root element? The div element on the StepConnector component? So basically move these

[classes.lineActive]: active,
[classes.lineCompleted]: completed,
[classes.lineDisabled]: disabled,

to className instead of the lineClassName? So they are applied to the root element?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what do you think about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that! However, the following doesn't work anymore

lineActive: {
  borderColor: theme.palette.secondary.main,
},
lineCompleted: {
  borderColor: theme.palette.primary.main,
},

<StepConnector
  classes={{ lineActive: classes.lineActive, lineCompleted: classes.lineCompleted }}
/>

because the div element doesn't have a borderColor. How can we apply a borderColor in this case with a class on the div element instead of the span element? How can we style the line with a class on the div element? Maybe I am missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, there is a way to accomplish that! I updated the PR!

@@ -87,6 +117,9 @@ StepConnector.propTypes = {
StepConnector.defaultProps = {
alternativeLabel: false,
orientation: 'horizontal',
active: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the default value if they are not documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, we don't need to define default values. The default value is undefined anyway so [classes.lineActive]: active will work as expected.

@@ -66,12 +66,21 @@ function Stepper(props) {
connector: connectorProp,
};

const connectorProps = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse a state object between the connetor and control element?

@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 Sep 27, 2018
@spirosikmd spirosikmd force-pushed the step-connector-customize branch from bd38e10 to f9862d3 Compare September 29, 2018 07:59
@oliviertassinari oliviertassinari self-assigned this Sep 29, 2018
@oliviertassinari oliviertassinari changed the title [StepConnector] Customize connector based on active, completed, and disabled states [StepConnector] Customize connector based on internal states Sep 29, 2018
@@ -64,6 +62,12 @@ Labels can be placed below the step icon by setting the `alternativeLabel` prope

{{"demo": "pages/demos/steppers/VerticalLinearStepper.js"}}

## Customized Stepper

The example also uses a customized `StepConnector` element that changes border color based on the `active` and `completed` state.
Copy link
Contributor Author

@spirosikmd spirosikmd Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text is a bit off now that we moved it to its own section. Maybe

This component uses a customized `StepConnector` element that changes border color based on the `active` and `completed` state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@oliviertassinari oliviertassinari merged commit 89f6c30 into mui:master Sep 29, 2018
@oliviertassinari
Copy link
Member

@spirosikmd Thank you!

@spirosikmd spirosikmd deleted the step-connector-customize branch September 29, 2018 10:21
marcelpanse pushed a commit to marcelpanse/material-ui that referenced this pull request Oct 2, 2018
* [StepConnector] Introduce active, completed, and disabled properties

The properties are used to render classNames for the line element of the
`StepConnector`.

* [Stepper] Pass active, completed, disabled props to connectors

* [StepConnector] Update api docs

* [Stepper] Use state object for control and connector

* [StepConnector] Remove default boolean state values

* [StepConnector] Apply state classes to root element

* let's merge

* Update steppers.md

* remove regressions
@eps1lon eps1lon mentioned this pull request Oct 8, 2018
2 tasks
@colespencer1453
Copy link

@oliviertassinari Would it be possible to include an error class here as well?

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.

3 participants