From b4216c778ec8a80bda19ee3c0f59970b89a91936 Mon Sep 17 00:00:00 2001 From: paranoidjk Date: Mon, 20 Mar 2017 13:24:46 +0800 Subject: [PATCH 01/10] feat: pagination current start from 1. close #1009 --- CHANGELOG.en-US.md | 20 ++++++++++++- CHANGELOG.zh-CN.md | 13 +++++++- .../__tests__/__snapshots__/demo.test.js.snap | 11 +++++-- .../__snapshots__/demo.test.web.js.snap | 6 ++-- .../__tests__/__snapshots__/demo.test.js.snap | 30 ++++++++++++------- .../__snapshots__/demo.test.web.js.snap | 22 +++++++------- .../__snapshots__/index.test.web.js.snap | 2 +- components/pagination/index.en-US.md | 5 ++-- components/pagination/index.tsx | 24 ++++++++------- components/pagination/index.web.tsx | 25 +++++++++------- components/pagination/index.zh-CN.md | 2 +- docs/react/upgrade-notes.en-US.md | 4 +++ docs/react/upgrade-notes.zh-CN.md | 4 +++ 13 files changed, 113 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 175e8f92c3..b8aaafed0a 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -14,6 +14,19 @@ timeline: true --- + +### 2.0.0 + +`2017-xx-xx` + +## New Feature + + +## Break Change + +- `pagination` 组件 `current` 属性改成从 `1` 开始索引 ([#1009](https://github.com/ant-design/ant-design-mobile/issues/1009)) + + ## 1.4.2 `2017-07-12` @@ -26,7 +39,6 @@ timeline: true - **Improve && Enhancement** - 升级 Slider 依赖的 rc-slider 版本。 - 部分组件文档国际化完善,增加部分组件测试用例。 - ## 1.4.1 @@ -48,6 +60,7 @@ timeline: true - 去除 object-assign 依赖,改为使用 es6 展开操作符 ([67e0ee6](https://github.com/ant-design/ant-design-mobile/commit/67e0ee6a985d1e143f3dbbf63988d01a05d67b59)) - 网站信息结构优化,并增加拷贝代码按钮 ([#1481](https://github.com/ant-design/ant-design-mobile/issues/1481)) + ## 1.4.0 `2017-06-24` @@ -222,6 +235,7 @@ timeline: true ## 1.0.8 + `2017-04-07` - **Feature** @@ -241,6 +255,7 @@ timeline: true ## 1.0.7 + `2017-03-24` - **Feature** @@ -260,8 +275,11 @@ timeline: true - DatePicker 确保默认日期在 `minDate`, `maxDate` 范围内 ([#1033](https://github.com/ant-design/ant-design-mobile/issues/1033)) +<<<<<<< HEAD ## 1.0.6 +======= +>>>>>>> feat: pagination current start from 1. close #1009 `2017-03-17` - **Feature** diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index e15778fba8..aea5c6eb0f 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -14,6 +14,17 @@ timeline: true --- +### 2.0.0 + +`2017-xx-xx` + +## New Feature + + +## Break Change + +- `pagination` 组件 `current` 属性改成从 `1` 开始索引 ([#1009](https://github.com/ant-design/ant-design-mobile/issues/1009)) + ## 1.4.2 `2017-07-12` @@ -26,7 +37,6 @@ timeline: true - **Improve && Enhancement** - 升级 Slider 依赖的 rc-slider 版本。 - 部分组件文档国际化完善,增加部分组件测试用例。 - ## 1.4.1 @@ -262,6 +272,7 @@ timeline: true ## 1.0.6 + `2017-03-17` - **Feature** diff --git a/components/locale-provider/__tests__/__snapshots__/demo.test.js.snap b/components/locale-provider/__tests__/__snapshots__/demo.test.js.snap index 229c1b6ca0..a5bdf0926f 100644 --- a/components/locale-provider/__tests__/__snapshots__/demo.test.js.snap +++ b/components/locale-provider/__tests__/__snapshots__/demo.test.js.snap @@ -189,7 +189,10 @@ exports[`renders ./components/locale-provider/demo/basic.tsx correctly 1`] = ` "backgroundColor": "#fff", "borderColor": "#ddd", }, - false, + Object { + "backgroundColor": "#ddd", + "borderColor": "#ddd", + }, false, false, undefined, @@ -218,7 +221,9 @@ exports[`renders ./components/locale-provider/demo/basic.tsx correctly 1`] = ` Object { "color": "#000", }, - false, + Object { + "color": "#bbb", + }, false, ] } @@ -274,7 +279,7 @@ exports[`renders ./components/locale-provider/demo/basic.tsx correctly 1`] = ` ] } > - 2 + 1 @@ -41,7 +41,7 @@ exports[`renders ./components/locale-provider/demo/basic.md correctly 1`] = ` - 2 + 1 / diff --git a/components/pagination/__tests__/__snapshots__/demo.test.js.snap b/components/pagination/__tests__/__snapshots__/demo.test.js.snap index ae1aaf2109..e99127fb66 100644 --- a/components/pagination/__tests__/__snapshots__/demo.test.js.snap +++ b/components/pagination/__tests__/__snapshots__/demo.test.js.snap @@ -118,7 +118,10 @@ exports[`renders ./components/pagination/demo/basic.tsx correctly 1`] = ` "backgroundColor": "#fff", "borderColor": "#ddd", }, - false, + Object { + "backgroundColor": "#ddd", + "borderColor": "#ddd", + }, false, false, undefined, @@ -147,7 +150,9 @@ exports[`renders ./components/pagination/demo/basic.tsx correctly 1`] = ` Object { "color": "#000", }, - false, + Object { + "color": "#bbb", + }, false, ] } @@ -203,7 +208,7 @@ exports[`renders ./components/pagination/demo/basic.tsx correctly 1`] = ` ] } > - 2 + 1 - 4 + 3 @@ -733,9 +745,7 @@ exports[`renders ./components/pagination/demo/basic.tsx correctly 1`] = ` "marginHorizontal": 2.5, "marginVertical": 3, }, - Object { - "backgroundColor": "#888", - }, + false, ] } /> diff --git a/components/pagination/__tests__/__snapshots__/demo.test.web.js.snap b/components/pagination/__tests__/__snapshots__/demo.test.web.js.snap index c319dd9e49..6d5e9275ac 100644 --- a/components/pagination/__tests__/__snapshots__/demo.test.web.js.snap +++ b/components/pagination/__tests__/__snapshots__/demo.test.web.js.snap @@ -19,8 +19,8 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = ` class="am-flexbox-item am-pagination-wrap-btn am-pagination-wrap-btn-prev" > @@ -35,7 +35,7 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = ` - 2 + 1 / @@ -72,8 +72,8 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = ` class="am-flexbox-item am-pagination-wrap-btn am-pagination-wrap-btn-prev" > - 2 + 1 / @@ -143,8 +143,8 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = ` class="am-flexbox-item am-pagination-wrap-btn am-pagination-wrap-btn-prev" > @@ -181,7 +181,7 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = ` - 4 + 3 / @@ -207,12 +207,12 @@ exports[`renders ./components/pagination/demo/basic.md correctly 1`] = `
diff --git a/components/pagination/__tests__/__snapshots__/index.test.web.js.snap b/components/pagination/__tests__/__snapshots__/index.test.web.js.snap index ec3057dafa..33979084ec 100644 --- a/components/pagination/__tests__/__snapshots__/index.test.web.js.snap +++ b/components/pagination/__tests__/__snapshots__/index.test.web.js.snap @@ -27,7 +27,7 @@ exports[`Pagination renders correctly 1`] = ` - 4 + 3 / diff --git a/components/pagination/index.en-US.md b/components/pagination/index.en-US.md index 78166aab25..9b5327b50f 100644 --- a/components/pagination/index.en-US.md +++ b/components/pagination/index.en-US.md @@ -17,9 +17,10 @@ Support WEB, React-Native. Properties | Descrition | Type | Default -----------|------------|------|-------- | mode | the mode of `Pagination` which can be one of `button`,`number`,`pointer` | string | `button` | -| current | current page index(Note: the index is counted from 0) | number | | -| total | total number of data | number | 0 | +| current | current page index | number | | +| total | total number of data | number | 1 | | simple | whether to hide number | boolean | false | | disabled | whether is disabled | boolean | false | | locale | [i18n](/components/locale-provider/) setting, you can override the configuration of the global `LocaleProvider | Object:{prevText, nextText} | | | onChange | invoked with the new index when the value changes. | (index: Number): void | | + diff --git a/components/pagination/index.tsx b/components/pagination/index.tsx index 49cdc2e745..08db92a4c8 100644 --- a/components/pagination/index.tsx +++ b/components/pagination/index.tsx @@ -11,7 +11,7 @@ import zh_CN from './locale/zh_CN'; export default class Pagination extends React.Component { static defaultProps = { mode: 'button', - current: 0, + current: 1, simple: false, onChange: () => {}, indicatorStyle: null, @@ -30,9 +30,11 @@ export default class Pagination extends React.Component { } componentWillReceiveProps(nextProps) { - this.setState({ - current: nextProps.current, - }); + if (nextProps.current !== this.state.current) { + this.setState({ + current: nextProps.current, + }); + } } onChange(p) { @@ -49,11 +51,11 @@ export default class Pagination extends React.Component { const locale = getComponentLocale(this.props, this.context, 'Pagination', () => zh_CN); const { prevText, nextText } = locale; - const current = this.state.current; + const { current } = this.state; const simpleItem = !simple ? ( - {current + 1} + {current} /{total} @@ -62,7 +64,7 @@ export default class Pagination extends React.Component { @@ -82,7 +84,7 @@ export default class Pagination extends React.Component { if (mode === 'number') { markup = ( - {current + 1} + {current} /{total} ); @@ -92,7 +94,7 @@ export default class Pagination extends React.Component { arr.push( , ); } diff --git a/components/pagination/index.web.tsx b/components/pagination/index.web.tsx index c60da44e0a..ac4d609d47 100644 --- a/components/pagination/index.web.tsx +++ b/components/pagination/index.web.tsx @@ -11,7 +11,7 @@ export default class Pagination extends React.Component { static defaultProps = { prefixCls: 'am-pagination', mode: 'button', - current: 0, + current: 1, simple: false, onChange: () => { }, }; @@ -28,9 +28,11 @@ export default class Pagination extends React.Component { } componentWillReceiveProps(nextProps) { - this.setState({ - current: nextProps.current, - }); + if (nextProps.current !== this.state.current) { + this.setState({ + current: nextProps.current, + }); + } } onChange(p) { @@ -44,23 +46,24 @@ export default class Pagination extends React.Component { render() { const { prefixCls, className, style, mode, total, simple } = this.props; - const current = this.state.current; + const { current } = this.state; const locale = getComponentLocale(this.props, this.context, 'Pagination', () => require('./locale/zh_CN')); const { prevText, nextText } = locale; let markup = ( - + {this.props.children ? ({this.props.children}) : (!simple && - {current + 1}/{total} - )} + {current}/{total} + ) + }