├── .editorconfig ├── .eslintrc.js ├── .fatherrc.js ├── .github ├── dependabot.yml └── workflows │ └── main.yml ├── .gitignore ├── .husky └── pre-commit ├── .nowignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── .umirc.ts ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── assets ├── icons.png ├── index.less ├── line.gif └── loading.gif ├── docs ├── changelog.md ├── demo │ ├── animation-draggable.md │ ├── animation.md │ ├── basic-controlled.md │ ├── basic.md │ ├── big-data.md │ ├── contextmenu.md │ ├── custom-switch-icon.md │ ├── draggable-allow-drop.md │ ├── draggable.md │ ├── dropdown.md │ ├── dynamic.md │ ├── expandAction.md │ ├── fieldNames.md │ ├── funtionTitle.md │ ├── icon.md │ └── selectable.md ├── examples │ ├── animation-draggable.jsx │ ├── animation.jsx │ ├── animation.less │ ├── basic-controlled.jsx │ ├── basic.jsx │ ├── basic.less │ ├── big-data-generator.js │ ├── big-data.jsx │ ├── contextmenu.jsx │ ├── contextmenu.less │ ├── custom-switch-icon.jsx │ ├── draggable-allow-drop.jsx │ ├── draggable.jsx │ ├── draggable.less │ ├── dropdown.jsx │ ├── dropdown.less │ ├── dynamic.jsx │ ├── expandAction.jsx │ ├── expandAction.less │ ├── fieldNames.tsx │ ├── funtionTitle.jsx │ ├── icon.jsx │ ├── icon.less │ ├── longData.json │ ├── selectable.jsx │ ├── selectable.less │ └── utils │ │ └── dataUtil.js └── index.md ├── index.js ├── jest.config.js ├── now.json ├── package.json ├── src ├── DropIndicator.tsx ├── Indent.tsx ├── MotionTreeNode.tsx ├── NodeList.tsx ├── Tree.tsx ├── TreeNode.tsx ├── contextTypes.ts ├── index.ts ├── interface.tsx ├── useUnmount.ts ├── util.tsx └── utils │ ├── conductUtil.ts │ ├── diffUtil.ts │ ├── keyUtil.ts │ └── treeUtil.ts ├── tests ├── Accessibility.spec.tsx ├── FieldNames.spec.tsx ├── MyTree.tsx ├── React18.spec.tsx ├── Tree.spec.tsx ├── TreeDraggable.spec.tsx ├── TreeMotion.spec.tsx ├── TreeNodeProps.spec.tsx ├── TreeProps.spec.tsx ├── TreeVirtual.spec.tsx ├── __mocks__ │ ├── rc-util │ │ └── lib │ │ │ └── raf.ts │ └── rc-virtual-list.tsx ├── __snapshots__ │ ├── Tree.spec.tsx.snap │ ├── TreeNodeProps.spec.tsx.snap │ └── TreeProps.spec.tsx.snap ├── expandAction.spec.tsx ├── setupFilesAfterEnv.js ├── type.spec.tsx ├── util.spec.js └── util.ts ├── tsconfig.json ├── typings.d.ts └── update-example.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*.{js,css}] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [require.resolve('@umijs/fabric/dist/eslint')], 3 | 4 | rules: { 5 | 'react/sort-comp': 0, 6 | 'default-case': 0, 7 | 'eslint-comments/disable-enable-pair': 0, 8 | 'react/require-default-props': 0, 9 | 'react/no-unused-prop-types': 1, 10 | 'react-hooks/exhaustive-deps': 0, 11 | 'jsx-a11y/label-has-for': 0, 12 | 'jsx-a11y/label-has-associated-control': 0, 13 | 'no-loop-func': 0, 14 | '@typescript-eslint/no-loop-func': 0, 15 | '@typescript-eslint/consistent-type-imports': 0, 16 | '@typescript-eslint/consistent-type-definitions': 0, 17 | 'max-classes-per-file': 0, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /.fatherrc.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'father'; 2 | 3 | export default defineConfig({ 4 | plugins: ['@rc-component/father-plugin'], 5 | }); 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "21:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: "@types/react" 11 | versions: 12 | - 17.0.0 13 | - 17.0.1 14 | - 17.0.2 15 | - 17.0.3 16 | - dependency-name: "@types/react-dom" 17 | versions: 18 | - 17.0.0 19 | - 17.0.1 20 | - 17.0.2 21 | - dependency-name: '@rc-component/np' 22 | versions: 23 | - 1.0.0 24 | - dependency-name: '@rc-component/tooltip' 25 | versions: 26 | - 1.0.0 27 | - dependency-name: less 28 | versions: 29 | - 4.1.0 -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: ✅ test 2 | on: [push, pull_request] 3 | jobs: 4 | test: 5 | uses: react-component/rc-test/.github/workflows/test.yml@main 6 | secrets: inherit 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .storybook 2 | .vscode 3 | *.iml 4 | *.log 5 | .doc/ 6 | .idea/ 7 | .ipr 8 | .iws 9 | *~ 10 | ~* 11 | *.diff 12 | *.patch 13 | *.bak 14 | .DS_Store 15 | Thumbs.db 16 | .project 17 | .*proj 18 | .svn/ 19 | coverage/ 20 | *.swp 21 | *.swo 22 | *.pyc 23 | *.pyo 24 | package-lock.json 25 | .build 26 | node_modules 27 | .cache 28 | dist 29 | *.css 30 | build 31 | lib 32 | /coverage 33 | yarn.lock 34 | es/ 35 | !tests/__mocks__/rc-util/lib 36 | # umi 37 | .umi 38 | .umi-production 39 | .umi-test 40 | .env.local 41 | 42 | .dumi/ -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | lint-staged -------------------------------------------------------------------------------- /.nowignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | node-options="--openssl-legacy-provider" -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .doc 2 | .storybook 3 | es 4 | lib 5 | **/*.svg 6 | **/*.ejs 7 | **/*.html 8 | package.json 9 | .umi 10 | .umi-production 11 | .umi-test 12 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "endOfLine": "lf", 3 | "semi": true, 4 | "singleQuote": true, 5 | "tabWidth": 2, 6 | "trailingComma": "all", 7 | "proseWrap": "never", 8 | "printWidth": 100, 9 | "arrowParens": "avoid" 10 | } 11 | -------------------------------------------------------------------------------- /.umirc.ts: -------------------------------------------------------------------------------- 1 | // more config: https://d.umijs.org/config 2 | import { defineConfig } from 'dumi'; 3 | 4 | export default defineConfig({ 5 | themeConfig: { 6 | name: 'Tree', 7 | }, 8 | }); 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | - https://github.com/react-component/tree/releases 4 | 5 | ## 3.2.0 `2020-05-08` 6 | 7 | - Upgrade `rc-animate`. 8 | - Remove `react-lifecycles-compat` and `prop-types`. 9 | 10 | ## 2.1.0 / 2019-04-28 11 | 12 | - TreeNode support `checkable`. 13 | 14 | ## 2.0.0 / 2019-04-26 15 | 16 | - Remove old animation api and use `motion` instead. 17 | 18 | ## 1.11.5 / 2018-04-19 19 | - add `onClick` & `onDoubleClick` for node click event 20 | - add related className in treeNode 21 | - fix drag into another tree will throw exception 22 | 23 | ## 1.10.0 / 2018-04-17 24 | - `onCheck` arguments provide nativeEvent 25 | - `onSelect` arguments provide nativeEvent 26 | - `onExpand` arguments provide nativeEvent 27 | 28 | ## 1.9.0 / 2018-04-09 29 | - adjust `dragable` logic to make drag more smooth 30 | - fix `loadData` trigger twice when expand node 31 | - add `icon` prop on `Tree` 32 | - fix check by prop not work on `disabled` node 33 | 34 | 35 | ## 1.8.0 / 2018-03-29 36 | - code refactor and optimize logic 37 | - add `disabled` API 38 | - add `icon` API 39 | 40 | ## 1.4.0 / 2016-10-24 41 | - add `onDragEnd` API and fix related issues. 42 | 43 | ## 1.3.0 / 2016-04-15 44 | - make `autoExpandParent` also work in controlled mode.(Before just work in uncontrolled mode) 45 | - change `onExpand` params 46 | - old: function(node, expanded, expandedKeys) 47 | - new: function(expandedKeys, {expanded: bool, node}) 48 | 49 | ## 1.2.1 / 2016-04-08 50 | - remove `halfCheckedKeys` api, and change `checkedKeys` to an object on setting `checkStrictly`. 51 | 52 | ## 1.2.0 / 2016-04-06 53 | - improve performance. 54 | - add `checkStrictly`/`halfCheckedKeys` api. 55 | 56 | ## 1.1.0 / 2016-01-25 57 | - change `onDrop` params (from `originExpandedKeys` to `rawExpandedKeys`) 58 | 59 | ## 1.0.x / 2016-01-15 60 | - change `onSelect`/`onCheck` params 61 | 62 | ## 0.26.x / 2016-01-13 63 | - change drag api (from `onTreeXX` to `onXX`) 64 | 65 | ## 0.23.x / 2015-12-31 66 | - change `onDataLoaded` api to `loadData` 67 | 68 | ## 0.22.x / 2015-12-30 69 | - add `expandedKeys`/`onExpand`/`filterTreeNode` api 70 | 71 | ## 0.21.x / 2015-12-25 72 | - add `onMouseEnter`/`onMouseLeave` api 73 | 74 | ## 0.20.0 / 2015-12-01 75 | - add draggable feature #5 76 | 77 | ## 0.18.0 / 2015-10-23 78 | - add contextmenu feature #5 79 | 80 | ## 0.17.0 / 2015-10-14 81 | - add dynamic feature #4 82 | 83 | ## 0.9.5 / 2015-05-26 84 | - support checkbox 85 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT LICENSE 2 | 3 | Copyright (c) 2015-present Alipay.com, https://www.alipay.com/ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rc-tree 2 | 3 | Tree component. 4 | 5 | [![NPM version][npm-image]][npm-url] 6 | [![npm download][download-image]][download-url] 7 | [![build status][github-actions-image]][github-actions-url] 8 | [![Codecov][codecov-image]][codecov-url] 9 | [![bundle size][bundlephobia-image]][bundlephobia-url] 10 | [![dumi][dumi-image]][dumi-url] 11 | 12 | [npm-image]: http://img.shields.io/npm/v/rc-tree.svg?style=flat-square 13 | [npm-url]: http://npmjs.org/package/rc-tree 14 | [github-actions-image]: https://github.com/react-component/tree/actions/workflows/main.yml/badge.svg 15 | [github-actions-url]: https://github.com/react-component/tree/actions/workflows/main.yml 16 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/tree/master.svg?style=flat-square 17 | [codecov-url]: https://codecov.io/gh/react-component/tree/ 18 | [david-url]: https://david-dm.org/react-component/tree 19 | [david-image]: https://david-dm.org/react-component/tree/status.svg?style=flat-square 20 | [david-dev-url]: https://david-dm.org/react-component/tree?type=dev 21 | [david-dev-image]: https://david-dm.org/react-component/tree/dev-status.svg?style=flat-square 22 | [download-image]: https://img.shields.io/npm/dm/rc-tree.svg?style=flat-square 23 | [download-url]: https://npmjs.org/package/rc-tree 24 | [bundlephobia-url]: https://bundlephobia.com/result?p=rc-tree 25 | [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-tree 26 | [dumi-url]: https://github.com/umijs/dumi 27 | [dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square 28 | 29 | ## Screenshots 30 | 31 | 32 | 33 | ## Feature 34 | 35 | - Support all popular browsers, including Internet Explorer 9 and above. 36 | 37 | ## Example 38 | 39 | http://localhost:9001/ 40 | 41 | online example: https://tree.react-component.now.sh/ 42 | 43 | ## Install 44 | 45 | [![rc-tree](https://nodei.co/npm/rc-tree.png)](https://npmjs.org/package/rc-tree) 46 | 47 | ## Usage 48 | > Note: `import "rc-tree/assets/index.css"` 49 | 50 | see examples 51 | 52 | ## API 53 | 54 | ### Tree props 55 | 56 | | name | description | type | default | 57 | | --- | --- | --- | --- | 58 | | autoExpandParent | whether auto expand parent treeNodes | bool | false | 59 | | checkable | whether support checked | bool/React Node | false | 60 | | checkedKeys | Controlled checked treeNodes(After setting, defaultCheckedKeys will not work). Note: parent and children nodes are associated, if the parent node's key exists, it all children node will be checked, and vice versa. When set checkable and checkStrictly, it should be an object, which contains checked array and halfChecked array. | String[]/{checked:Array,halfChecked:Array} | [] | 61 | | checkStrictly | check node precisely, parent and children nodes are not associated | bool | false | 62 | | className | additional css class of root dom node | String | '' | 63 | | defaultCheckedKeys | default checked treeNodes | String[] | [] | 64 | | defaultExpandedKeys | expand specific treeNodes | String[] | [] | 65 | | defaultExpandAll | expand all treeNodes | bool | false | 66 | | defaultExpandParent | auto expand parent treeNodes when init | bool | true | 67 | | defaultSelectedKeys | default selected treeNodes | String[] | [] | 68 | | disabled | whether disabled the tree | bool | false | 69 | | draggable | whether can drag treeNode. (drag events are not supported in Internet Explorer 8 and earlier versions or Safari 5.1 and earlier versions.) | bool \| ({ node }) => boolean | false | 70 | | expandedKeys | Controlled expand specific treeNodes | String[] | - | 71 | | filterTreeNode | filter some treeNodes as you need. it should return true | function(node) | - | 72 | | icon | customize icon. When you pass component, whose render will receive full TreeNode props as component props | element/Function(props) | - | 73 | | loadedKeys | Mark node is loaded when `loadData` is true | String[] | - | 74 | | loadData | load data asynchronously and the return value should be a promise | function(node) | - | 75 | | multiple | whether multiple select | bool | false | 76 | | prefixCls | prefix class | String | 'rc-tree' | 77 | | selectable | whether can be selected | bool | true | 78 | | selectedKeys | Controlled selected treeNodes(After setting, defaultSelectedKeys will not work) | String[] | [] | 79 | | showIcon | whether show icon | bool | true | 80 | | showLine | whether show line | bool | false | 81 | | treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | array<{key,title,children, [disabled, selectable]}> | - | 82 | | onCheck | click the treeNode/checkbox to fire | function(checkedKeys, e:{checked: bool, checkedNodes, node, event, nativeEvent}) | - | 83 | | onExpand | fire on treeNode expand or not | function(expandedKeys, {expanded: bool, node, nativeEvent}) | - | 84 | | onDragEnd | it execs when fire the tree's dragend event | function({event,node}) | - | 85 | | onDragEnter | it execs when fire the tree's dragenter event | function({event,node,expandedKeys}) | - | 86 | | onDragLeave | it execs when fire the tree's dragleave event | function({event,node}) | - | 87 | | onDragOver | it execs when fire the tree's dragover event | function({event,node}) | - | 88 | | onDragStart | it execs when fire the tree's dragstart event | function({event,node}) | - | 89 | | onDrop | it execs when fire the tree's drop event | function({event, node, dragNode, dragNodesKeys}) | - | 90 | | onLoad | Trigger when a node is loaded. If you set the `loadedKeys`, you must handle `onLoad` to avoid infinity loop | function(loadedKeys, {event, node}) | - | 91 | | onMouseEnter | call when mouse enter a treeNode | function({event,node}) | - | 92 | | onMouseLeave | call when mouse leave a treeNode | function({event,node}) | - | 93 | | onRightClick | select current treeNode and show customized contextmenu | function({event,node}) | - | 94 | | onSelect | click the treeNode to fire | function(selectedKeys, e:{selected: bool, selectedNodes, node, event, nativeEvent}) | - | 95 | | switcherIcon | specific the switcher icon. | ReactNode / (props: TreeNodeAttribute) => ReactNode | - | 96 | | virtual | Disable virtual scroll when `false` | boolean | - | 97 | | allowDrop | Whether to allow drop on node | ({ dragNode, dropNode, dropPosition }) => boolean | - | 98 | | dropIndicatorRender | The indicator to render when dragging | ({ dropPosition, dropLevelOffset, indent: number, prefixCls }) => ReactNode| - | 99 | | direction | Display direction of the tree, it may affect dragging behavior | `ltr` \| `rtl` | - | 100 | | expandAction | Tree open logic, optional: false \| `click` \| `doubleClick` | string \| boolean | `click` | 101 | 102 | ### TreeNode props 103 | 104 | > note: if you have a lot of TreeNode, like more than 1000, 105 | > make the parent node is collapsed by default, will obvious effect, very fast. 106 | > Because the children hide TreeNode will not insert into dom. 107 | 108 | | name | description | type | default | 109 | | --- | --- | --- | --- | 110 | | className | additional class to treeNode | String | '' | 111 | | checkable | control node checkable if Tree is checkable | bool | false | 112 | | style | set style to treeNode | Object | '' | 113 | | disabled | whether disabled the treeNode | bool | false | 114 | | disableCheckbox | whether disable the treeNode' checkbox | bool | false | 115 | | title | tree/subTree's title | String/element/((data: DataNode) => React.ReactNode) | '---' | 116 | | key | it's used with tree props's (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys. you'd better to set it, and it must be unique in the tree's all treeNodes | String | treeNode's position | 117 | | isLeaf | whether it's leaf node | bool | false | 118 | | icon | customize icon. When you pass component, whose render will receive full TreeNode props as component props | element/Function(props) | - | 119 | | switcherIcon | specific the switcher icon. | ReactNode / (props: TreeNodeAttribute) => ReactNode | - | 120 | 121 | ## Note 122 | 123 | The number of treeNodes can be very large, but when enable `checkable`, it will spend more computing time, so we cached some calculations(e.g. `this.treeNodesStates`), to avoid double computing. But, this bring some restrictions, **when you async load treeNodes, you should render tree like this** `{this.state.treeData.length ? {this.state.treeData.map(t => )} : 'loading tree'}` 124 | 125 | ## Development 126 | 127 | ```bash 128 | npm install 129 | npm start 130 | ``` 131 | 132 | ## Test Case 133 | 134 | http://localhost:8018/tests/runner.html?coverage 135 | 136 | ## Coverage 137 | 138 | http://localhost:8018/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8018/tests/runner.html?coverage 139 | 140 | ## License 141 | 142 | rc-tree is released under the MIT license. 143 | 144 | ## Other tree views 145 | 146 | - [zTree](http://www.treejs.cn/) 147 | - [jqTree](https://mbraak.github.io/jqTree/) 148 | - [jquery.treeselect](https://travistidwell.com/jquery.treeselect.js/) 149 | - [Angular Multi Select Tree](https://a5hik.github.io/angular-multi-select-tree/) 150 | -------------------------------------------------------------------------------- /assets/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-component/tree/a45cf7bc879a5b928a2e21313553f6cc8739aa7d/assets/icons.png -------------------------------------------------------------------------------- /assets/line.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-component/tree/a45cf7bc879a5b928a2e21313553f6cc8739aa7d/assets/line.gif -------------------------------------------------------------------------------- /assets/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-component/tree/a45cf7bc879a5b928a2e21313553f6cc8739aa7d/assets/loading.gif -------------------------------------------------------------------------------- /docs/changelog.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/demo/animation-draggable.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Animation Draggable 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Animation 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/basic-controlled.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Basic Controlled 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/basic.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Basic 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/big-data.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Big Data 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/contextmenu.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Context Menu 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/custom-switch-icon.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Custom Switch Icon 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/draggable-allow-drop.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Draggable Allow Drop 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/draggable.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Draggable 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/dropdown.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Dropdown 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/dynamic.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Dynamic 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/expandAction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Expand Action 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/fieldNames.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Field Names 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/funtionTitle.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Function Title 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/icon.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Icon 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/demo/selectable.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Selectable 3 | nav: 4 | title: Demo 5 | path: /demo 6 | --- 7 | 8 | 9 | -------------------------------------------------------------------------------- /docs/examples/animation-draggable.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console, react/no-access-state-in-setstate, 2 | react/no-danger, no-param-reassign */ 3 | import React from 'react'; 4 | import { gData } from './utils/dataUtil'; 5 | import '../../assets/index.less'; 6 | import Tree from '@rc-component/tree'; 7 | 8 | const STYLE = ` 9 | .rc-tree-child-tree { 10 | display: block; 11 | } 12 | 13 | .node-motion { 14 | transition: all .3s; 15 | overflow-y: hidden; 16 | } 17 | `; 18 | 19 | const motion = { 20 | motionName: 'node-motion', 21 | motionAppear: false, 22 | onAppearStart: node => { 23 | console.log('Start Motion:', node); 24 | return { height: 0 }; 25 | }, 26 | onAppearActive: node => ({ height: node.scrollHeight }), 27 | onLeaveStart: node => ({ height: node.offsetHeight }), 28 | onLeaveActive: () => ({ height: 0 }), 29 | }; 30 | 31 | // const gData = [ 32 | // { title: '0-0', key: '0-0' }, 33 | // { title: '0-1', key: '0-1' }, 34 | // { title: '0-2', key: '0-2', children: [{ title: '0-2-0', key: '0-2-0' }] }, 35 | // ]; 36 | 37 | class Demo extends React.Component { 38 | state = { 39 | gData, 40 | autoExpandParent: true, 41 | expandedKeys: ['0-0-key', '0-0-0-key', '0-0-0-0-key'], 42 | }; 43 | 44 | onDragEnter = ({ expandedKeys }) => { 45 | console.log('enter', expandedKeys); 46 | this.setState({ 47 | expandedKeys, 48 | }); 49 | }; 50 | 51 | onDrop = info => { 52 | console.log('drop', info); 53 | const dropKey = info.node.props.eventKey; 54 | const dragKey = info.dragNode.props.eventKey; 55 | const dropPos = info.node.props.pos.split('-'); 56 | const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); 57 | 58 | const loop = (data, key, callback) => { 59 | data.forEach((item, index, arr) => { 60 | if (item.key === key) { 61 | callback(item, index, arr); 62 | return; 63 | } 64 | if (item.children) { 65 | loop(item.children, key, callback); 66 | } 67 | }); 68 | }; 69 | const data = [...this.state.gData]; 70 | 71 | // Find dragObject 72 | let dragObj; 73 | loop(data, dragKey, (item, index, arr) => { 74 | arr.splice(index, 1); 75 | dragObj = item; 76 | }); 77 | 78 | if (!info.dropToGap) { 79 | // Drop on the content 80 | loop(data, dropKey, item => { 81 | item.children = item.children || []; 82 | // where to insert 示例添加到尾部,可以是随意位置 83 | item.children.push(dragObj); 84 | }); 85 | } else if ( 86 | (info.node.props.children || []).length > 0 && // Has children 87 | info.node.props.expanded && // Is expanded 88 | dropPosition === 1 // On the bottom gap 89 | ) { 90 | loop(data, dropKey, item => { 91 | item.children = item.children || []; 92 | // where to insert 示例添加到尾部,可以是随意位置 93 | item.children.unshift(dragObj); 94 | }); 95 | } else { 96 | // Drop on the gap 97 | let ar; 98 | let i; 99 | loop(data, dropKey, (item, index, arr) => { 100 | ar = arr; 101 | i = index; 102 | }); 103 | if (dropPosition === -1) { 104 | ar.splice(i, 0, dragObj); 105 | } else { 106 | ar.splice(i + 1, 0, dragObj); 107 | } 108 | } 109 | 110 | this.setState({ 111 | gData: data, 112 | }); 113 | }; 114 | 115 | onExpand = expandedKeys => { 116 | console.log('onExpand', expandedKeys); 117 | this.setState({ 118 | expandedKeys, 119 | autoExpandParent: false, 120 | }); 121 | }; 122 | 123 | render() { 124 | const { expandedKeys } = this.state; 125 | 126 | return ( 127 |
128 |