forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TreeView] Add
getItemTree
and getItemOrderedChildrenIds
methods …
…to the public API (mui#13804)
- Loading branch information
1 parent
2157520
commit f4163a8
Showing
17 changed files
with
488 additions
and
23 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItemOrderedChildrenIds.js
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,68 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
|
||
import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | ||
|
||
const MUI_X_PRODUCTS = [ | ||
{ | ||
id: 'grid', | ||
label: 'Data Grid', | ||
children: [ | ||
{ id: 'grid-community', label: '@mui/x-data-grid' }, | ||
{ id: 'grid-pro', label: '@mui/x-data-grid-pro' }, | ||
{ id: 'grid-premium', label: '@mui/x-data-grid-premium' }, | ||
], | ||
}, | ||
{ | ||
id: 'pickers', | ||
label: 'Date and Time Pickers', | ||
children: [ | ||
{ id: 'pickers-community', label: '@mui/x-date-pickers' }, | ||
{ id: 'pickers-pro', label: '@mui/x-date-pickers-pro' }, | ||
], | ||
}, | ||
{ | ||
id: 'charts', | ||
label: 'Charts', | ||
children: [{ id: 'charts-community', label: '@mui/x-charts' }], | ||
}, | ||
{ | ||
id: 'tree-view', | ||
label: 'Tree View', | ||
children: [{ id: 'tree-view-community', label: '@mui/x-tree-view' }], | ||
}, | ||
]; | ||
|
||
export default function ApiMethodGetItemOrderedChildrenIds() { | ||
const apiRef = useTreeViewApiRef(); | ||
const [isSelectedItemLeaf, setIsSelectedItemLeaf] = React.useState(null); | ||
|
||
const handleSelectedItemsChange = (event, itemId) => { | ||
if (itemId == null) { | ||
setIsSelectedItemLeaf(null); | ||
} else { | ||
const children = apiRef.current.getItemOrderedChildrenIds(itemId); | ||
setIsSelectedItemLeaf(children.length === 0); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack spacing={2}> | ||
<Typography> | ||
{isSelectedItemLeaf == null && 'No item selected'} | ||
{isSelectedItemLeaf === true && 'The selected item is a leaf'} | ||
{isSelectedItemLeaf === false && 'The selected item is a node with children'} | ||
</Typography> | ||
<Box sx={{ minHeight: 352, minWidth: 300 }}> | ||
<RichTreeView | ||
items={MUI_X_PRODUCTS} | ||
apiRef={apiRef} | ||
onSelectedItemsChange={handleSelectedItemsChange} | ||
/> | ||
</Box> | ||
</Stack> | ||
); | ||
} |
73 changes: 73 additions & 0 deletions
73
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItemOrderedChildrenIds.tsx
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,73 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
import { TreeViewBaseItem } from '@mui/x-tree-view/models'; | ||
import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | ||
|
||
const MUI_X_PRODUCTS: TreeViewBaseItem[] = [ | ||
{ | ||
id: 'grid', | ||
label: 'Data Grid', | ||
children: [ | ||
{ id: 'grid-community', label: '@mui/x-data-grid' }, | ||
{ id: 'grid-pro', label: '@mui/x-data-grid-pro' }, | ||
{ id: 'grid-premium', label: '@mui/x-data-grid-premium' }, | ||
], | ||
}, | ||
{ | ||
id: 'pickers', | ||
label: 'Date and Time Pickers', | ||
children: [ | ||
{ id: 'pickers-community', label: '@mui/x-date-pickers' }, | ||
{ id: 'pickers-pro', label: '@mui/x-date-pickers-pro' }, | ||
], | ||
}, | ||
{ | ||
id: 'charts', | ||
label: 'Charts', | ||
children: [{ id: 'charts-community', label: '@mui/x-charts' }], | ||
}, | ||
{ | ||
id: 'tree-view', | ||
label: 'Tree View', | ||
children: [{ id: 'tree-view-community', label: '@mui/x-tree-view' }], | ||
}, | ||
]; | ||
|
||
export default function ApiMethodGetItemOrderedChildrenIds() { | ||
const apiRef = useTreeViewApiRef(); | ||
const [isSelectedItemLeaf, setIsSelectedItemLeaf] = React.useState<boolean | null>( | ||
null, | ||
); | ||
|
||
const handleSelectedItemsChange = ( | ||
event: React.SyntheticEvent, | ||
itemId: string | null, | ||
) => { | ||
if (itemId == null) { | ||
setIsSelectedItemLeaf(null); | ||
} else { | ||
const children = apiRef.current!.getItemOrderedChildrenIds(itemId); | ||
setIsSelectedItemLeaf(children.length === 0); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack spacing={2}> | ||
<Typography> | ||
{isSelectedItemLeaf == null && 'No item selected'} | ||
{isSelectedItemLeaf === true && 'The selected item is a leaf'} | ||
{isSelectedItemLeaf === false && 'The selected item is a node with children'} | ||
</Typography> | ||
<Box sx={{ minHeight: 352, minWidth: 300 }}> | ||
<RichTreeView | ||
items={MUI_X_PRODUCTS} | ||
apiRef={apiRef} | ||
onSelectedItemsChange={handleSelectedItemsChange} | ||
/> | ||
</Box> | ||
</Stack> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItemOrderedChildrenIds.tsx.preview
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,12 @@ | ||
<Typography> | ||
{isSelectedItemLeaf == null && 'No item selected'} | ||
{isSelectedItemLeaf === true && 'The selected item is a leaf'} | ||
{isSelectedItemLeaf === false && 'The selected item is a node with children'} | ||
</Typography> | ||
<Box sx={{ minHeight: 352, minWidth: 300 }}> | ||
<RichTreeView | ||
items={MUI_X_PRODUCTS} | ||
apiRef={apiRef} | ||
onSelectedItemsChange={handleSelectedItemsChange} | ||
/> | ||
</Box> |
66 changes: 66 additions & 0 deletions
66
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItemTree.js
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,66 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
import Typography from '@mui/material/Typography'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
|
||
import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | ||
|
||
const MUI_X_PRODUCTS = [ | ||
{ | ||
id: 'grid', | ||
label: 'Data Grid', | ||
children: [ | ||
{ id: 'grid-community', label: '@mui/x-data-grid' }, | ||
{ id: 'grid-pro', label: '@mui/x-data-grid-pro' }, | ||
{ id: 'grid-premium', label: '@mui/x-data-grid-premium' }, | ||
], | ||
}, | ||
{ | ||
id: 'pickers', | ||
label: 'Date and Time Pickers', | ||
children: [ | ||
{ id: 'pickers-community', label: '@mui/x-date-pickers' }, | ||
{ id: 'pickers-pro', label: '@mui/x-date-pickers-pro' }, | ||
], | ||
}, | ||
{ | ||
id: 'charts', | ||
label: 'Charts', | ||
children: [{ id: 'charts-community', label: '@mui/x-charts' }], | ||
}, | ||
{ | ||
id: 'tree-view', | ||
label: 'Tree View', | ||
children: [{ id: 'tree-view-community', label: '@mui/x-tree-view' }], | ||
}, | ||
]; | ||
|
||
export default function ApiMethodGetItemTree() { | ||
const apiRef = useTreeViewApiRef(); | ||
|
||
const [items, setItems] = React.useState(MUI_X_PRODUCTS); | ||
const [itemOnTop, setItemOnTop] = React.useState(items[0].label); | ||
|
||
const handleInvertItems = () => { | ||
setItems((prevItems) => [...prevItems].reverse()); | ||
}; | ||
|
||
const handleUpdateItemOnTop = () => { | ||
setItemOnTop(apiRef.current.getItemTree()[0].label); | ||
}; | ||
|
||
return ( | ||
<Stack spacing={2}> | ||
<Stack direction="row" spacing={2}> | ||
<Button onClick={handleInvertItems}>Invert first tree</Button> | ||
<Button onClick={handleUpdateItemOnTop}>Update item on top</Button> | ||
</Stack> | ||
<Typography>Item on top: {itemOnTop}</Typography> | ||
<Box sx={{ minHeight: 352, minWidth: 300 }}> | ||
<RichTreeView apiRef={apiRef} items={items} /> | ||
</Box> | ||
</Stack> | ||
); | ||
} |
66 changes: 66 additions & 0 deletions
66
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItemTree.tsx
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,66 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
import Typography from '@mui/material/Typography'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
import { TreeViewBaseItem } from '@mui/x-tree-view/models'; | ||
import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | ||
|
||
const MUI_X_PRODUCTS: TreeViewBaseItem[] = [ | ||
{ | ||
id: 'grid', | ||
label: 'Data Grid', | ||
children: [ | ||
{ id: 'grid-community', label: '@mui/x-data-grid' }, | ||
{ id: 'grid-pro', label: '@mui/x-data-grid-pro' }, | ||
{ id: 'grid-premium', label: '@mui/x-data-grid-premium' }, | ||
], | ||
}, | ||
{ | ||
id: 'pickers', | ||
label: 'Date and Time Pickers', | ||
children: [ | ||
{ id: 'pickers-community', label: '@mui/x-date-pickers' }, | ||
{ id: 'pickers-pro', label: '@mui/x-date-pickers-pro' }, | ||
], | ||
}, | ||
{ | ||
id: 'charts', | ||
label: 'Charts', | ||
children: [{ id: 'charts-community', label: '@mui/x-charts' }], | ||
}, | ||
{ | ||
id: 'tree-view', | ||
label: 'Tree View', | ||
children: [{ id: 'tree-view-community', label: '@mui/x-tree-view' }], | ||
}, | ||
]; | ||
|
||
export default function ApiMethodGetItemTree() { | ||
const apiRef = useTreeViewApiRef(); | ||
|
||
const [items, setItems] = React.useState(MUI_X_PRODUCTS); | ||
const [itemOnTop, setItemOnTop] = React.useState(items[0].label); | ||
|
||
const handleInvertItems = () => { | ||
setItems((prevItems) => [...prevItems].reverse()); | ||
}; | ||
|
||
const handleUpdateItemOnTop = () => { | ||
setItemOnTop(apiRef.current!.getItemTree()[0].label); | ||
}; | ||
|
||
return ( | ||
<Stack spacing={2}> | ||
<Stack direction="row" spacing={2}> | ||
<Button onClick={handleInvertItems}>Invert first tree</Button> | ||
<Button onClick={handleUpdateItemOnTop}>Update item on top</Button> | ||
</Stack> | ||
<Typography>Item on top: {itemOnTop}</Typography> | ||
<Box sx={{ minHeight: 352, minWidth: 300 }}> | ||
<RichTreeView apiRef={apiRef} items={items} /> | ||
</Box> | ||
</Stack> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItemTree.tsx.preview
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,8 @@ | ||
<Stack direction="row" spacing={2}> | ||
<Button onClick={handleInvertItems}>Invert first tree</Button> | ||
<Button onClick={handleUpdateItemOnTop}>Update item on top</Button> | ||
</Stack> | ||
<Typography>Item on top: {itemOnTop}</Typography> | ||
<Box sx={{ minHeight: 352, minWidth: 300 }}> | ||
<RichTreeView apiRef={apiRef} items={items} /> | ||
</Box> |
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
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
Oops, something went wrong.