mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Using material-ui lab TreeView components
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
1 parent
69e7397e17
commit
3744d4a3cd
4 files changed
+59
-49
No files matched your search
@@ -26,17 +26,17 @@ export function ScrollSpy(props: Props) {
|
||||
const children: NavigationTree[] = [];
|
||||
|
||||
sections.forEach(section => {
|
||||
const key = section.getAttribute("id");
|
||||
const label = section.querySelector(":first-child").textContent;
|
||||
const id = section.getAttribute("id");
|
||||
const name = section.querySelector(":first-child").textContent;
|
||||
|
||||
if (!label || !key) {
|
||||
if (!name || !id) {
|
||||
return;
|
||||
}
|
||||
|
||||
children.push({
|
||||
key,
|
||||
label,
|
||||
nodes: getNavigation(section)
|
||||
id,
|
||||
name,
|
||||
children: getNavigation(section)
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,25 +1,45 @@
|
||||
import React from "react";
|
||||
import TreeMenu from "react-simple-tree-menu";
|
||||
import { Icon } from "../icon";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import TreeView from "@material-ui/lab/TreeView";
|
||||
import TreeItem from "@material-ui/lab/TreeItem";
|
||||
|
||||
export interface NavigationTree {
|
||||
key: string;
|
||||
label: string;
|
||||
nodes?: NavigationTree[];
|
||||
id: string;
|
||||
name: string;
|
||||
children?: NavigationTree[];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
data: NavigationTree[]
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: 110,
|
||||
flexGrow: 1,
|
||||
maxWidth: 400,
|
||||
},
|
||||
});
|
||||
|
||||
export function RecursiveTreeView({ data }: Props) {
|
||||
const classes = useStyles();
|
||||
|
||||
const renderTree = (nodes: NavigationTree[]) => {
|
||||
return nodes.map(node => (
|
||||
<TreeItem key={node.id} nodeId={node.id} label={node.name}>
|
||||
{Array.isArray(node.children) ? node.children.map((node) => renderTree([node])) : null}
|
||||
</TreeItem>
|
||||
));
|
||||
};
|
||||
|
||||
return (
|
||||
<TreeMenu
|
||||
data={data}
|
||||
hasSearch={false}
|
||||
initialActiveKey="application/appearance"
|
||||
resetOpenNodesOnDataUpdate={true}
|
||||
debounceTime={125}
|
||||
/>
|
||||
<TreeView
|
||||
className={classes.root}
|
||||
defaultCollapseIcon={<Icon material="expand_more"/>}
|
||||
defaultExpandIcon={<Icon material="chevron_right" />}
|
||||
>
|
||||
{renderTree(data)}
|
||||
</TreeView>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user