Skip to content

Commit cfef508

Browse files
bousejinoliviertassinari
authored andcommitted
[Stepper] Merge StepPositionIcon in StepIcon (#12026)
* Merged StepIcon and StepPositionIcon * yarn docs:api * fix typescript
1 parent aa8ee1a commit cfef508

File tree

6 files changed

+25
-92
lines changed

6 files changed

+25
-92
lines changed

packages/material-ui/src/StepIcon/StepIcon.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface StepIconProps
99
icon: React.ReactNode;
1010
}
1111

12-
export type StepIconClasskey = 'root' | 'active' | 'completed' | 'error';
12+
export type StepIconClasskey = 'root' | 'text' | 'active' | 'completed' | 'error';
1313

1414
declare const StepIcon: React.ComponentType<StepIconProps>;
1515

packages/material-ui/src/StepIcon/StepIcon.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import classNames from 'classnames';
44
import CheckCircle from '../internal/svg-icons/CheckCircle';
55
import Warning from '../internal/svg-icons/Warning';
66
import withStyles from '../styles/withStyles';
7-
import StepPositionIcon from './StepPositionIcon';
7+
import SvgIcon from '../SvgIcon';
88

99
export const styles = theme => ({
1010
root: {
1111
display: 'block',
12+
color: theme.palette.text.disabled,
1213
'&$active': {
1314
color: theme.palette.primary.main,
1415
},
@@ -19,6 +20,11 @@ export const styles = theme => ({
1920
color: theme.palette.error.main,
2021
},
2122
},
23+
text: {
24+
fill: theme.palette.primary.contrastText,
25+
fontSize: theme.typography.caption.fontSize,
26+
fontFamily: theme.typography.fontFamily,
27+
},
2228
active: {},
2329
completed: {},
2430
error: {},
@@ -35,12 +41,16 @@ function StepIcon(props) {
3541
return <CheckCircle className={classNames(classes.root, classes.completed)} />;
3642
}
3743
return (
38-
<StepPositionIcon
44+
<SvgIcon
3945
className={classNames(classes.root, {
4046
[classes.active]: active,
4147
})}
42-
position={icon}
43-
/>
48+
>
49+
<circle cx="12" cy="12" r="12" />
50+
<text className={classes.text} x="12" y="16" textAnchor="middle">
51+
{icon}
52+
</text>
53+
</SvgIcon>
4454
);
4555
}
4656

packages/material-ui/src/StepIcon/StepIcon.test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { assert } from 'chai';
33
import CheckCircle from '../internal/svg-icons/CheckCircle';
44
import Warning from '../internal/svg-icons/Warning';
55
import { createShallow, createMount } from '../test-utils';
6-
import StepPositionIcon from './StepPositionIcon';
76
import StepIcon from './StepIcon';
7+
import SvgIcon from '../SvgIcon';
88

99
describe('<StepIcon />', () => {
1010
let shallow;
@@ -31,13 +31,14 @@ describe('<StepIcon />', () => {
3131
assert.strictEqual(warning.length, 1, 'should have an <Warning />');
3232
});
3333

34-
it('renders <StepPositionIcon> when not completed', () => {
35-
const wrapper = shallow(<StepIcon icon={1} active />);
36-
const checkCircle = wrapper.find(StepPositionIcon);
37-
assert.strictEqual(checkCircle.length, 1, 'should have an <StepPositionIcon />');
38-
const props = checkCircle.props();
39-
assert.strictEqual(props.position, 1, 'should set position');
40-
assert.include(props.className, 'active');
34+
it('renders a <SvgIcon>', () => {
35+
const wrapper = shallow(<StepIcon icon={1} />);
36+
assert.strictEqual(wrapper.find(SvgIcon).length, 1);
37+
});
38+
39+
it('contains text "3" when position is "3"', () => {
40+
const wrapper = shallow(<StepIcon icon={3} />);
41+
assert.strictEqual(wrapper.find('text').text(), '3');
4142
});
4243

4344
it('renders the custom icon', () => {

packages/material-ui/src/StepIcon/StepPositionIcon.js

-50
This file was deleted.

packages/material-ui/src/StepIcon/StepPositionIcon.test.js

-29
This file was deleted.

pages/api/step-icon.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Any other properties supplied will be spread to the root element (native element
2828
You can override all the class names injected by Material-UI thanks to the `classes` property.
2929
This property accepts the following keys:
3030
- `root`
31+
- `text`
3132
- `active`
3233
- `completed`
3334
- `error`

0 commit comments

Comments
 (0)