ant-design/components/steps/demo/step-next.md

57 lines
1.2 KiB
Markdown
Raw Normal View History

2016-03-31 09:40:55 +08:00
---
order: 3
title: 切换到下一步
---
2015-06-25 16:01:04 +08:00
2015-09-01 17:43:08 +08:00
随机生成 3~6 个步骤,初始随机进行到其中一个步骤。
2015-06-25 20:01:20 +08:00
2015-07-08 16:36:08 +08:00
````css
2015-09-16 16:28:57 +08:00
#components-steps-demo-step-next > div > div {
2015-07-08 16:36:08 +08:00
margin-bottom: 30px;
2015-06-25 18:12:42 +08:00
}
2015-07-08 16:36:08 +08:00
````
2015-06-25 16:01:04 +08:00
````jsx
import { Steps, Button } from 'antd';
const Step = Steps.Step;
const array = Array.apply(null, Array(Math.floor(Math.random() * 3) + 3));
const steps = array.map((item, i) => {
2015-09-16 16:28:57 +08:00
return {
title: `步骤${i + 1}`
2015-09-16 16:28:57 +08:00
};
});
2015-06-25 18:12:42 +08:00
const App = React.createClass({
2015-06-25 18:12:42 +08:00
getInitialState() {
return {
currentStep: Math.floor(Math.random() * steps.length)
};
2015-06-25 18:12:42 +08:00
},
2015-09-16 16:28:57 +08:00
next() {
let s = this.state.currentStep + 1;
2015-06-25 18:12:42 +08:00
if (s === steps.length) {
s = 0;
}
this.setState({
currentStep: s
});
},
render() {
const cs = this.state.currentStep;
2015-09-16 16:28:57 +08:00
return (
<div>
2016-04-06 16:16:46 +08:00
<div style={{ marginBottom: 24 }}>当前正在执行第 {cs + 1} 步</div>
2015-09-16 16:28:57 +08:00
<Steps current={cs}>
{steps.map((s, i) => <Step key={i} title={s.title} description={s.description} />)}
</Steps>
2016-04-06 16:16:46 +08:00
<div style={{ marginTop: 24 }}>
<Button onClick={this.next}>下一步</Button>
2015-09-16 16:28:57 +08:00
</div>
</div>
);
2015-06-25 18:12:42 +08:00
}
});
ReactDOM.render(<App />, mountNode);
2015-06-25 20:01:20 +08:00
````