From ba6a032a3325c3d34140ef1f75c3f807aa1b08c2 Mon Sep 17 00:00:00 2001 From: solarjoker Date: Sun, 29 Sep 2019 10:53:38 +0800 Subject: [PATCH 1/6] fix: fix #695 --- components/carousel/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/carousel/index.js b/components/carousel/index.js index c35fd31e5..c1c5a02b9 100644 --- a/components/carousel/index.js +++ b/components/carousel/index.js @@ -57,6 +57,9 @@ class Carousel extends Component { if (active >= this.props.children.length) { active = 0 } + if (active < 0) { + active = this.props.children.length + active + } this.setState({ active }) From 6ec6193134bbead485c233a6aa68f32076738782 Mon Sep 17 00:00:00 2001 From: solarjoker Date: Sun, 29 Sep 2019 11:54:32 +0800 Subject: [PATCH 2/6] fix: fix #703 --- components/pagination/Pagination.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/pagination/Pagination.js b/components/pagination/Pagination.js index c6baafdc4..6a1918ec7 100644 --- a/components/pagination/Pagination.js +++ b/components/pagination/Pagination.js @@ -134,7 +134,8 @@ class Pagination extends Component { clearable={false} style={{ width: 120 }} data={pageSizeOptions.map(n => ({ - id: n, + // 这里的类型判断是考虑对过去的兼容写法 + id: typeof n === 'object' ? n.value : n, title: `${n} ${i18nItem}/${i18nItemPerPage}` }))} value={pageSize} From c1308750a1e0c0d38c0325631988c674e9f6393d Mon Sep 17 00:00:00 2001 From: solarjoker Date: Mon, 30 Sep 2019 12:12:38 +0800 Subject: [PATCH 3/6] docs: update cascader options to data --- docs/demo/cascader/section-advanced.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/demo/cascader/section-advanced.jsx b/docs/demo/cascader/section-advanced.jsx index c174747ac..90b9c5167 100644 --- a/docs/demo/cascader/section-advanced.jsx +++ b/docs/demo/cascader/section-advanced.jsx @@ -74,7 +74,7 @@ class Demo extends React.Component { value: 'goodsId', children: 'subGoods', }} - options={this.state.options} + data={this.state.options} style={{width: '240px'}} /> ) @@ -146,7 +146,7 @@ class Demo extends React.Component { onChange={(value)=>{ console.log('on change', value) }} - options={this.state.options} + data={this.state.options} style={{ width: 240 }} displayRender={values => { return values.join(' > ') @@ -265,7 +265,7 @@ class Demo extends React.Component { }} noFoundTip="未搜索到相关内容" searchable={true} - options={this.state.options} + data={this.state.options} style={{ width: 240 }} /> ) @@ -383,7 +383,7 @@ class Demo extends React.Component { onChange={(value)=>{ console.log('on change', value) }} - options={this.state.options} + data={this.state.options} style={{ width: 240 }} onActiveItemChange={values=>{ if(values[0] == 'mix') { From 673d81c99c9ba9a33d65a83dd509614a7f365f3f Mon Sep 17 00:00:00 2001 From: solarjoker Date: Mon, 30 Sep 2019 12:16:14 +0800 Subject: [PATCH 4/6] feat: cascader add filterOption --- components/cascader/Cascader.js | 10 ++++++---- docs/zh-CN/components/cascader.mdx | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/components/cascader/Cascader.js b/components/cascader/Cascader.js index bd3f8e482..f7e60d40d 100644 --- a/components/cascader/Cascader.js +++ b/components/cascader/Cascader.js @@ -25,7 +25,8 @@ class Cascader extends Component { style: PropTypes.object, onActiveItemChange: PropTypes.func, onChange: PropTypes.func, - displayRender: PropTypes.func + displayRender: PropTypes.func, + filterOption: PropTypes.func } static defaultProps = { @@ -173,7 +174,8 @@ class Cascader extends Component { onKeywordChange () { const { - data + data, + filterOption: filterFunc } = this.props const { keyword @@ -194,7 +196,7 @@ class Cascader extends Component { let label = option[labelKey] const value = option[valueKey] const children = option[childrenKey] - if (label.toString().indexOf(keyword) > -1 || value.toString().indexOf(keyword) > -1) { + if ((filterFunc && filterFunc(keyword, option)) || label.toString().includes(keyword) || value.toString().includes(keyword)) { match.matchCount++ } match.options.push({ @@ -210,7 +212,7 @@ class Cascader extends Component { filterOptions.push(match.options.slice()) } } - if (label.toString().indexOf(keyword) > -1 || value.toString().indexOf(keyword) > -1) { + if ((filterFunc && filterFunc(keyword, option)) || label.toString().includes(keyword) || value.toString().includes(keyword)) { match.matchCount-- } match.options.pop() diff --git a/docs/zh-CN/components/cascader.mdx b/docs/zh-CN/components/cascader.mdx index 1542be669..9b71d6a2f 100644 --- a/docs/zh-CN/components/cascader.mdx +++ b/docs/zh-CN/components/cascader.mdx @@ -28,20 +28,21 @@ import { Badge } from '@libs' ## Props -| 参数 | 说明 | 类型 | 可选值 | 默认值 | -| -------------- | ------------------------------------------------- | --------------------------- | ------------- | ------------------------------------------------------- | -| fieldNames | 设置 options 中 label, value, children 对应的 key | object | - | { label: 'label', value: 'value', children: 'children'} | -| data | 设置选择项数据源 | DataItem[] | - | - | -| value | 设置当前选中值 | string[] | - | [] | -| searchable | 是否可搜索 | boolean | true \| false | false | -| clearable | 是否可清空 | boolean | true \| false | true | -| disabled | 是否禁止使用 | boolean | true \| false | false | -| changeOnSelect | 是否启用选择即改变功能 | boolean | true \| false | false | -| placeholder | 输入框占位 | string | - | '请选择' | -| emptyContent | 设置选项为空时展示的内容 | string \| ReactNode | - | '无匹配数据' | -| displayRender | 自定义选择后展示的内容 | (value: string[]) => string | - | - | -| style | 自定义样式 | object | - | - | -| onChange | 选择后的回调 | (value: string[]) => void | - | - | +| 参数 | 说明 | 类型 | 可选值 | 默认值 | +| -------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ------------- | ------------------------------------------------------- | +| fieldNames | 设置 options 中 label, value, children 对应的 key | object | - | { label: 'label', value: 'value', children: 'children'} | +| data | 设置选择项数据源 | DataItem[] | - | - | +| value | 设置当前选中值 | string[] | - | [] | +| searchable | 是否可搜索 | boolean | true \| false | false | +| filterOption | 第一个参数为输入的关键字,第二个为数据项,返回值为 true 时将出现在结果项。仅在 searchable 为 true 时有效 | (keyword: string, item: DataItem) => boolean | - | - | +| clearable | 是否可清空 | boolean | true \| false | true | +| disabled | 是否禁止使用 | boolean | true \| false | false | +| changeOnSelect | 是否启用选择即改变功能 | boolean | true \| false | false | +| placeholder | 输入框占位 | string | - | '请选择' | +| emptyContent | 设置选项为空时展示的内容 | string \| ReactNode | - | '无匹配数据' | +| displayRender | 自定义选择后展示的内容 | (value: string[]) => string | - | - | +| style | 自定义样式 | object | - | - | +| onChange | 选择后的回调 | (value: string[]) => void | - | - | ## Type From 0ebf46c5a370a607a6ec2081e9a4d093ad164452 Mon Sep 17 00:00:00 2001 From: solarjoker Date: Wed, 9 Oct 2019 19:56:54 +0800 Subject: [PATCH 5/6] fix: fix #667 --- components/cascader/Cascader.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/cascader/Cascader.js b/components/cascader/Cascader.js index f7e60d40d..f23bb7015 100644 --- a/components/cascader/Cascader.js +++ b/components/cascader/Cascader.js @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom' import classNames from 'classnames' import PropTypes from 'prop-types' import debounce from 'lodash/debounce' +import isEqual from 'lodash/isEqual' import shallowequal from 'shallowequal' import Popper from '../popper' import Menu from './Menu' @@ -66,8 +67,8 @@ class Cascader extends Component { } componentWillReceiveProps (nextProps) { - if (!shallowequal(nextProps.value, this.props.value)) { - const cascaderLabel = this.getCascaderLabel(nextProps.value) + if (!shallowequal(nextProps.value, this.props.value) || !isEqual(nextProps.data, this.props.data)) { + const cascaderLabel = this.getCascaderLabel(nextProps.value, nextProps.data) this.setState({ cacheValue: nextProps.value, // 缓存原始value,用户可能点击option但是没选中,用于恢复初始value cascaderLabel @@ -109,7 +110,7 @@ class Cascader extends Component { this.inputRef.focus() } - getCascaderLabel (values) { + getCascaderLabel (values, data) { if (this.props.displayRender) { return this.props.displayRender(values) } @@ -118,7 +119,7 @@ class Cascader extends Component { } else { let labels = [] let index = 0 - let _options = this.props.data + let _options = data || this.props.data const labelKey = this.labelKey() const valueKey = this.valueKey() const childrenKey = this.childrenKey() From 9dd095c0d0da2239e1c8efa706dcca1e9ca16974 Mon Sep 17 00:00:00 2001 From: solarjoker Date: Thu, 10 Oct 2019 09:47:19 +0800 Subject: [PATCH 6/6] docs: update datepicker --- docs/zh-CN/components/date-picker.mdx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/zh-CN/components/date-picker.mdx b/docs/zh-CN/components/date-picker.mdx index c4a0c94ae..a57a06f71 100755 --- a/docs/zh-CN/components/date-picker.mdx +++ b/docs/zh-CN/components/date-picker.mdx @@ -91,16 +91,24 @@ import DemoModal from '../../demo/date-picker/section-modal.jsx' | 参数 | 说明 | 类型 | 可选值 | 默认值 | | ----------- | --------------------------------- | -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------ | | type | 选择器类型 | string | date 普通日期
daterange 日期范围
year 年份
month 月份
week 周
weekrange 周范围
timeperiod 时间段(1.5 新增) | date | -| value | 默认显示的日期 | Date \| string \| number\| object \| undefined \| null | -- | null | +| value | 默认显示的日期 | Date \| string \| number\| DateRange \| undefined \| null | - | null | | minDate | 最小日期 | Date | null | null | | maxDate | 最大日期 | Date | null | null | | disabled | 是否禁用输入框 | boolean | true \| false | false | | clearable | 是否可以清空 | boolean | true \| false | true | | showTime | 是否在日期选择器中显示时间选择器 | boolean | true \| false | false | | shortcuts | 快捷面板 | string[] | 近一周, 近一月, 近三月, 近一年 | null | -| weekOffset | 周起始
默认周日做为第一列 | number | 0/1 | 0 | +| weekOffset | 周起始
默认周日做为第一列 | number | 0 \| 1 | 0 | | placeholder | 自定义占位符
数组用于范围日期 | string \| string[] | - | - | + +## Type +### DateRange +| 参数 | 说明 | 类型 | 可选值 | 默认值 | +| -------- | --------------- | ---------------- | ------ | ------ | +| start | 起始时间 | Date \| string \| number \| undefined \| null | - | - | +| end | 截止时间 | Date \| string \| number \| undefined \| null | - | - | + ## Methods `DatePicker.format(date: Date, format: string)`