From e23265c74cf62650fe6a21258b1d916b03866502 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Tue, 25 Dec 2018 12:00:39 +0800 Subject: [PATCH] Refactor tree select (#335) * refactor: tree-select --- components/_util/BaseMixin.js | 7 +- .../__tests__/__snapshots__/demo.test.js.snap | 24 +- components/tree-select/demo/basic.md | 5 +- components/tree-select/demo/checkable.md | 15 +- components/tree-select/demo/index.vue | 2 + components/tree-select/demo/multiple.md | 6 +- components/tree-select/demo/suffix.md | 54 + components/tree-select/demo/treeData.md | 13 +- components/tree-select/index.en-US.md | 5 +- components/tree-select/index.jsx | 2 + components/tree-select/index.zh-CN.md | 11 +- components/tree-select/interface.jsx | 33 +- components/tree/Tree.jsx | 4 +- components/vc-select/Select.jsx | 10 +- components/vc-tree-select/assets/select.less | 64 +- components/vc-tree-select/assets/tree.less | 2 +- components/vc-tree-select/demo/basic.jsx | 155 +- ...ta-generator.jsx => big-data-generator.js} | 0 .../demo/{big-data.jsx => big-data.js} | 2 + components/vc-tree-select/demo/controlled.jsx | 68 + .../vc-tree-select/demo/custom-icons.jsx | 113 + components/vc-tree-select/demo/demo.less | 3 +- .../demo/{disable.jsx => disable.js} | 23 +- .../demo/{dynamic.jsx => dynamic.js} | 37 +- .../demo/{filter.jsx => filter.js} | 2 + components/vc-tree-select/demo/form.js | 3 +- components/vc-tree-select/demo/util.js | 6 +- components/vc-tree-select/index.js | 5 +- .../vc-tree-select/src/Base/BasePopup.jsx | 284 +++ .../vc-tree-select/src/Base/BaseSelector.jsx | 187 ++ .../src/Popup/MultiplePopup.jsx | 3 + .../vc-tree-select/src/Popup/SinglePopup.jsx | 80 + components/vc-tree-select/src/PropTypes.js | 102 +- components/vc-tree-select/src/SearchInput.jsx | 127 ++ components/vc-tree-select/src/Select.jsx | 1906 +++++++++-------- components/vc-tree-select/src/SelectNode.jsx | 28 + .../vc-tree-select/src/SelectTrigger.jsx | 374 +--- .../Selector/MultipleSelector/Selection.jsx | 64 + .../src/Selector/MultipleSelector/index.jsx | 192 ++ .../src/Selector/SingleSelector.jsx | 75 + components/vc-tree-select/src/TreeNode.jsx | 12 - components/vc-tree-select/src/index.js | 31 +- components/vc-tree-select/src/propTypes.js | 46 + components/vc-tree-select/src/util.js | 865 ++++---- components/vc-tree/src/Tree.jsx | 12 +- components/vc-tree/src/TreeNode.jsx | 3 + components/vc-trigger/Popup.jsx | 4 +- 47 files changed, 3018 insertions(+), 2051 deletions(-) create mode 100644 components/tree-select/demo/suffix.md rename components/vc-tree-select/demo/{big-data-generator.jsx => big-data-generator.js} (100%) rename components/vc-tree-select/demo/{big-data.jsx => big-data.js} (96%) create mode 100644 components/vc-tree-select/demo/controlled.jsx create mode 100644 components/vc-tree-select/demo/custom-icons.jsx rename components/vc-tree-select/demo/{disable.jsx => disable.js} (80%) rename components/vc-tree-select/demo/{dynamic.jsx => dynamic.js} (59%) rename components/vc-tree-select/demo/{filter.jsx => filter.js} (97%) create mode 100644 components/vc-tree-select/src/Base/BasePopup.jsx create mode 100644 components/vc-tree-select/src/Base/BaseSelector.jsx create mode 100644 components/vc-tree-select/src/Popup/MultiplePopup.jsx create mode 100644 components/vc-tree-select/src/Popup/SinglePopup.jsx create mode 100644 components/vc-tree-select/src/SearchInput.jsx create mode 100644 components/vc-tree-select/src/SelectNode.jsx create mode 100644 components/vc-tree-select/src/Selector/MultipleSelector/Selection.jsx create mode 100644 components/vc-tree-select/src/Selector/MultipleSelector/index.jsx create mode 100644 components/vc-tree-select/src/Selector/SingleSelector.jsx delete mode 100644 components/vc-tree-select/src/TreeNode.jsx create mode 100644 components/vc-tree-select/src/propTypes.js diff --git a/components/_util/BaseMixin.js b/components/_util/BaseMixin.js index cdbd3fd87..1897d3cfe 100644 --- a/components/_util/BaseMixin.js +++ b/components/_util/BaseMixin.js @@ -1,4 +1,3 @@ -import { getOptionProps } from './props-util' export default { directives: { @@ -17,9 +16,9 @@ export default { methods: { setState (state, callback) { const newState = typeof state === 'function' ? state(this.$data) : state - if (this.getDerivedStateFromProps) { - Object.assign(newState, this.getDerivedStateFromProps(getOptionProps(this), this.$data, true) || {}) - } + // if (this.getDerivedStateFromProps) { + // Object.assign(newState, this.getDerivedStateFromProps(getOptionProps(this), { ...this.$data, ...newState }, true) || {}) + // } Object.assign(this.$data, newState) this.$nextTick(() => { callback && callback() diff --git a/components/tree-select/__tests__/__snapshots__/demo.test.js.snap b/components/tree-select/__tests__/__snapshots__/demo.test.js.snap index 1d75453ce..42922c124 100644 --- a/components/tree-select/__tests__/__snapshots__/demo.test.js.snap +++ b/components/tree-select/__tests__/__snapshots__/demo.test.js.snap @@ -1,25 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders ./components/tree-select/demo/basic.md correctly 1`] = ` -Please select -`; +exports[`renders ./components/tree-select/demo/basic.md correctly 1`] = `Please select`; exports[`renders ./components/tree-select/demo/checkable.md correctly 1`] = ` -
  • Node1
  • - -
    -
    +
    + +
    +
    `; exports[`renders ./components/tree-select/demo/multiple.md correctly 1`] = ` -
    +
    Please select
    `; -exports[`renders ./components/tree-select/demo/treeData.md correctly 1`] = ` -Please select -`; +exports[`renders ./components/tree-select/demo/suffix.md correctly 1`] = `Please select`; + +exports[`renders ./components/tree-select/demo/treeData.md correctly 1`] = `Please select`; diff --git a/components/tree-select/demo/basic.md b/components/tree-select/demo/basic.md index 735280343..39cdbfece 100644 --- a/components/tree-select/demo/basic.md +++ b/components/tree-select/demo/basic.md @@ -22,7 +22,7 @@ The most basic usage. > - + @@ -39,12 +39,13 @@ The most basic usage. export default { data () { return { + treeExpandedKeys: [], value: undefined, } }, methods: { onChange (value) { - console.log(arguments) + console.log(value) this.value = value }, }, diff --git a/components/tree-select/demo/checkable.md b/components/tree-select/demo/checkable.md index 9abca3780..49be73220 100644 --- a/components/tree-select/demo/checkable.md +++ b/components/tree-select/demo/checkable.md @@ -18,7 +18,6 @@ Multiple and checkable. treeCheckable :showCheckedStrategy="SHOW_PARENT" searchPlaceholder='Please select' - treeNodeFilterProp='label' /> @@ -27,29 +26,29 @@ import { TreeSelect } from 'ant-design-vue' const SHOW_PARENT = TreeSelect.SHOW_PARENT const treeData = [{ - label: 'Node1', + title: 'Node1', value: '0-0', key: '0-0', children: [{ - label: 'Child Node1', + title: 'Child Node1', value: '0-0-0', key: '0-0-0', }], }, { - label: 'Node2', + title: 'Node2', value: '0-1', key: '0-1', children: [{ - label: 'Child Node3', + title: 'Child Node3', value: '0-1-0', key: '0-1-0', disabled: true, }, { - label: 'Child Node4', + title: 'Child Node4', value: '0-1-1', key: '0-1-1', }, { - label: 'Child Node5', + title: 'Child Node5', value: '0-1-2', key: '0-1-2', }], @@ -64,7 +63,7 @@ export default { }, methods: { onChange (value) { - console.log('onChange ', value, arguments) + console.log('onChange ', value) this.value = value }, }, diff --git a/components/tree-select/demo/index.vue b/components/tree-select/demo/index.vue index a0e0f736d..7a74cb360 100644 --- a/components/tree-select/demo/index.vue +++ b/components/tree-select/demo/index.vue @@ -3,6 +3,7 @@ import Basic from './basic' import Checkable from './checkable' import Multiple from './multiple' import TreeData from './treeData' +import Suffix from './suffix' import CN from '../index.zh-CN.md' import US from '../index.en-US.md' @@ -35,6 +36,7 @@ export default { +