-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Tree): add renderChildNodes prop (#1273)
* feat(Tree): add renderChildNodes prop
- Loading branch information
1 parent
e25e236
commit aede069
Showing
7 changed files
with
142 additions
and
4 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,81 @@ | ||
# 平铺叶子节点 | ||
|
||
- order: 9 | ||
|
||
当最后一级都是叶子节点时,平铺展示 | ||
|
||
:::lang=en-us | ||
# Tile leaf nodes | ||
|
||
- order: 9 | ||
|
||
When the last level is all leaf nodes, the tiling display. | ||
::: | ||
|
||
--- | ||
|
||
````jsx | ||
import { Tree } from '@alifd/next'; | ||
|
||
const TreeNode = Tree.Node; | ||
|
||
|
||
const formatDataSource = (data) => { | ||
return data.map((it) => { | ||
return { | ||
...it, | ||
key: it.value, | ||
children: formatDataSource(it.children || []) | ||
}; | ||
}); | ||
} | ||
|
||
class Demo extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
data: [] | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
fetch('https://os.alipayobjects.com/rmsportal/ODDwqcDFTLAguOvWEolX.json') | ||
.then(response => response.json()) | ||
.then(data => this.setState({ data: formatDataSource([data[0]]) })) | ||
.catch(e => console.log(e)); | ||
} | ||
|
||
render() { | ||
return <Tree checkable renderChildNodes={(nodes) => { | ||
if (nodes.filter((node) => !node.props.children || node.props.children.length === 0).length !== nodes.length) { | ||
<ul role="group" className={`next-tree-child-tree`}> | ||
{nodes} | ||
</ul> | ||
} | ||
return <ul role="group" className="next-tree-child-tree custom-leaf-tree">{nodes}</ul>; | ||
}} defaultExpandAll dataSource={this.state.data}/>; | ||
} | ||
} | ||
|
||
ReactDOM.render(<Demo />, mountNode); | ||
```` | ||
|
||
```css | ||
.custom-leaf-tree { | ||
padding-left: 20px; | ||
display: block; | ||
font-size: 0; | ||
white-space: normal; | ||
} | ||
.custom-leaf-tree .next-tree-switcher{ | ||
display: none; | ||
} | ||
|
||
.custom-leaf-tree .next-tree-node { | ||
margin-left: 0 !important; | ||
margin-right: 8px; | ||
width: 68px; | ||
display: inline-block; | ||
} | ||
``` |
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
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