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.
[docs] Unify Tree View
apiRef
methods doc examples (mui#13193)
Signed-off-by: Flavien DELANGLE <[email protected]> Co-authored-by: Michel Engelen <[email protected]>
- Loading branch information
1 parent
8ea4839
commit 3c3f226
Showing
20 changed files
with
249 additions
and
31 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
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
File renamed without changes.
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
File renamed without changes.
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
56 changes: 56 additions & 0 deletions
56
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItem.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,56 @@ | ||
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' }, | ||
], | ||
}, | ||
]; | ||
|
||
export default function ApiMethodGetItem() { | ||
const apiRef = useTreeViewApiRef(); | ||
const [selectedItem, setSelectedItem] = React.useState(null); | ||
|
||
const handleSelectedItemsChange = (event, itemId) => { | ||
if (itemId == null) { | ||
setSelectedItem(null); | ||
} else { | ||
setSelectedItem(apiRef.current.getItem(itemId)); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack spacing={2}> | ||
<Typography> | ||
Selected item: {selectedItem == null ? 'none' : selectedItem.label} | ||
</Typography> | ||
<Box sx={{ minHeight: 220, minWidth: 320, flexGrow: 1 }}> | ||
<RichTreeView | ||
items={MUI_X_PRODUCTS} | ||
apiRef={apiRef} | ||
selectedItems={selectedItem?.id ?? null} | ||
onSelectedItemsChange={handleSelectedItemsChange} | ||
/> | ||
</Box> | ||
</Stack> | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItem.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,61 @@ | ||
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' }, | ||
], | ||
}, | ||
]; | ||
|
||
export default function ApiMethodGetItem() { | ||
const apiRef = useTreeViewApiRef(); | ||
const [selectedItem, setSelectedItem] = React.useState<TreeViewBaseItem | null>( | ||
null, | ||
); | ||
|
||
const handleSelectedItemsChange = ( | ||
event: React.SyntheticEvent, | ||
itemId: string | null, | ||
) => { | ||
if (itemId == null) { | ||
setSelectedItem(null); | ||
} else { | ||
setSelectedItem(apiRef.current!.getItem(itemId)); | ||
} | ||
}; | ||
|
||
return ( | ||
<Stack spacing={2}> | ||
<Typography> | ||
Selected item: {selectedItem == null ? 'none' : selectedItem.label} | ||
</Typography> | ||
<Box sx={{ minHeight: 220, minWidth: 320, flexGrow: 1 }}> | ||
<RichTreeView | ||
items={MUI_X_PRODUCTS} | ||
apiRef={apiRef} | ||
selectedItems={selectedItem?.id ?? null} | ||
onSelectedItemsChange={handleSelectedItemsChange} | ||
/> | ||
</Box> | ||
</Stack> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
docs/data/tree-view/rich-tree-view/items/ApiMethodGetItem.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,11 @@ | ||
<Typography> | ||
Selected item: {selectedItem == null ? 'none' : selectedItem.label} | ||
</Typography> | ||
<Box sx={{ minHeight: 220, minWidth: 320, flexGrow: 1 }}> | ||
<RichTreeView | ||
items={MUI_X_PRODUCTS} | ||
apiRef={apiRef} | ||
selectedItems={selectedItem?.id ?? null} | ||
onSelectedItemsChange={handleSelectedItemsChange} | ||
/> | ||
</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
Oops, something went wrong.