From 18d80fff9f8c276700bcb4ea794566684f5cba29 Mon Sep 17 00:00:00 2001 From: yuanshen Date: Sun, 15 Jul 2018 12:34:33 +0800 Subject: [PATCH 1/2] feat: add starting number --- examples/start.html | 1 + examples/start.js | 24 ++++++ src/Steps.jsx | 6 +- tests/__snapshots__/index.test.js.snap | 115 +++++++++++++++++++++++++ tests/index.test.js | 5 ++ 5 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 examples/start.html create mode 100644 examples/start.js diff --git a/examples/start.html b/examples/start.html new file mode 100644 index 0000000..b3a4252 --- /dev/null +++ b/examples/start.html @@ -0,0 +1 @@ +placeholder \ No newline at end of file diff --git a/examples/start.js b/examples/start.js new file mode 100644 index 0000000..f74a473 --- /dev/null +++ b/examples/start.js @@ -0,0 +1,24 @@ +import 'rc-steps/assets/index.less'; +import 'rc-steps/assets/iconfont.less'; +import React from 'react'; +import ReactDOM from 'react-dom'; +import Steps, { Step } from 'rc-steps'; + +const container = document.getElementById('__react-content'); + +ReactDOM.render( +
+ + + + + + + + + + + + +
+, container); diff --git a/src/Steps.jsx b/src/Steps.jsx index 5682f5a..4a118b8 100644 --- a/src/Steps.jsx +++ b/src/Steps.jsx @@ -22,6 +22,7 @@ export default class Steps extends Component { ]), style: PropTypes.object, current: PropTypes.number, + start: PropTypes.number, }; static defaultProps = { prefixCls: 'rc-steps', @@ -32,6 +33,7 @@ export default class Steps extends Component { status: 'process', size: '', progressDot: false, + start: 1, }; constructor(props) { super(props); @@ -86,7 +88,7 @@ export default class Steps extends Component { const { prefixCls, style = {}, className, children, direction, labelPlacement, iconPrefix, status, size, current, progressDot, - ...restProps, + start, ...restProps, } = this.props; const { lastStepOffsetWidth, flexSupported } = this.state; const filteredChildren = React.Children.toArray(children).filter(c => !!c); @@ -106,7 +108,7 @@ export default class Steps extends Component { return null; } const childProps = { - stepNumber: `${index + 1}`, + stepNumber: `${start + index}`, prefixCls, iconPrefix, wrapperStyle: style, diff --git a/tests/__snapshots__/index.test.js.snap b/tests/__snapshots__/index.test.js.snap index 9ba3497..7ebe55d 100644 --- a/tests/__snapshots__/index.test.js.snap +++ b/tests/__snapshots__/index.test.js.snap @@ -1370,3 +1370,118 @@ exports[`Steps render renders with fasly children 1`] = ` `; + +exports[`Steps render renders step with specified starting number 1`] = ` +
+
+
+ +
+
+ + 4 + +
+
+
+ 已完成 +
+
+
+
+
+ +
+
+ + 5 + +
+
+
+ 进行中 +
+
+
+
+
+ +
+
+ + 6 + +
+
+
+ 待运行 +
+
+
+
+
+ +
+
+ + 7 + +
+
+
+ 待运行 +
+
+
+
+`; \ No newline at end of file diff --git a/tests/index.test.js b/tests/index.test.js index ea4083c..ca09ee2 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -98,5 +98,10 @@ describe('Steps', () => { ); expect(wrapper).toMatchSnapshot(); }); + + it('renders step with specified starting number', () => { + const wrapper = render(React.cloneElement(steps, { start: 4 })); + expect(wrapper).toMatchSnapshot(); + }); }); }); From 424067a582299ec6b07e01b0a57d7f31a1fff4e0 Mon Sep 17 00:00:00 2001 From: yuanshen Date: Sun, 15 Jul 2018 15:17:57 +0800 Subject: [PATCH 2/2] fix: new line at end of file --- examples/start.html | 2 +- tests/__snapshots__/index.test.js.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/start.html b/examples/start.html index b3a4252..48cdce8 100644 --- a/examples/start.html +++ b/examples/start.html @@ -1 +1 @@ -placeholder \ No newline at end of file +placeholder diff --git a/tests/__snapshots__/index.test.js.snap b/tests/__snapshots__/index.test.js.snap index 7ebe55d..731bacf 100644 --- a/tests/__snapshots__/index.test.js.snap +++ b/tests/__snapshots__/index.test.js.snap @@ -1484,4 +1484,4 @@ exports[`Steps render renders step with specified starting number 1`] = ` -`; \ No newline at end of file +`;