|
| 1 | +### React Component Library - code4bones react UI |
| 2 | + |
| 3 | +### Components |
| 4 | + |
| 5 | +| Component| Description | |
| 6 | +| ------------ | ------------ | |
| 7 | +| TreeMenu | Navigation Menu Tree | |
| 8 | + |
| 9 | + |
| 10 | +# react-c4b-ui |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +     |
| 16 | + |
| 17 | +### Links |
| 18 | + |
| 19 | +[Change log](https://github.com/code4bones/react-c4b-ui/wiki/Change-Log "Change log") |
| 20 | + |
| 21 | +### System default / custom theme |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +|feature|sample| |
| 26 | +|-------|------| |
| 27 | +|| | |
| 28 | +|| |
| 29 | + |
| 30 | +### Install |
| 31 | + |
| 32 | + |
| 33 | +`$ yarn add @code4bones/react-c4b-ui` |
| 34 | + |
| 35 | +#### TreeMenu |
| 36 | + |
| 37 | +#### Brief |
| 38 | + |
| 39 | +```tsx |
| 40 | + |
| 41 | +import {TreeMenu, TreeMenuActions,TreeMenuItem } from "@code4bones/react-c4b-ui"; |
| 42 | +import "@code4bones/react-c4b-ui/build/styles.css"; |
| 43 | + |
| 44 | +const ITEMS : TreeMenuItem[] = [{ |
| 45 | + id:"item1", |
| 46 | + title:"Item 1", |
| 47 | + // other TreeMenuItem's props |
| 48 | + childs:[{ |
| 49 | + id:"sub", |
| 50 | + title:"Subitem 1", |
| 51 | + }] |
| 52 | +}]; |
| 53 | + |
| 54 | +// if your need to use exponsed actions |
| 55 | +const ref = createRef<TreeMenuActions>(); |
| 56 | + |
| 57 | +<TreeMenu |
| 58 | + ref={ref} |
| 59 | + items={ITEMS} |
| 60 | + onClick={onClick} |
| 61 | +/> |
| 62 | + |
| 63 | +``` |
| 64 | + |
| 65 | +### Properties |
| 66 | + |
| 67 | +type `RenderFn` = (item:MenuItem) => React.ReactElement | undefined | null; |
| 68 | +type `RenderType` = `RenderFn` | React.ReactElement; |
| 69 | + |
| 70 | + |
| 71 | +| Propery name | Description | Signature |
| 72 | +| ------------- | ------------------------------ | ---- | |
| 73 | +| `items[]` | tree menu items array | `TreeMenuItem`[] | |
| 74 | +| `ref` | handle to TreeMenu methods | `TreeMenuActions` | |
| 75 | +| `onClick` | item click handler | onClick?:(item:TreeMenuItem) => void| |
| 76 | +| `onToggle` | collapse / expand | onToggle?:(id?:string,collapsed?:boolean) => void;| |
| 77 | +| `initialCollapsed` | initial tree state | boolean | |
| 78 | +| `initialSelected` | initial selected item | item's `id` : string| |
| 79 | +| `renderBadge` | item click handler | `RenderType` | |
| 80 | +| `renderIcon` | Left side element of item | `RenderType` | |
| 81 | +| `renderGroupState` | Group indicator | `RenderType` | |
| 82 | +| `theme` | theme override class name | `dark`, `light`, custom name | |
| 83 | +| `classPrefix` | container global prefix | string | |
| 84 | +| `enableRotate` | Rotate collapse / expand | boolean | |
| 85 | + |
| 86 | + |
| 87 | +`TreeMenuItem` |
| 88 | + |
| 89 | +```tsx |
| 90 | + id:string; |
| 91 | + title:string | React.ReactElement; |
| 92 | + info?:string | React.ReactElement; |
| 93 | + infoReveal?:InfoReveal; |
| 94 | + icon?:React.ReactElement; |
| 95 | + badge?:string | React.ReactElement; |
| 96 | + disabled?:boolean; |
| 97 | + unselectable?:boolean; |
| 98 | + titleClass?:string; |
| 99 | + infoClass?:string; |
| 100 | + style?:React.CSSProperties; |
| 101 | + titleStyle?:React.CSSProperties; |
| 102 | + infoStyle?:React.CSSProperties; |
| 103 | +``` |
| 104 | + |
| 105 | +`TreeMenuActions` ( use `ref` ) |
| 106 | +``` |
| 107 | + enable:(id:string,disable?:boolean) => void; |
| 108 | + getItem:(id:string) => TreeMenuItem | null; |
| 109 | + collapse:(id:string,collapsed?:boolean) => void; |
| 110 | + select:(id:string) => void; |
| 111 | +
|
| 112 | +``` |
| 113 | + |
| 114 | +### Sample |
| 115 | + |
| 116 | +Sample available via storybook `yarn storybook` |
0 commit comments