2.4.6 • Published 26 days ago

tree-graph-react v2.4.6

Weekly downloads
54
License
MIT
Repository
github
Last release
26 days ago

Tree graph for React / React Tree Diagram Component

████████╗██████╗ ███████╗███████╗     ██████╗ ██████╗  █████╗ ██████╗ ██╗  ██╗
╚══██╔══╝██╔══██╗██╔════╝██╔════╝    ██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██║  ██║
   ██║   ██████╔╝█████╗  █████╗█████╗██║  ███╗██████╔╝███████║██████╔╝███████║
   ██║   ██╔══██╗██╔══╝  ██╔══╝╚════╝██║   ██║██╔══██╗██╔══██║██╔═══╝ ██╔══██║
   ██║   ██║  ██║███████╗███████╗    ╚██████╔╝██║  ██║██║  ██║██║     ██║  ██║
   ╚═╝   ╚═╝  ╚═╝╚══════╝╚══════╝     ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝  ╚═╝

Dev

yarn start
yarn storybook

## PS: Storybook must run under Node 16.
nvm use

live demo

Installation

yarn add tree-graph-react

or

npm i tree-graph-react

Screenshot

Tree(MutiCol)

fVyxH0.png

Tree(MutiCol Dark)

fV6SEV.png

Tree(SingleCol)

fV6pNT.png

Mind(MutiCol))

fV694U.png

Mind(SingleCol))

fV6PCF.png

Menu

fV6cV0.png

Mini Menu

fV6ybq.png

Catalog

fV6gaV.png

Slides

5iN4X9.png

TreeEditor(Outline text editor)

I87KLd.png

Use case

fVgoAx.png fVg5H1.png IGS9VU.png

Usage

import { Tree, MenuTree, MiniMenu, Catalog, Mind } from 'tree-graph-react';
import 'tree-graph-react/dist/tree-graph-react.cjs.development.css';

const nodes = {
  '001': {
    _key: '001',
    name: '项目管理',
    father: '',
    sortList: ['002', '003', '004', '005'],
    contract: false,
    avatarUri: 'https://psnine.com/Upload/game/11387.png',
    icon: 'https://cdn-icare.qingtime.cn/rooter.svg',
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '002': {
    _key: '002',
    name: '计划进度',
    father: '001',
    sortList: ['006', '007'],
    contract: false,
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
    icon: 'https://cdn-icare.qingtime.cn/docFolder.svg',
  },
  '003': {
    _key: '003',
    name: '项目状态',
    father: '001',
    sortList: ['010', '011'],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
    icon: 'https://cdn-icare.qingtime.cn/favFolder.svg',
  },
  '004': {
    _key: '004',
    name: '项目会议',
    father: '001',
    sortList: [],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '005': {
    _key: '005',
    name: '验收',
    father: '001',
    sortList: [],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '006': {
    _key: '006',
    name: '阶段壹',
    father: '002',
    contract: false,
    sortList: ['008', '009'],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '007': {
    _key: '007',
    name: '阶段二',
    father: '002',
    sortList: [],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '008': {
    _key: '008',
    name: '备份json文件',
    father: '006',
    sortList: [],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '009': {
    _key: '009',
    name: '还原数据',
    father: '006',
    sortList: ['015'],
    checked: false,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '010': {
    _key: '010',
    name: '4月计划',
    father: '003',
    sortList: [],
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '011': {
    _key: '011',
    name: '5月计划',
    father: '003',
    sortList: ['012', '013', '014'],
    contract: false,
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '012': {
    _key: '012',
    name: '原型、界面设计',
    father: '011',
    sortList: [],
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '013': {
    _key: '013',
    name: '开发',
    father: '011',
    sortList: [],
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '014': {
    _key: '014',
    name: '测试',
    father: '011',
    sortList: [],
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
  '015': {
    _key: '015',
    name: '还原数据-还原数据',
    father: '009',
    sortList: [],
    checked: true,
    hour: 0.1,
    limitDay: 1610726400000,
  },
};

const MyComp = () => <Tree nodes={nodes} startId="001" />;

operate

OperationShortcut
Edit Node NameDoubleClick
Add Child NodeTab
Add Sibling NodeEnter
Delete NodeDelete
Move Selected NodeArrow keys
Move Node UpShift + ↑
Move Node DownShift + ↓
Copy NodeCommand/Ctrl + C
Cut NodeCommand/Ctrl + X
Paste NodeCommand/Ctrl + V
Save Tree (file mode)Command/Ctrl + S
Add Note (TreeEditor)Shift + Enter
Indent Left (TreeEditor)Shift + Tab

Functions

Method NameDescription
addNextAdd a new node as a sibling to the currently selected node
addChildAdd a new node as a child to the currently selected node
deleteNodeDelete the currently selected node
saveNodesGet the data of all nodes in the tree
renameRename the currently selected node
getSelectedIdGet the ID of the currently selected node
getSelectedIdsGet the IDs of the currently selected nodes
renameByIdUpdate the name of a node with a given ID
updateNodeByIdUpdate the data of a node with a given ID
updateNodesByIdsUpdate the data of nodes with given IDs
exportImageExport image (type: 'svg', 'png' , 'pdf')

Props

PropertyDescriptionTypeRequiredDefault
nodesThe nodes of the treeObjectYes-
uncontrolledWhether it is an uncontrolled componentBooleanNotrue
startIdThe ID of the root nodeStringYes-
defaultSelectedIdThe ID of the initially selected nodeStringYes-
refReference to call internal methods of the component-No-
singleColumnWhether to display the tree in a single columnBooleanNofalse
itemHeightHeight of the node elementNumberNo50
topBottomMarginNode Text Vertical MarginsNumberNo5
lineHeightNode Text Line HeightNumberNo20
fontSizeFont size of the nodesNumberNo14
fontWeightFont weight of the nodesNumberNo-
indentIndentationNumberNo25
columnSpacingSpacing between columnsNumberNo55
avatarWidthWidth of the avatarNumberNo22
pathWidthWidth of the connecting linesNumberNo1
pathColorColor of the connecting linesNumberNo-
nodeColorColor of the nodeNumberNo-
paddingLeftPadding leftNumberNo50
paddingTopPadding topNumberNo50
avatarRadiusAvatar border radiusNumberNo11
backgroundColorBackground colorNumberNounset
colorFont colorNumberNo#595959
hoverBorderColorBorder color when hovering over a nodeNumberNo#bed2fc
selectedBorderColorBorder color of the selected nodeNumberNo#35a6f8
selectedBackgroundColorBackground color of the selected nodeNumberNo#e8e8e8
lineRadiusRadius of the connecting linesNumberNo4
checkBoxWidthWidth of the checkboxNumberNo18
disableShortcutWhether to disable keyboard shortcutsNumberNo-
disabledWhether the tree is read-onlyNumberNo-
showIconWhether to show the iconsbooleanNotrue
showAvatarWhether to show the avatarsBoolean-
avatarUriAvatar URLString-
handleClickNodeClick event for nodes (parameters: node)FunctionNo-
handleDbClickNodeDouble click event for nodes (parameters: node)FunctionNo-
handleClickExpandClick event for expand/collapse (parameters: node)FunctionNo-
handleCheckClick event for checkboxes (parameters: node)FunctionNo-
handleClickAvatarClick event for avatars (parameters: node)FunctionNo-
handleClickStatusClick event for status (parameters: node)FunctionNo-
handleChangeNodeTextEvent for changing node name (parameters: nodeId, text)FunctionNo-
handleAddNextEvent for adding a sibling node (parameters: selectedNode)FunctionNo-
handleAddChildEvent for adding a child node (parameters: selectedNode)FunctionNo-
handleDeleteNodeEvent for deleting nodes (parameters: selectedId, selectedNodes)FunctionNo-
handleClickPreviewButtonClick event for the preview button (parameters: clickNode)FunctionNo-
handleClickDotClick event for dotsFunctionNo-
handleShiftUpDownMove node up/down (parameters: id, sortList, type)FunctionNo-
handleSaveSave the treeFunctionNo-
handleDragDrag nodes (parameters: dragInfo)FunctionNo-
handlePasteCopy nodes (parameters: pasteNodeKey, pasteType, targetNodeKey, event)FunctionNo-
hideHourHide task hoursbooleanNo-
dragEndFromOutsideDrag nodes from outside the tree (parameters: node, dataTransferText)FunctionNo-
handleMouseEnterAvatarMouse enter event for avatars (parameters: node)FunctionNo-
handleMouseLeaveAvatarMouse leave event for avatars (parameters: node)FunctionNo-
handleChangeTree data change eventFunctionNo-
showDeleteConformShow delete confirmation (uncontrolled mode)FunctionNo-
handleMutiSelectMulti-select nodes (parameters: selectedNodes)FunctionNo-
handleFileChangeTo handle file changes (parameters: nodeKey: string,nodeName:string, files: FileList)FunctionNo-
handleQuickCommandOpenTo handle the event after pressing the quickCommandKey (parameters: nodeEl: HTMLElement)FunctionNo-
handlePasteTextTo handle the event after pasting text. (parameters: text: string, event: ClipboardEvent)FunctionNo-
handleContextMenuTo handle the right-click event. (parameters: nodeKey: string, event: React.MouseEvent)FunctionNo-
handleClickNodeImageTo handle click node image event. (parameters: url: string)FunctionNo-
handleResizeNodeImageTo handle the node image resize. (parameters: nodeKey: string, nodeWidth: number)FunctionNo-
PropertyDescriptionTypeRequiredDefault
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
nodesThe nodes of the treeObjectYes-
uncontrolledWhether it is an uncontrolled componentBooleanNotrue
startIdThe ID of the root nodeStringYes-
defaultSelectedIdThe ID of the initially selected nodeStringYes-
refReference to call internal methods of the component-No-
singleColumnWhether to display the tree in a single columnBooleanNofalse
itemHeightHeight of the node elementNumberNo50
topBottomMarginNode Text Vertical MarginsNumberNo5
lineHeightNode Text Line HeightNumberNo20
fontSizeFont size of the nodesNumberNo14
fontWeightFont weight of the nodesNumberNo-
indentIndentationNumberNo25
columnSpacingSpacing between columnsNumberNo55
avatarWidthWidth of the avatarNumberNo22
pathWidthWidth of the connecting linesNumberNo1
pathColorColor of the connecting linesNumberNo-
nodeColorColor of the nodeNumberNo-
paddingLeftPadding leftNumberNo50
paddingTopPadding topNumberNo50
avatarRadiusAvatar border radiusNumberNo11
backgroundColorBackground colorNumberNounset
colorFont colorNumberNo#595959
hoverBorderColorBorder color when hovering over a nodeNumberNo#bed2fc
selectedBorderColorBorder color of the selected nodeNumberNo#35a6f8
selectedBackgroundColorBackground color of the selected nodeNumberNo#e8e8e8
lineRadiusRadius of the connecting linesNumberNo4
checkBoxWidthWidth of the checkboxNumberNo18
disableShortcutWhether to disable keyboard shortcutsNumberNo-
disabledWhether the tree is read-onlyNumberNo-
showIconWhether to show the iconsbooleanNotrue
showAvatarWhether to show the avatarsBoolean-
avatarUriAvatar URLString-
customAdornmentOptional component that allows custom adornments to be added to the tree node.(x:number,y:number,height:number,nodeKey:string)=>JSX.Element-
handleClickNodeClick event for nodes (parameters: node)FunctionNo-
handleDbClickNodeDouble click event for nodes (parameters: node)FunctionNo-
handleClickExpandClick event for expand/collapse (parameters: node)FunctionNo-
handleCheckClick event for checkboxes (parameters: node)FunctionNo-
handleClickAvatarClick event for avatars (parameters: node)FunctionNo-
handleClickStatusClick event for status (parameters: node)FunctionNo-
handleChangeNodeTextEvent for changing node name (parameters: nodeId, text)FunctionNo-
handleAddNextEvent for adding a sibling node (parameters: selectedNode)FunctionNo-
handleAddChildEvent for adding a child node (parameters: selectedNode)FunctionNo-
handleDeleteNodeEvent for deleting nodes (parameters: selectedId, selectedNodes)FunctionNo-
handleClickPreviewButtonClick event for the preview button (parameters: clickNode)FunctionNo-
handleClickDotClick event for dotsFunctionNo-
handleShiftUpDownMove node up/down (parameters: id, sortList, type)FunctionNo-
handleSaveSave the treeFunctionNo-
handleDragDrag nodes (parameters: dragInfo)FunctionNo-
handlePasteCopy nodes (parameters: pasteNodeKey, pasteType, targetNodeKey)FunctionNo-
hideHourHide task hoursbooleanNo-
dragEndFromOutsideDrag nodes from outside the tree (parameters: node, dataTransferText)FunctionNo-
handleMouseEnterAvatarMouse enter event for avatars (parameters: node)FunctionNo-
handleMouseLeaveAvatarMouse leave event for avatars (parameters: node)FunctionNo-
handleChangeTree data change eventFunctionNo-
showDeleteConformShow delete confirmation (uncontrolled mode)FunctionNo-
handleMutiSelectMulti-select nodes (parameters: selectedNodes)FunctionNo-
handleFileChangeTo handle file changes (parameters: nodeKey: string,nodeName:string, files: FileList)FunctionNo-
handleQuickCommandOpenTo handle the event after pressing the quickCommandKey (parameters: nodeEl: HTMLElement)FunctionNo-
handlePasteTextTo handle the event after pasting text. (parameters: text: string)FunctionNo-
handleContextMenuTo handle the right-click event. (parameters: nodeKey: string, event: React.MouseEvent)FunctionNo-
handleClickNodeImageTo handle click node image event. (parameters: url: string)FunctionNo-
handleResizeNodeImageTo handle the node image resize. (parameters: nodeKey: string, nodeWidth: number)FunctionNo-
interface DragInfo {
  dragNodeId: string;
  dropNodeId: string;
  placement: 'up' | 'down' | 'in';
}

Menu Props

PropertyDescriptionTypeRequiredDefault
collapseModeWhether it is in collapse mode (open one level at a time, automatically collapse others)booleanNofalse

MiniMenu Props

PropertyDescriptionTypeRequiredDefault
nodesNodesObjectYes-
startIdRoot node IDStringYes-
widthMenu widthstringNo48
backgroundColorMenu background colorstringNo#333333
selectedBackgroundColorSelected menu background colorstringNo#00CDD3
colorSelected menu text colorstringNo#CDD0D2
itemHeightNode element heightNumberNo48
fontSizeNode font sizeNumberNo14
columnSpacingColumn spacingNumberNo1
borderRadiusborder-radiusNumberNo0
normalFirstLevelWhether the first level is normal widthbooleanNofalse
handleClickNodeClick node event, parameters: nodeFunctionNo-
handleClickExpandClick expand/collapse event, parameters: nodeFunctionNo-
handleMouseEnterMouse enter eventFunctionNo-
handleMouseLeaveMouse leave eventFunctionNo-

Catalog Props

PropertyDescriptionTypeRequiredDefault
nodesNodesObjectYes-
startIdRoot node IDStringYes-
backgroundColorMenu background colorstringNo-
colorFont colorstringNo#595959
hoverColorFont color on hoverstringNo#8c8c8c
itemHeightNode element heightNumberNo48
blockHeightNode block heightNumberNo30
fontSizeNode font sizeNumberNo14
titleFontSizeTitle node font sizeNumberNo24
handleClickNodeClick node event, parameters: nodeFunctionNo-
indentIndentationNumberNo25
infoDirectory description infoReactElementNo-
itemInfoMapDirectory item description infoItemInfoMap { [_key: string]: ReactElement;}No-

TreeEditor Props

PropertyDescriptionTypeRequiredDefault
handlePasteFilesPaste attachmentsFunctionYes-
handleDeleteAttachDelete attachmentFunctionYes-
handleAddNoteAdd noteFunctionNo-
handleChangeNoteChange noteFunctionNo-
handleDeleteNoteDelete noteFunctionNo-
handleSwitchToBrotherChildPress Tab on an empty node, convert the current node to the last child of its brother node.FunctionNo-

Node Props

PropertyDescriptionType
_keyNode IDString
nameNode textString
fatherParent node IDString
sortListArray of child node IDsArray
contractWhether to collapse child nodesBoolean
checkedWhether it is checkedBoolean
avatarUriAvatar image addressString
iconIcon image addressString
dotIconDot icon image addressString
colorNode font colorString
backgroundColorNode background colorString
showCheckboxWhether to show the checkboxBoolean
showStatusWhether to show node statusBoolean
strikethroughWhether to show strikethroughBoolean
hourNode (task) hoursNumber
limitDayNode (task) remaining daystimestamp
disabledWhether it is disabledBoolean
2.4.6

26 days ago

2.4.5

2 months ago

2.4.4

2 months ago

2.4.3

3 months ago

2.4.2

3 months ago

2.4.1

4 months ago

2.4.0

4 months ago

2.3.8

5 months ago

2.3.7

5 months ago

2.3.9

5 months ago

2.3.0

9 months ago

2.3.2

9 months ago

2.3.1

9 months ago

2.3.4

8 months ago

2.3.3

9 months ago

2.3.6

8 months ago

2.3.5

8 months ago

2.2.1

9 months ago

2.2.0

9 months ago

2.2.2

9 months ago

2.2.5

9 months ago

2.2.4

9 months ago

2.2.7

9 months ago

2.2.6

9 months ago

2.1.2

9 months ago

2.1.1

9 months ago

2.1.4

9 months ago

2.1.3

9 months ago

2.1.6

9 months ago

2.1.5

9 months ago

2.1.8

9 months ago

2.1.7

9 months ago

2.1.0

9 months ago

2.2.9

9 months ago

2.2.8

9 months ago

2.0.3

10 months ago

2.0.2

10 months ago

2.0.5

10 months ago

2.0.4

10 months ago

2.0.7

10 months ago

2.0.9

9 months ago

2.0.8

9 months ago

2.0.1

10 months ago

2.0.0

10 months ago

2.1.9

9 months ago

1.7.2

1 year ago

1.6.9

1 year ago

1.6.8

1 year ago

1.6.7

2 years ago

1.6.6

2 years ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.5

2 years ago

1.6.0

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.2.0

3 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.9

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.9

3 years ago

1.0.2

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.9

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.9

3 years ago

0.8.8

3 years ago

0.8.7

3 years ago

0.8.6

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.9

3 years ago

0.7.8

3 years ago

0.7.7

3 years ago

0.7.4

3 years ago

0.7.6

3 years ago

0.7.5

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.3

3 years ago

0.7.0

3 years ago

0.6.9

3 years ago

0.6.8

3 years ago

0.6.7

3 years ago

0.6.6

3 years ago

0.6.5

3 years ago

0.6.3

3 years ago

0.6.2

3 years ago

0.6.4

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.9

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago