-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(tree): 新增 icon 支持自定义渲染函数(#2960) * chore(tree): 生成变更记录文件 * feat(tree): 示例添加可编辑属性 --------- Co-authored-by: xiamiao <[email protected]>
- Loading branch information
1 parent
a90f1e9
commit 7bdd549
Showing
7 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/tree": minor | ||
--- | ||
|
||
feat: 新增 icon 支持自定义渲染函数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(tree): 新增 icon 支持自定义渲染函数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react' | ||
import Tree, { useTreeAction } from '../src' | ||
import { Modal } from '@hi-ui/modal' | ||
import { FileOutlined, FolderOpenOutlined, FolderOutlined } from '@hi-ui/icons' | ||
|
||
/** | ||
* @title 自定义 icon 渲染函数 | ||
*/ | ||
export const IconRender = () => { | ||
const ActionTree = useTreeAction(Tree) | ||
|
||
return ( | ||
<> | ||
<h1>IconRender for Tree</h1> | ||
<div className="tree-icon-render__wrap"> | ||
<ActionTree | ||
expandOnSelect | ||
editPlaceholder="请填写菜单" | ||
menuOptions={[ | ||
{ | ||
type: 'addChildNode', | ||
title: '新建子节点', | ||
}, | ||
{ | ||
type: 'addSiblingNode', | ||
title: '新建兄弟节点', | ||
}, | ||
{ | ||
// type: 'deleteNode', | ||
title: '删除当前菜单', | ||
onClick(node, action) { | ||
action.closeMenu() | ||
|
||
Modal.confirm({ | ||
title: '提示', | ||
content: '确定删除吗?', | ||
onConfirm: () => { | ||
action.deleteNode() | ||
}, | ||
}) | ||
}, | ||
}, | ||
{ | ||
type: 'editNode', | ||
title: '编辑当前菜单', | ||
}, | ||
{ | ||
title: 'Hello,自定义的菜单', | ||
onClick(node, action) { | ||
console.log(node) | ||
action.closeMenu() | ||
}, | ||
}, | ||
]} | ||
data={[ | ||
{ | ||
id: 1, | ||
title: '小米', | ||
children: [ | ||
{ | ||
id: 2, | ||
title: '研发', | ||
children: [ | ||
{ id: 3, title: '后端' }, | ||
{ id: 4, title: '运维' }, | ||
{ id: 5, title: '前端' }, | ||
], | ||
}, | ||
{ id: 6, title: '产品' }, | ||
], | ||
}, | ||
{ | ||
id: 11, | ||
title: '大米', | ||
children: [ | ||
{ id: 22, title: '可视化' }, | ||
{ id: 66, title: 'HiUI' }, | ||
], | ||
}, | ||
]} | ||
iconRender={(node) => { | ||
if (!node.children?.length) { | ||
return <FileOutlined /> | ||
} | ||
|
||
if (node.expanded) { | ||
return <FolderOpenOutlined /> | ||
} else return <FolderOutlined /> | ||
}} | ||
/> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters