• Stars
    star
    1,113
  • Rank 40,362 (Top 0.9 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Tree

rc-tree

Tree component.

NPM version dumi build status Test coverage Dependencies DevDependencies npm download bundle size

Screenshots

Feature

  • Support all popular browsers, including Internet Explorer 9 and above.

Example

http://localhost:9001/

online example: https://tree.react-component.now.sh/

Install

rc-tree

Usage

Note: import "rc-tree/assets/index.css"

see examples

API

Tree props

name description type default
autoExpandParent whether auto expand parent treeNodes bool false
checkable whether support checked bool/React Node false
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} []
checkStrictly check node precisely, parent and children nodes are not associated bool false
className additional css class of root dom node String ''
defaultCheckedKeys default checked treeNodes String[] []
defaultExpandedKeys expand specific treeNodes String[] []
defaultExpandAll expand all treeNodes bool false
defaultExpandParent auto expand parent treeNodes when init bool true
defaultSelectedKeys default selected treeNodes String[] []
disabled whether disabled the tree bool false
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
expandedKeys Controlled expand specific treeNodes String[] -
filterTreeNode filter some treeNodes as you need. it should return true function(node) -
icon customize icon. When you pass component, whose render will receive full TreeNode props as component props element/Function(props) -
loadedKeys Mark node is loaded when loadData is true String[] -
loadData load data asynchronously and the return value should be a promise function(node) -
multiple whether multiple select bool false
prefixCls prefix class String 'rc-tree'
selectable whether can be selected bool true
selectedKeys Controlled selected treeNodes(After setting, defaultSelectedKeys will not work) String[] []
showIcon whether show icon bool true
showLine whether show line bool false
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]}> -
onCheck click the treeNode/checkbox to fire function(checkedKeys, e:{checked: bool, checkedNodes, node, event, nativeEvent}) -
onExpand fire on treeNode expand or not function(expandedKeys, {expanded: bool, node, nativeEvent}) -
onDragEnd it execs when fire the tree's dragend event function({event,node}) -
onDragEnter it execs when fire the tree's dragenter event function({event,node,expandedKeys}) -
onDragLeave it execs when fire the tree's dragleave event function({event,node}) -
onDragOver it execs when fire the tree's dragover event function({event,node}) -
onDragStart it execs when fire the tree's dragstart event function({event,node}) -
onDrop it execs when fire the tree's drop event function({event, node, dragNode, dragNodesKeys}) -
onLoad Trigger when a node is loaded. If you set the loadedKeys, you must handle onLoad to avoid infinity loop function(loadedKeys, {event, node}) -
onMouseEnter call when mouse enter a treeNode function({event,node}) -
onMouseLeave call when mouse leave a treeNode function({event,node}) -
onRightClick select current treeNode and show customized contextmenu function({event,node}) -
onSelect click the treeNode to fire function(selectedKeys, e:{selected: bool, selectedNodes, node, event, nativeEvent}) -
switcherIcon specific the switcher icon. ReactNode / (props: TreeNodeAttribute) => ReactNode -
virtual Disable virtual scroll when false boolean -
allowDrop Whether to allow drop on node ({ dragNode, dropNode, dropPosition }) => boolean -
dropIndicatorRender The indicator to render when dragging ({ dropPosition, dropLevelOffset, indent: number, prefixCls }) => ReactNode -
direction Display direction of the tree, it may affect dragging behavior ltr | rtl -
expandAction Tree open logic, optional: false | click | doubleClick string | boolean click

TreeNode props

note: if you have a lot of TreeNode, like more than 1000,
make the parent node is collapsed by default, will obvious effect, very fast.
Because the children hide TreeNode will not insert into dom.

name description type default
className additional class to treeNode String ''
checkable control node checkable if Tree is checkable bool false
style set style to treeNode Object ''
disabled whether disabled the treeNode bool false
disableCheckbox whether disable the treeNode' checkbox bool false
title tree/subTree's title String/element/((data: DataNode) => React.ReactNode) '---'
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
isLeaf whether it's leaf node bool false
icon customize icon. When you pass component, whose render will receive full TreeNode props as component props element/Function(props) -
switcherIcon specific the switcher icon. ReactNode / (props: TreeNodeAttribute) => ReactNode -

Note

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 ? <Tree ...>{this.state.treeData.map(t => <TreeNode ... />)}</Tree> : 'loading tree'}

Development

npm install
npm start

Test Case

http://localhost:8018/tests/runner.html?coverage

Coverage

http://localhost:8018/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8018/tests/runner.html?coverage

License

rc-tree is released under the MIT license.

Other tree views

More Repositories

1

slider

React Slider
JavaScript
2,962
star
2

form

React High Order Form Component(web & react-native)
JavaScript
1,799
star
3

calendar

React Calendar
JavaScript
1,681
star
4

table

React Table
TypeScript
1,183
star
5

field-form

⚡️ React Performance First Form Component
TypeScript
914
star
6

tooltip

React Tooltip
TypeScript
896
star
7

select

React Select
TypeScript
854
star
8

upload

React Upload
TypeScript
766
star
9

progress

React Progress Bar
TypeScript
678
star
10

animate

anim react element easily
JavaScript
675
star
11

menu

React Menu
TypeScript
655
star
12

virtual-list

🧾 React Virtual List Component which worked with animation
TypeScript
645
star
13

pagination

React Pagination
TypeScript
629
star
14

util

Common Utils For React Component
TypeScript
604
star
15

tabs

React Tabs
TypeScript
540
star
16

queue-anim

Animate React Component in queue
TypeScript
474
star
17

time-picker

React TimePicker
JavaScript
463
star
18

dialog

React Dialog
TypeScript
424
star
19

color-picker

React ColorPicker
TypeScript
419
star
20

m-date-picker

React Mobile DatePicker(web & react-native)
TypeScript
400
star
21

react-component.github.io

docs and site of react-component
HTML
378
star
22

drawer

React Drawer
TypeScript
372
star
23

tween-one

Animate One React Element
TypeScript
370
star
24

notification

React Notification
TypeScript
364
star
25

trigger

Abstract React Trigger
TypeScript
345
star
26

collapse

React Collapse / Accordion
TypeScript
319
star
27

steps

React Steps
TypeScript
311
star
28

scroll-anim

Animate Scroll React Component
JavaScript
301
star
29

input-number

React Input Number
TypeScript
296
star
30

tree-select

React Tree Select
TypeScript
272
star
31

picker

📅 All Date Pickers you need.
TypeScript
253
star
32

m-picker

React Mobile Picker(web & react-native)
TypeScript
246
star
33

swipeout

React Swipeout(web & react-native)
TypeScript
213
star
34

rc-tools

Tools For React Component
JavaScript
205
star
35

cascader

cascade select in one box
TypeScript
198
star
36

switch

React Switch
JavaScript
187
star
37

image

🖼 React Image Component
TypeScript
179
star
38

banner-anim

Animate Banner React Component
JavaScript
170
star
39

m-pull-to-refresh

React Mobile Pull To Refresh
TypeScript
166
star
40

dropdown

React Dropdown
TypeScript
163
star
41

texty

React Text Animate
TypeScript
154
star
42

resize-observer

👓 Resize observer for React
JavaScript
153
star
43

m-tabs

React Mobile Tabs Component (web & react-native)
TypeScript
139
star
44

checkbox

React Checkbox
TypeScript
130
star
45

motion

⛷ CSS Animation for React
TypeScript
120
star
46

gesture

Support gesture for react component.
TypeScript
103
star
47

rate

React Rate
JavaScript
91
star
48

form-validation

This project is deprecated, you can try https://github.com/react-component/form
JavaScript
86
star
49

m-list-view

ReactNative ListView Web Port
JavaScript
85
star
50

footer

🐾 Pretty Footer react component used in ant.design
JavaScript
83
star
51

align

Abstract React Align
TypeScript
81
star
52

mentions

React Mentions
TypeScript
67
star
53

rn-packager

Standalone ReactNative Packager
JavaScript
66
star
54

generator-rc

yeoman generator for react component
JavaScript
58
star
55

editor-core

a draft-js based editor
TypeScript
56
star
56

m-drawer

React Drawer
JavaScript
54
star
57

cropping

image cropping
TypeScript
54
star
58

editor-mention

React Mention
JavaScript
53
star
59

m-cascader

React Mobile Cascader Component(web and react-native)
TypeScript
51
star
60

m-dialog

React Mobile Dialog(web & react-native)
TypeScript
45
star
61

spider

React Tree Diagrams
JavaScript
44
star
62

overflow

📦 Auto collapse box util component
TypeScript
42
star
63

css-transition-group

standalone CSSTransitionGroup for React.addons.CSSTransitionGroup
JavaScript
38
star
64

m-calendar

React Mobile Calendar Component (web)
TypeScript
36
star
65

m-feedback

:active pseudo-class with react for mobile
TypeScript
36
star
66

tour

TypeScript
30
star
67

input

React Input Component
TypeScript
29
star
68

pager

React Pager
JavaScript
26
star
69

m-notification

JavaScript
23
star
70

dropzone

React Dropzone
JavaScript
23
star
71

textarea

React Textarea
TypeScript
22
star
72

radio

[DEPRECATED] React Radio
CSS
19
star
73

m-input-number

input-number mobile ui component for react (web & react-native)
TypeScript
17
star
74

portal

TypeScript
16
star
75

touchable

React Touchable Component
TypeScript
16
star
76

rc-server

This project is deprecated, use rc-tools run server
JavaScript
15
star
77

gulp-jsx2example

Compile JSX file to HTML (react demo)
JavaScript
13
star
78

cascade-select

React CascadeSelect
JavaScript
13
star
79

icon-anim

Icon cutover or morph animate React Element
JavaScript
12
star
80

m-select-list

React Mobile Select List Component
JavaScript
12
star
81

segmented

React Segmented Controls
TypeScript
12
star
82

rc-test

test react component
JavaScript
11
star
83

mobile

ant design mobile components
TypeScript
10
star
84

m-tooltip

React Tooltip for mobile
TypeScript
8
star
85

context

TypeScript
7
star
86

rn-tools

tools for react-native
JavaScript
7
star
87

m-trigger

React Trigger Component for mobile
JavaScript
6
star
88

rn-core

Standalone ReactNative Framework
Objective-C
6
star
89

record

Record audio from microphone
JavaScript
5
star
90

.github

5
star
91

RNPlayground

react-native playground container
Objective-C
5
star
92

mutate-observer

TypeScript
5
star
93

editor-plugin-emoji

HTML
4
star
94

m-steps

React Steps for mobile
CSS
4
star
95

editor-plugin-basic-style

TypeScript
3
star
96

mini-decimal

TypeScript
3
star
97

editor-utils

editor utilities
TypeScript
2
star
98

father-plugin

father plugin for all react-component project
TypeScript
1
star
99

editor-plugin-image

TypeScript
1
star