diff --git a/components/input-number/demo/index.vue b/components/input-number/demo/index.vue index 8f5ff5519..373c4587f 100644 --- a/components/input-number/demo/index.vue +++ b/components/input-number/demo/index.vue @@ -13,7 +13,7 @@ const md = { ## 何时使用 当需要获取标准数值时。 ## 代码演示`, - us: `# Data Entry + us: `# InputNumber Enter a number within certain range with the mouse or keyboard. ## When To Use When a numeric value needs to be provided. diff --git a/components/transfer/demo/basic.md b/components/transfer/demo/basic.md index dd6cabf2b..f85f18d12 100644 --- a/components/transfer/demo/basic.md +++ b/components/transfer/demo/basic.md @@ -1,6 +1,6 @@ #### 基本用法 -最基本的用法,展示了 `dataSource`、`targetKeys`、每行的渲染函数 `render` 以及回调函数 `onChange` `onSelectChange` `onScroll` 的用法。 +最基本的用法,展示了 `dataSource`、`targetKeys`、每行的渲染函数 `render` 以及回调函数 `change` `selectChange` `scroll` 的用法。 @@ -41,7 +41,7 @@ export default { return { mockData, targetKeys, - selectedKeys: [], + selectedKeys: ['1', '4'], } }, methods: { diff --git a/components/transfer/index.en-US.md b/components/transfer/index.en-US.md index 43788fc1f..384026974 100644 --- a/components/transfer/index.en-US.md +++ b/components/transfer/index.en-US.md @@ -1,48 +1,36 @@ ---- -category: Components -type: Data Entry -cols: 1 -title: Transfer ---- - -Double column transfer choice box. - -## When To Use - -Transfer the elements between two columns in an intuitive and efficient way. - -One or more elements can be selected from either column, one click on the proper 'direction' button, and the transfer is done. The left column is considered the 'source' and the right column is considered the 'target'. As you can see in the API description, these names are reflected in. - ## API | Property | Description | Type | Default | | -------- | ----------- | ---- | ------- | -| className | A custom CSS class. | string | ['', ''] | -| dataSource | Used for setting the source data. The elements that are part of this array will be present the left column. Except the elements whose keys are included in `targetKeys` prop. | [TransferItem](https://git.io/vMM64)\[] | \[] | +| dataSource | Used for setting the source data. The elements that are part of this array will be present the left column. Except the elements whose keys are included in `targetKeys` prop. | \[{key: string.isRequired,title: string.isRequired,description: string,disabled: bool}\] | \[] | | filterOption | A function to determine whether an item should show in search result list | (inputValue, option): boolean | | -| footer | A function used for rendering the footer. | (props): ReactNode | | -| lazy | property of [react-lazy-load](https://github.com/loktar00/react-lazy-load) for lazy rendering items. Turn off it by set to `false`. | object\|boolean | `{ height: 32, offset: 32 }` | +| footer | customize the progress dot by setting a scoped slot | slot="footer" slot-scope="props" | | +| lazy | property of vc-lazy-load for lazy rendering items. Turn off it by set to `false`. | object\|boolean | `{ height: 32, offset: 32 }` | | listStyle | A custom CSS style used for rendering the transfer columns. | object | | -| notFoundContent | Text to display when a column is empty. | string\|ReactNode | 'The list is empty' | +| notFoundContent | Text to display when a column is empty. | string\|slot | 'The list is empty' | | operations | A set of operations that are sorted from bottom to top. | string\[] | ['>', '<'] | -| render | The function to generate the item shown on a column. Based on an record (element of the dataSource array), this function should return a React element which is generated from that record. Also, it can return a plain object with `value` and `label`, `label` is a React element and `value` is for title | Function(record) | | +| render | The function to generate the item shown on a column. Based on an record (element of the dataSource array), this function should return a element which is generated from that record. Also, it can return a plain object with `value` and `label`, `label` is a element and `value` is for title | Function(record) | | | searchPlaceholder | The hint text of the search box. | string | 'Search here' | | selectedKeys | A set of keys of selected items. | string\[] | \[] | | showSearch | If included, a search box is shown on each column. | boolean | false | | targetKeys | A set of keys of elements that are listed on the right column. | string\[] | \[] | | titles | A set of titles that are sorted from left to right. | string\[] | - | -| onChange | A callback function that is executed when the transfer between columns is complete. | (targetKeys, direction, moveKeys): void | | -| onScroll | A callback function which is executed when scroll options list | (direction, event): void | | -| onSearchChange | A callback function which is executed when search field are changed | (direction: 'left'\|'right', event: Event): void | - | -| onSelectChange | A callback function which is executed when selected items are changed. | (sourceSelectedKeys, targetSelectedKeys): void | | + +### events +| Events Name | Description | Arguments | +| --- | --- | --- | +| change | A callback function that is executed when the transfer between columns is complete. | (targetKeys, direction, moveKeys): void | | +| scroll | A callback function which is executed when scroll options list | (direction, event): void | | +| searchChange | A callback function which is executed when search field are changed | (direction: 'left'\|'right', event: Event): void | - | +| selectChange | A callback function which is executed when selected items are changed. | (sourceSelectedKeys, targetSelectedKeys): void | | ## Warning -According the [standard](http://facebook.github.io/react/docs/lists-and-keys.html#keys) of React, the key should always be supplied directly to the elements in the array. In Transfer, the keys should be set on the elements included in `dataSource` array. By default, `key` property is used as an unique identifier. +According the standard of Vue, the key should always be supplied directly to the elements in the array. In Transfer, the keys should be set on the elements included in `dataSource` array. By default, `key` property is used as an unique identifier. If there's no `key` in your data, you should use `rowKey` to specify the key that will be used for uniquely identify each element. ```jsx // eg. your primary key is `uid` -return record.uid} />; +return ; ``` diff --git a/components/transfer/index.jsx b/components/transfer/index.jsx index 4c255d2d3..e64e9f99b 100644 --- a/components/transfer/index.jsx +++ b/components/transfer/index.jsx @@ -13,12 +13,12 @@ import defaultLocale from '../locale-provider/default' export const TransferDirection = 'left' | 'right' -export const TransferItem = PropTypes.shape({ - key: PropTypes.string, - title: PropTypes.string, +export const TransferItem = { + key: PropTypes.string.isRequired, + title: PropTypes.string.isRequired, description: PropTypes.string, disabled: PropTypes.bool, -}).loose +} export const TransferProps = { prefixCls: PropTypes.string, @@ -27,8 +27,8 @@ export const TransferProps = { selectedKeys: PropTypes.arrayOf(PropTypes.string), render: PropTypes.func, listStyle: PropTypes.object, - titles: PropTypes.arrayOf(TransferItem), - operations: PropTypes.arrayOf(TransferItem), + titles: PropTypes.arrayOf(PropTypes.string), + operations: PropTypes.arrayOf(PropTypes.string), showSearch: PropTypes.bool, filterOption: PropTypes.func, searchPlaceholder: PropTypes.string, @@ -50,12 +50,13 @@ export const TransferLocale = { const tranferProps = { prefixCls: PropTypes.string, - dataSource: PropTypes.arrayOf(TransferItem), - targetKeys: PropTypes.array, + dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose), + targetKeys: PropTypes.arrayOf(PropTypes.string), + selectedKeys: PropTypes.arrayOf(PropTypes.string), listStyle: PropTypes.object, render: PropTypes.func, - titles: PropTypes.array, - operations: PropTypes.array, + titles: PropTypes.arrayOf(PropTypes.string), + operations: PropTypes.arrayOf(PropTypes.string), showSearch: PropTypes.bool, filterOption: PropTypes.func, searchPlaceholder: PropTypes.string, diff --git a/components/transfer/index.zh-CN.md b/components/transfer/index.zh-CN.md index 1687bc535..b2c821838 100644 --- a/components/transfer/index.zh-CN.md +++ b/components/transfer/index.zh-CN.md @@ -2,32 +2,35 @@ | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | -| className | 自定义类 | string | | -| dataSource | 数据源,其中的数据将会被渲染到左边一栏中,`targetKeys` 中指定的除外。 | [TransferItem](https://git.io/vMM64)\[] | \[] | +| dataSource | 数据源,其中的数据将会被渲染到左边一栏中,`targetKeys` 中指定的除外。 | \[{key: string.isRequired,title: string.isRequired,description: string,disabled: bool}\]\[] | \[] | | filterOption | 接收 `inputValue` `option` 两个参数,当 `option` 符合筛选条件时,应返回 `true`,反之则返回 `false`。 | (inputValue, option): boolean | | -| footer | 底部渲染函数 | (props): ReactNode | | -| lazy | Transfer 使用了 [react-lazy-load](https://github.com/loktar00/react-lazy-load) 优化性能,这里可以设置相关参数。设为 `false` 可以关闭懒加载。 | object\|boolean | `{ height: 32, offset: 32 }` | +| footer | 可以设置为一个 作用域插槽 | slot="footer" slot-scope="props" | | +| lazy | Transfer 使用了 [vc-lazy-load]优化性能,这里可以设置相关参数。设为 `false` 可以关闭懒加载。 | object\|boolean | `{ height: 32, offset: 32 }` | | listStyle | 两个穿梭框的自定义样式 | object | | -| notFoundContent | 当列表为空时显示的内容 | string\|ReactNode | '列表为空' | +| notFoundContent | 当列表为空时显示的内容 | string\|slot | '列表为空' | | operations | 操作文案集合,顺序从下至上 | string\[] | ['>', '<'] | -| render | 每行数据渲染函数,该函数的入参为 `dataSource` 中的项,返回值为 ReactElement。或者返回一个普通对象,其中 `label` 字段为 ReactElement,`value` 字段为 title | Function(record) | | +| render | 每行数据渲染函数,该函数的入参为 `dataSource` 中的项,返回值为 element。或者返回一个普通对象,其中 `label` 字段为 element,`value` 字段为 title | Function(record) | | | searchPlaceholder | 搜索框的默认值 | string | '请输入搜索内容' | | selectedKeys | 设置哪些项应该被选中 | string\[] | \[] | | showSearch | 是否显示搜索框 | boolean | false | | targetKeys | 显示在右侧框数据的key集合 | string\[] | \[] | | titles | 标题集合,顺序从左至右 | string\[] | ['', ''] | -| onChange | 选项在两栏之间转移时的回调函数 | (targetKeys, direction, moveKeys): void | | -| onScroll | 选项列表滚动时的回调函数 | (direction, event): void | | -| onSearchChange | 搜索框内容时改变时的回调函数 | (direction: 'left'\|'right', event: Event): void | - | -| onSelectChange | 选中项发生改变时的回调函数 | (sourceSelectedKeys, targetSelectedKeys): void | | + +### 事件 +| 事件名称 | 说明 | 回调参数 | +| --- | --- | --- | +| change | 选项在两栏之间转移时的回调函数 | (targetKeys, direction, moveKeys): void | | +| scroll | 选项列表滚动时的回调函数 | (direction, event): void | | +| searchChange | 搜索框内容时改变时的回调函数 | (direction: 'left'\|'right', event: Event): void | - | +| selectChange | 选中项发生改变时的回调函数 | (sourceSelectedKeys, targetSelectedKeys): void | | ## 注意 -按照 React 的[规范](http://facebook.github.io/react/docs/lists-and-keys.html#keys),所有的组件数组必须绑定 key。在 Transfer 中,`dataSource`里的数据值需要指定 `key` 值。对于 `dataSource` 默认将每列数据的 `key` 属性作为唯一的标识。 +按照Vue最新的规范,所有的组件数组最好绑定 key。在 Transfer 中,`dataSource`里的数据值需要指定 `key` 值。对于 `dataSource` 默认将每列数据的 `key` 属性作为唯一的标识。 如果你的数据没有这个属性,务必使用 `rowKey` 来指定数据列的主键。 ```jsx // 比如你的数据主键是 uid -return record.uid} />; +return ; ``` diff --git a/components/transfer/list.jsx b/components/transfer/list.jsx index 14943d2b3..785bd1e9c 100644 --- a/components/transfer/list.jsx +++ b/components/transfer/list.jsx @@ -9,14 +9,14 @@ import Search from './search' import Item from './item' import triggerEvent from '../_util/triggerEvent' -const TransferItem = PropTypes.shape({ - key: PropTypes.string, - title: PropTypes.string, +function noop () { +} + +const TransferItem = { + key: PropTypes.string.isRequired, + title: PropTypes.string.isRequired, description: PropTypes.string, disabled: PropTypes.bool, -}).loose - -function noop () { } function isRenderResultPlainObject (result) { @@ -27,8 +27,7 @@ function isRenderResultPlainObject (result) { export const TransferListProps = { prefixCls: PropTypes.string, titleText: PropTypes.string, - dataSource: PropTypes.arrayOf(TransferItem), - // dataSource: PropTypes.any, + dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose), filter: PropTypes.string, filterOption: PropTypes.func, checkedKeys: PropTypes.arrayOf(PropTypes.string), diff --git a/site/demo.js b/site/demo.js index c032ecb56..9b1bcf475 100644 --- a/site/demo.js +++ b/site/demo.js @@ -40,3 +40,4 @@ export { default as progress } from 'antd/progress/demo/index.vue' export { default as timeline } from 'antd/timeline/demo/index.vue' export { default as table } from 'antd/table/demo/index.vue' export { default as inputNumber } from 'antd/input-number/demo/index.vue' +export { default as transfer } from 'antd/transfer/demo/index.vue' diff --git a/site/routes.js b/site/routes.js index a5002d67d..9f0203788 100644 --- a/site/routes.js +++ b/site/routes.js @@ -2,7 +2,7 @@ import Demo from './components/demo.vue' const AsyncComp = () => { const d = window.location.hash.replace('#', '') return { - component: import(`../components/input-number/demo/${d}`), + component: import(`../components/transfer/demo/${d}`), } } export default [