1- # React Tress
1+ # React Tree
22
33[ ![ Build Status] ( https://travis-ci.org/kenshoo/react-tree.svg?branch=master )] ( https://travis-ci.org/kenshoo/react-tree )
44[ ![ Test Coverage] ( https://api.codeclimate.com/v1/badges/7b44acc9042c5ee410a8/test_coverage )] ( https://codeclimate.com/github/kenshoo/react-tree/test_coverage )
55
6- Code usage:
6+ React Tree is a straight forward component that allows a user to display and manage a hierarchical structure of items in a clear and comfortable way.
77
8+ ## Optional Themes
9+
10+ Two optional themes are supported when using React Tree:
11+ - Basic tree: using @emotion/core .
12+ - Material tree: based on the basic tree logic, using Material-UI components - https://github.com/kenshoo/react-tree/blob/master/packages/material_tree/README.md
813
14+ Both options support component customization.
15+
16+ Examples - https://github.com/kenshoo/react-tree/blob/master/packages/docs/stories/core.stories.js
17+
18+ ## Basic tree
19+
20+ <p align =" center " >
21+ <img src="core-tree-demo.gif?raw=true" width="400" />
22+ </p >
23+
24+ ### Installation
25+
26+ ** Installation using npm:**
27+ ```
28+ npm install @kenshooui/react-tree --save
29+ ```
30+ ** Installation using Yarn:**
31+
32+ ```
33+ yarn add @kenshooui/react-tree
34+ ```
35+
36+ ### How to use
937 <!-- example -->
1038
1139``` jsx
@@ -31,12 +59,191 @@ const structure = [
3159/ > ;
3260```
3361
34- ## Props
62+ ### Props
63+
64+ | Name | Type | Default | Description |
65+ | :------------------ | :---------- | :--------------------- | :-------------------------------------------------------------- |
66+ | ` structure ` | ` Array ` | ` [] ` | ` Component input - array of leaves along with their ancestors ` |
67+ | ` title ` | ` String ` | ` "" ` | ` Title to be displayed on root mode ` |
68+ | ` onSelect ` | ` Func ` | ` () => {} ` | ` callback when clicking a leaf ` |
69+ | ` styles ` | ` Object ` | | ` Optional - enables customized styles ` |
70+ | ` width ` | ` number ` | ` 230 ` | ` The width of the tree component ` |
71+ | ` height ` | ` number ` | ` 300 ` | ` The height of the tree component ` |
72+ | ` noResultsText ` | ` String ` | ` No matching results ` | ` The message to be displayed when having no results on searching ` |
73+ | ` noResultsRenderer ` | ` Component ` | ` no_matching_items.js ` | ` Component to replace the default NoResults component. ` |
74+ | ` noResultsIconRenderer ` | ` Component ` | | ` Component to replace the default NoResultsIcon component. ` |
75+ | ` headerRenderer ` | ` Component ` | ` header.js ` | ` Component to replace the default Header component. ` |
76+ | ` backIconRenderer ` | ` Component ` | | ` Component to replace the default BackIcon component. ` |
77+ | ` inputRenderer ` | ` Component ` | ` input.js️ ` | ` Component to replace the default Input component. ` |
78+ | ` inputIconRenderer ` | ` Component ` | | ` Component to replace the default InputIcon component. ` |
79+ | ` clearIconRenderer ` | ` Component ` | | ` Component to replace the default CleaseIcon component. ` |
80+ | ` itemRenderer ` | ` Component ` | ` item.js️ ` | ` Component to replace the default Item component. ` |
81+ | ` itemsRenderer ` | ` Component ` | ` items.js ` | ` Component to replace the default Items component. ` |
82+ | ` forwardIconRenderer ` | ` Component ` | | ` Component to replace the default ForwardIcon component. ` |
83+ | ` treeContainerRenderer ` | ` Component ` | ` tree_container.js ` | ` Component to replace the default TreeContainer component. ` |
84+ | ` markSelectedItem ` | ` boolean ` | ` false ` | ` Toggle to mark selected item. ` |
85+
86+ <br />
87+
88+ ### Customization
89+
90+ #### Styling
91+
92+ The basic tree gets "styles" object property.
93+ <br />
94+ If the "styles" object is empty, the basic tree will use the default styles.
95+ <br />
96+ The "styles" object can override any of the following:
97+ - container - tree container
98+ - header - tree header. Displays tree title or item's parents
99+ - headerBackIcon - back icon
100+ - item - a single item from the hierarchical tree.
101+ - highlight - the style of the searched (highlighted) letters of an item
102+ - searchItemInitial: the style of the basic ("not searched") letters of an item
103+ - parents - the style of parents sub-title on search
104+ - items - items list container
105+ - noResults - displayed when there are no found items
106+ - noResultsIcon - the icon displayed when there are no found items
107+ - noResultsText - the massage displayed when there are no found items
108+ - input - search input
109+ - searchInput - the icon of the search input
110+ - clearInput - the icon of the search input "clear" button
111+ - forwardIcon - the icon that is part of the item component. Displayed when the item has children.
112+ - selectedItem - the style of the selectedItem item
113+ - inputWrapper - the style of input wrapper
114+
115+ <br />
116+
117+ #### Renderers
118+
119+ You can replace the renderers of the following components:
120+
121+ <br />
122+
123+ ** Container**
124+
125+ Use the ` treeContainerRenderer ` to replace the default component.
126+
127+ Each treeContainer receives the following props:
128+
129+ ` containerRef ` - Holds a reference to the tree container component
130+
131+ ` children ` - Holds all sub components (like header, input, items, etc..)
132+
133+ ` getStyles ` - Gets relevant styles
134+
135+ ` styles ` - Enables using customized styles
136+
137+ <br />
138+
139+ ** Header**
140+
141+ Use the ` headerRenderer ` to replace the default component.
142+
143+ Each header receives the following props:
144+
145+ ` headerRef ` - Holds a reference to the header component
146+
147+ ` parents ` - Holds the parents of the current level.
148+ <br />
149+ For example for the following structure: [ "Profiles", "Performance", "Clicks"]
150+ - In the first level the parents are: [ ""]
151+ - In the second level the parents are: [ "Profile"]
152+ - In the third level the parents are: [ "Profile, "Performance"]
153+
154+
155+ ` onClick ` - Triggers the back event on click
156+
157+ ` title ` - The title of the header. Displayed on the first level.
158+
159+ ` getStyles ` - Gets relevant styles
160+
161+ ` styles ` - Enables using customized styles
162+
163+ ` backIconRenderer ` - Use the ` backIconRenderer ` to replace the default back button component.
164+
165+ <br />
166+
167+ ** Input**
168+
169+ Use the ` inputRenderer ` to replace the default component.
170+
171+ Each header receives the following props:
172+
173+ ` inputRef ` - Holds a reference to the input component
174+
175+ ` searchTerm ` - Holds the searched value
176+
177+ ` onInputChange ` - Triggers set searchTerm event on change
178+
179+ ` getStyles ` - Gets relevant styles
180+
181+ ` styles ` - Enables using customized styles
182+
183+ ` inputIconRenderer ` - Use the ` inputIconRenderer ` to replace the default input icon component.
184+
185+ ` clearIconRenderer ` - Use the ` clearIconRenderer ` to replace the default clear input icon component.
186+
187+ <br />
188+
189+ ** Items**
190+
191+ Use the ` itemsRenderer ` to replace the default component.
192+
193+ Each header receives the following props:
194+
195+ ` getStyles ` - Gets relevant styles
196+
197+ ` styles ` - Enables using customized styles
198+
199+ ` children ` - All items
200+
201+ <br />
202+
203+ ** Item**
204+
205+ Use the ` itemRenderer ` to replace the default component
206+
207+ Each header receives the following props:
208+
209+ ` getStyles ` - Gets relevant styles
210+
211+ ` styles ` - Enables using customized styles
212+
213+ ` searchTerm ` - Holds the searched value
214+
215+ ` item ` - Represents an item from the given structure
216+
217+ ` onClick ` - Is called when clicking on an item
218+
219+ ` forwardIconRenderer ` - Use the ` forwardIconRenderer ` to replace the default forward icon component
220+
221+ ` selectedItem ` - Represents the current selected item. Is relevant when markSelectedItem = true
222+
223+ <br />
224+
225+ ** No Results**
226+
227+ Use the ` noResultsRenderer ` to replace the default component.
228+
229+ ` getStyles ` - Gets relevant styles
230+
231+ ` styles ` - Enables using customized styles
232+
233+ ` text ` - Displayed when there are no results
234+
235+ ` noResultsIconRenderer ` - Use the ` noResultsIconRenderer ` to replace the default no results warning icon component.
236+
237+
238+ ## How to Contribute
239+
240+ #### Setting up development environment
241+
242+ 1 . Fork the repository and create your branch from ` master ` .
243+ 2 . Install the project: ` yarn install `
244+ 3 . Run tests: ` yarn test ` or ` yarn test:watch `
245+ 4 . Run dev environment: ` yarn storybook ` and head to [ https://localhost:6006 ] ( https://localhost:6006 )
35246
36- | Name | Type | Default | Description |
37- | :------------------ | :-------- | :--------------------- | :-------------------------------------------------------------- |
38- | ` structure ` | ` Array ` | ` [] ` | ` Component input - array of leaves along with their ancestors ` |
39- | ` title ` | ` String ` | `` | ` Title to be displayed on root mode ` |
40- | ` onSelect ` | ` Func ` | `` | ` callback when clicking a leaf ` |
41- | ` NoResultsRenderer ` | `` | ` no_matching_items.js ` | ` renderer when having no results on searching ` |
247+ ## Credit
42248
249+ Styling patterns were taken from react-select - https://github.com/JedWatson/react-select/blob/master/README.md
0 commit comments