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

[StepLabel] Introduce StepIconComponent property #13003

Merged
merged 6 commits into from
Sep 27, 2018

Conversation

semos
Copy link
Contributor

@semos semos commented Sep 25, 2018

Add a StepIconComponent prop in StepLabel to overwrite StepIcon standard behaviour with the provided component.

The component will be instantiated with the completed/active/error props.
Unit tests are OK.

fix #12987

@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 25, 2018
/**
* The React Element to render in place of the [`StepIcon`](/api/step-icon) element.
*/
StepIconComponent: PropTypes.oneOfType([
Copy link
Member

@eps1lon eps1lon Sep 25, 2018

Choose a reason for hiding this comment

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

You expect a component here? string, object or function are sufficient in that case.

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 thanks

icon={icon}
{...StepIconProps}
/>
) : (
<StepIcon
completed={completed}
active={active}
error={error}
icon={icon}
{...StepIconProps}
/>
Copy link
Member

Choose a reason for hiding this comment

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

The same props are applied to both paths. Why not just let StepIconComponent default to StepIcon?

Copy link
Member

Choose a reason for hiding this comment

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

Beat me to 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.

will do that

@eps1lon
Copy link
Member

eps1lon commented Sep 25, 2018

To fix CI run in the workspace root:

  • yarn docs:api
  • yarn prettier
    and commit changes.

@@ -78,6 +78,7 @@ function StepLabel(props) {
last,
optional,
orientation,
StepIconComponent = StepIcon,
StepIconProps,

This comment was marked as outdated.

@@ -96,13 +97,13 @@ function StepLabel(props) {
)}
{...other}
>
{icon && (
{(icon || StepIconComponent) && (
<span

This comment was marked as outdated.

@semos
Copy link
Contributor Author

semos commented Sep 26, 2018

@eps1lon Thanks for all the input.

I'm a bit uncomfortable with this proposal, as similar props of StepLabel are using nodes (icon, optional) and not components. I'm afraid this could cause confusion on how to use this new prop.

The simplest way to achieve the same behaviour would be to clone the icon to inject props in the StepIcon component, but that would introduce a slight behavioural change.

What's your opinion ?

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

The simplest way to achieve the same behaviour would be to clone the icon to inject props in the StepIcon component, but that would introduce a slight behavioural change.

The idea here is to provide a high level of flexibility. I think that using a component is a great to achieve it. A render property would be another way but requires a global design. We try to use cloneElement as few as possible, it's generally speaking an anti-pattern.

@@ -184,6 +185,10 @@ StepLabel.propTypes = {
* @ignore
*/
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
/**
* The React Element to render in place of the [`StepIcon`](/api/step-icon) element.
Copy link
Member

Choose a reason for hiding this comment

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

It's a component not an element

@oliviertassinari oliviertassinari changed the title Introduce StepIconComponent prop in StepLabel [StepLabel] Introduce StepIconComponent property Sep 26, 2018
semos and others added 6 commits September 27, 2018 09:00
Add StepIconComponent tests
propTypes validation
  - StepIconComponent can be a function/class or a ForwardRef
@oliviertassinari
Copy link
Member

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

@semos semos deleted the StepIcon branch September 27, 2018 08:08
marcelpanse pushed a commit to marcelpanse/material-ui that referenced this pull request Oct 2, 2018
* Add StepIconComponent prop to use customized icon

Add StepIconComponent tests
propTypes validation
  - StepIconComponent can be a function/class or a ForwardRef

* update api doc

* prettier

* update doc

* consolidation

* let's merge
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.

None yet

4 participants