Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 10, 2020
1 parent b0b0c16 commit 38fbdec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
19 changes: 4 additions & 15 deletions docs/src/pages/components/tree-view/RecursiveTreeView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import TreeView from '@material-ui/lab/TreeView';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
Expand All @@ -21,7 +20,6 @@ const data = {
{
id: '4',
name: 'Child - 4',
children: null,
},
],
},
Expand All @@ -36,23 +34,14 @@ const useStyles = makeStyles({
},
});

function renderTree(nodes) {
return (
export default function RecursiveTreeView() {
const classes = useStyles();

const renderTree = nodes => (
<TreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}>
{Array.isArray(nodes.children) ? nodes.children.map(node => renderTree(node)) : null}
</TreeItem>
);
}

renderTree.propTypes = {
children: PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.arrayOf(PropTypes.object)])
.isRequired,
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};

export default function RecursiveTreeView() {
const classes = useStyles();

return (
<TreeView
Expand Down
17 changes: 7 additions & 10 deletions docs/src/pages/components/tree-view/RecursiveTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import TreeItem from '@material-ui/lab/TreeItem';

interface TreeRenderProps {
interface RenderTree {
id: string;
name: string;
children: TreeRenderProps[] | null;
children?: RenderTree[];
}

const data: TreeRenderProps = {
const data: RenderTree = {
id: 'root',
name: 'Parent',
children: [
Expand All @@ -26,7 +26,6 @@ const data: TreeRenderProps = {
{
id: '4',
name: 'Child - 4',
children: null,
},
],
},
Expand All @@ -41,16 +40,14 @@ const useStyles = makeStyles({
},
});

function renderTree(nodes: TreeRenderProps) {
return (
export default function RecursiveTreeView() {
const classes = useStyles();

const renderTree = (nodes: RenderTree) => (
<TreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}>
{Array.isArray(nodes.children) ? nodes.children.map(node => renderTree(node)) : null}
</TreeItem>
);
}

export default function RecursiveTreeView() {
const classes = useStyles();

return (
<TreeView
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/tree-view/tree-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ The tree view also offers a controlled API.

## Rich object

While the `TreeView`/`TreeItem` component API is great to maximize flexibility, an extra step is needed to handle a rich object.
While the `TreeView`/`TreeItem` component API maximizes flexibility, an extra step is needed to handle a rich object.

Let's consider a data variable with the following shape, a recursion can be used to handle it.
Let's consider a data variable with the following shape, recursion can be used to handle it.

```js
const data = {
Expand Down

0 comments on commit 38fbdec

Please sign in to comment.