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] Allow StepIcon customization #11446

Merged
merged 3 commits into from
May 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/material-ui/src/StepLabel/StepLabel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { StandardProps } from '..';
import { Orientation } from '../Stepper';
import { StepButtonIcon } from '../StepButton';
import { StepIconProps } from '../StepIcon';

export interface StepLabelProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, StepLabelClasskey> {
Expand All @@ -15,6 +16,7 @@ export interface StepLabelProps
last?: boolean;
optional?: React.ReactNode;
orientation?: Orientation;
StepIconProps?: Partial<StepIconProps>;
}

export type StepLabelClasskey =
Expand Down
13 changes: 12 additions & 1 deletion packages/material-ui/src/StepLabel/StepLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function StepLabel(props) {
last,
optional,
orientation,
StepIconProps,
...other
} = props;

Expand All @@ -89,7 +90,13 @@ function StepLabel(props) {
[classes.alternativeLabel]: alternativeLabel,
})}
>
<StepIcon completed={completed} active={active} error={error} icon={icon} />
<StepIcon
completed={completed}
active={active}
error={error}
icon={icon}
{...StepIconProps}
/>
</span>
)}
<span className={classes.labelContainer}>
Expand Down Expand Up @@ -165,6 +172,10 @@ StepLabel.propTypes = {
* @ignore
*/
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
/**
* Properties applied to the `StepIcon` element.
*/
StepIconProps: PropTypes.object,
};

StepLabel.defaultProps = {
Expand Down
5 changes: 4 additions & 1 deletion packages/material-ui/src/StepLabel/StepLabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@ describe('<StepLabel />', () => {
});

it('renders <StepIcon>', () => {
const stepIconProps = { prop1: 'value1', prop2: 'value2' };
const wrapper = shallow(
<StepLabel icon={1} active completed alternativeLabel>
<StepLabel icon={1} active completed alternativeLabel StepIconProps={stepIconProps}>
Step One
</StepLabel>,
);
const stepIcon = wrapper.find(StepIcon);
assert.strictEqual(stepIcon.length, 1, 'should have an <StepIcon />');
const props = stepIcon.props();
assert.strictEqual(props.icon, 1, 'should set icon');
assert.strictEqual(props.prop1, 'value1', 'should have inherited custom prop1');
assert.strictEqual(props.prop2, 'value2', 'should have inherited custom prop2');
});
});

Expand Down
1 change: 1 addition & 0 deletions pages/api/step-label.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ filename: /packages/material-ui/src/StepLabel/StepLabel.js
| <span class="prop-name">error</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | Mark the step as failed. |
| <span class="prop-name">icon</span> | <span class="prop-type">node | | Override the default icon. |
| <span class="prop-name">optional</span> | <span class="prop-type">node | | The optional node to display. |
| <span class="prop-name">StepIconProps</span> | <span class="prop-type">object | | Properties applied to the `StepIcon` element. |

Any other properties supplied will be [spread to the root element](/guides/api#spread).

Expand Down