Skip to content

show finish stepNumber #48

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

Closed
wants to merge 9 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ assets/**/*.css
build
lib
es
coverage
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ notifications:
- [email protected]

node_js:
- node
- 10

before_install:
- |
Expand Down
6 changes: 5 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# History
----

## 3.230
## 3.4.0

- Support `onChange` event.

## 3.3.0

- Add `icons` prop for change preset icon.

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ online example: http://react-component.github.io/steps/examples/
<td></td>
<td>spicify the default finish icon and error icon</td>
</tr>
<tr>
<td>onChange</td>
<td>(current: number) => void</td>
<td></td>
<td>Trigger when Step changed</td>
</tr>
</tbody>
</table>

Expand Down
9 changes: 9 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
flex: 1;
overflow: hidden;

&[role='button'] {
cursor: pointer;
transition: all .3s;

&:hover {
opacity: 0.7;
}
}

&:last-child {
flex: none;
}
Expand Down
24 changes: 22 additions & 2 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import Steps, { Step } from 'rc-steps';
const container = document.getElementById('__react-content');
const description = '这里是多信息的描述啊描述啊描述啊描述啊哦耶哦耶哦耶哦耶哦耶哦耶哦耶哦耶哦耶哦耶哦耶哦耶';

const ControlSteps = () => {
const [current, setCurrent] = React.useState(0);
return (
<Steps
current={current}
onChange={(val) => {
console.log('Change:', val);
setCurrent(val);
}}
>
<Step title="已完成" />
<Step title="进行中" />
<Step title="待运行" description="Hello World!" />
<Step title="待运行" />
</Steps>
);
};

ReactDOM.render(
<div>
<Steps current={1}>
Expand All @@ -27,5 +45,7 @@ ReactDOM.render(
<Step title="待运行" description={description} />
<Step title="待运行" description={description} />
</Steps>
</div>
, container);
<ControlSteps />
</div>,
container,
);
11 changes: 11 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 2,
"name": "rc-steps",
"builds": [
{
"src": "package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
}
]
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-steps",
"version": "3.3.0",
"version": "3.4.1",
"description": "steps ui component for react",
"keywords": [
"react",
Expand Down Expand Up @@ -43,7 +43,8 @@
"lint:fix": "rc-tools run lint --fix",
"test": "jest",
"prepublish": "rc-tools run guard",
"coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls"
"coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"now-build": "npm run build"
},
"jest": {
"setupFiles": [
Expand All @@ -60,7 +61,7 @@
}
},
"devDependencies": {
"coveralls": "^2.11.15",
"coveralls": "^3.0.4",
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.0.1",
"enzyme-to-json": "^3.0.0",
Expand Down
28 changes: 26 additions & 2 deletions src/Step.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Step extends React.Component {
PropTypes.string,
]),
stepNumber: PropTypes.string,
stepIndex: PropTypes.number,
description: PropTypes.any,
title: PropTypes.any,
progressDot: PropTypes.oneOfType([
Expand All @@ -35,7 +36,20 @@ export default class Step extends React.Component {
finish: PropTypes.node,
error: PropTypes.node,
}),
onClick: PropTypes.func,
onStepClick: PropTypes.func,
};

onClick = (...args) => {
const { onClick, onStepClick, stepIndex } = this.props;

if (onClick) {
onClick(...args);
}

onStepClick(stepIndex);
};

renderIconNode() {
const {
prefixCls, progressDot, stepNumber, status, title, description, icon,
Expand Down Expand Up @@ -66,7 +80,7 @@ export default class Step extends React.Component {
} else if (icons && icons.error && status === 'error') {
iconNode = <span className={`${prefixCls}-icon`}>{icons.error}</span>;
} else if (icon || status === 'finish' || status === 'error') {
iconNode = <span className={iconClassName} />;
iconNode = <span className={iconClassName}>{stepNumber}</span>;
} else {
iconNode = <span className={`${prefixCls}-icon`}>{stepNumber}</span>;
}
Expand All @@ -79,7 +93,7 @@ export default class Step extends React.Component {
status = 'wait', iconPrefix, icon, wrapperStyle,
adjustMarginRight, stepNumber,
description, title, progressDot, tailContent,
icons,
icons, stepIndex, onStepClick, onClick,
...restProps,
} = this.props;

Expand All @@ -96,8 +110,18 @@ export default class Step extends React.Component {
if (adjustMarginRight) {
stepItemStyle.marginRight = adjustMarginRight;
}

const accessibilityProps = {};
if (onStepClick) {
accessibilityProps.role = 'button';
accessibilityProps.tabIndex = 0;
accessibilityProps.onClick = this.onClick;
}

return (
<div
onClick={onClick}
{...accessibilityProps}
{...restProps}
className={classString}
style={stepItemStyle}
Expand Down
14 changes: 13 additions & 1 deletion src/Steps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Steps extends Component {
finish: PropTypes.node,
error: PropTypes.node,
}),
onChange: PropTypes.func,
};
static defaultProps = {
prefixCls: 'rc-steps',
Expand Down Expand Up @@ -66,6 +67,14 @@ export default class Steps extends Component {
this.calcStepOffsetWidth.cancel();
}
}

onStepClick = (next) => {
const { onChange, current } = this.props;
if (onChange && current !== next) {
onChange(next);
}
};

calcStepOffsetWidth = () => {
if (isFlexSupported()) {
return;
Expand All @@ -92,7 +101,7 @@ export default class Steps extends Component {
const {
prefixCls, style = {}, className, children, direction,
labelPlacement, iconPrefix, status, size, current, progressDot, initial,
icons,
icons, onChange,
...restProps,
} = this.props;
const { lastStepOffsetWidth, flexSupported } = this.state;
Expand All @@ -103,6 +112,7 @@ export default class Steps extends Component {
[`${prefixCls}-${size}`]: size,
[`${prefixCls}-label-${adjustedlabelPlacement}`]: direction === 'horizontal',
[`${prefixCls}-dot`]: !!progressDot,
[`${prefixCls}-flex-not-supported`]: !flexSupported,
});

return (
Expand All @@ -115,11 +125,13 @@ export default class Steps extends Component {
const stepNumber = initial + index;
const childProps = {
stepNumber: `${stepNumber + 1}`,
stepIndex: stepNumber,
prefixCls,
iconPrefix,
wrapperStyle: style,
progressDot,
icons,
onStepClick: onChange && this.onStepClick,
...child.props,
};
if (!flexSupported && direction !== 'vertical' && index !== lastIndex) {
Expand Down
16 changes: 15 additions & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from 'enzyme';
import { mount, render } from 'enzyme';
import Steps, { Step } from '../src';

describe('Steps', () => {
Expand Down Expand Up @@ -166,4 +166,18 @@ describe('Steps', () => {
expect(wrapper).toMatchSnapshot();
});
});

it('onChange', () => {
const onChange = jest.fn();
const wrapper = mount(
<Steps onChange={onChange}>
<Step />
<Step />
<Step />
</Steps>
);

wrapper.find(Step).at(1).simulate('click');
expect(onChange).toBeCalledWith(1);
});
});