From 8f732fc4216fca01923a290a38c3a1638f54c4c9 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 28 Feb 2020 16:04:37 +0800 Subject: [PATCH] feat: transfer support custom children --- build/config.js | 2 +- components/_util/getTransitionProps.js | 3 +- .../transfer/{item.jsx => ListItem.jsx} | 4 +- .../__tests__/__snapshots__/demo.test.js.snap | 281 +++++++++++++++-- .../__snapshots__/index.test.js.snap | 30 +- .../__tests__/__snapshots__/list.test.js.snap | 11 +- components/transfer/__tests__/search.test.js | 2 +- components/transfer/demo/index.vue | 12 +- components/transfer/demo/table-transfer.md | 155 ++++++++++ components/transfer/index.en-US.md | 82 ++++- components/transfer/index.jsx | 250 ++++++++------- components/transfer/index.zh-CN.md | 82 ++++- components/transfer/list.jsx | 290 +++++++++++------- components/transfer/renderListBody.jsx | 108 +++++++ components/transfer/style/index.less | 2 +- 15 files changed, 1021 insertions(+), 293 deletions(-) rename components/transfer/{item.jsx => ListItem.jsx} (94%) create mode 100644 components/transfer/demo/table-transfer.md create mode 100644 components/transfer/renderListBody.jsx diff --git a/build/config.js b/build/config.js index 0ccb888ad..a7b14a769 100644 --- a/build/config.js +++ b/build/config.js @@ -1,5 +1,5 @@ module.exports = { dev: { - componentName: 'tabs', // dev components + componentName: 'transfer', // dev components }, }; diff --git a/components/_util/getTransitionProps.js b/components/_util/getTransitionProps.js index 19d7a312a..623060c8d 100644 --- a/components/_util/getTransitionProps.js +++ b/components/_util/getTransitionProps.js @@ -1,7 +1,7 @@ import animate from './css-animation'; const noop = () => {}; const getTransitionProps = (transitionName, opt = {}) => { - const { beforeEnter, enter, afterEnter, leave, afterLeave, appear = true, tag } = opt; + const { beforeEnter, enter, afterEnter, leave, afterLeave, appear = true, tag, nativeOn } = opt; const transitionProps = { props: { appear, @@ -22,6 +22,7 @@ const getTransitionProps = (transitionName, opt = {}) => { }), afterLeave: afterLeave || noop, }, + nativeOn, }; // transition-group if (tag) { diff --git a/components/transfer/item.jsx b/components/transfer/ListItem.jsx similarity index 94% rename from components/transfer/item.jsx rename to components/transfer/ListItem.jsx index c76bd829a..90bf42173 100644 --- a/components/transfer/item.jsx +++ b/components/transfer/ListItem.jsx @@ -6,7 +6,7 @@ import Checkbox from '../checkbox'; function noop() {} export default { - name: 'Item', + name: 'ListItem', props: { renderedText: PropTypes.any, renderedEl: PropTypes.any, @@ -42,7 +42,7 @@ export default { } > - {renderedEl} + {renderedEl} ); let children = null; diff --git a/components/transfer/__tests__/__snapshots__/demo.test.js.snap b/components/transfer/__tests__/__snapshots__/demo.test.js.snap index 6e7642872..df2c17eef 100644 --- a/components/transfer/__tests__/__snapshots__/demo.test.js.snap +++ b/components/transfer/__tests__/__snapshots__/demo.test.js.snap @@ -8,7 +8,7 @@ exports[`renders ./components/transfer/demo/advanced.md correctly 1`] = `
- + @@ -59,7 +59,7 @@ exports[`renders ./components/transfer/demo/basic.md correctly 1`] = `
2/14 itemsSource
-
    +
    @@ -74,7 +74,7 @@ exports[`renders ./components/transfer/demo/basic.md correctly 1`] = `
    -
+
@@ -104,7 +104,7 @@ exports[`renders ./components/transfer/demo/custom-item.md correctly 1`] = `
20 items
-
    +
    @@ -125,7 +125,7 @@ exports[`renders ./components/transfer/demo/custom-item.md correctly 1`] = `
    -
+
-
-
No Data
+
+
+ + + + + + + +

No Data

@@ -2189,7 +2205,7 @@ exports[`renders ./components/transfer/demo/search.md correctly 1`] = `
-
    +
    @@ -2210,7 +2226,7 @@ exports[`renders ./components/transfer/demo/search.md correctly 1`] = `
    -
+
-
-
No Data
+
+
+ + + + + + + +

No Data

@@ -2234,3 +2258,224 @@ exports[`renders ./components/transfer/demo/search.md correctly 1`] = `
`; + +exports[`renders ./components/transfer/demo/table-transfer.md correctly 1`] = ` +
+
+
+
14 items
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
Name
+
+
Tag
+
+
Description
+
+ content1description of content1
+ content2description of content2
+ content4description of content4
+ content5description of content5
+ content7description of content7
+ content8description of content8
+ content10description of content10
+ content11description of content11
+ content13description of content13
+ content14description of content14
+
+
+
+ +
+
+
+
+
+
+
+
+
6 items
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
Name
+
+ content3
+ content6
+ content9
+ content12
+ content15
+ content18
+
+
+
+ +
+
+
+
+
+
+
+
+`; diff --git a/components/transfer/__tests__/__snapshots__/index.test.js.snap b/components/transfer/__tests__/__snapshots__/index.test.js.snap index 98bab0925..b32fec2be 100644 --- a/components/transfer/__tests__/__snapshots__/index.test.js.snap +++ b/components/transfer/__tests__/__snapshots__/index.test.js.snap @@ -4,9 +4,12 @@ exports[`Transfer should render correctly 1`] = `
1/2 items
-
  • -
  • -
    +
    +
      +
    • +
    • +
    +
    1 item
    -
  • +
    +
      +
    • +
    +
    `; @@ -24,7 +31,11 @@ exports[`Transfer should show sorted targetkey 1`] = `
    1 item
    -
  • a
  • +
    +
      +
    • a
    • +
    +
    2 items
    -
  • c
  • -
  • b
  • -
    +
    +
      +
    • c
    • +
    • b
    • +
    +
    `; diff --git a/components/transfer/__tests__/__snapshots__/list.test.js.snap b/components/transfer/__tests__/__snapshots__/list.test.js.snap index 4f5da4fa6..ffedae977 100644 --- a/components/transfer/__tests__/__snapshots__/list.test.js.snap +++ b/components/transfer/__tests__/__snapshots__/list.test.js.snap @@ -3,9 +3,12 @@ exports[`List should render correctly 1`] = `
    1/3
    -
  • -
  • -
  • -
    +
    +
      +
    • +
    • +
    • +
    +
    `; diff --git a/components/transfer/__tests__/search.test.js b/components/transfer/__tests__/search.test.js index 47309dd57..1512da2e8 100644 --- a/components/transfer/__tests__/search.test.js +++ b/components/transfer/__tests__/search.test.js @@ -108,7 +108,7 @@ describe('Search', () => { input.trigger('input'); expect(errorSpy.mock.calls[0][0]).toMatch( - 'Warning: `searchChange` in Transfer is deprecated. Please use `search` instead.', + 'Warning: [antdv: Transfer] `searchChange` in Transfer is deprecated. Please use `search` instead.', ); expect(onSearchChange.mock.calls[0][0]).toEqual('left'); expect(onSearchChange.mock.calls[0][1].target.value).toEqual('a'); diff --git a/components/transfer/demo/index.vue b/components/transfer/demo/index.vue index 22bda1441..4b3fda214 100644 --- a/components/transfer/demo/index.vue +++ b/components/transfer/demo/index.vue @@ -3,6 +3,7 @@ import Basic from './basic.md'; import Search from './search.md'; import Advanced from './advanced.md'; import CustomItem from './custom-item.md'; +import TableTransfer from './table-transfer'; import CN from '../index.zh-CN.md'; import US from '../index.en-US.md'; @@ -44,10 +45,13 @@ export default { return (
    - - - - + + + + + + +