-
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] New API method:
setItemExpansion
(mui#12595)
Signed-off-by: Flavien DELANGLE <[email protected]> Co-authored-by: Lukas <[email protected]>
- Loading branch information
Showing
20 changed files
with
359 additions
and
29 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
docs/data/tree-view/rich-tree-view/expansion/ChangeItemExpansion.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,51 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
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 ChangeItemExpansion() { | ||
const apiRef = useTreeViewApiRef(); | ||
|
||
const handleExpandClick = (event) => { | ||
apiRef.current.setItemExpansion(event, 'grid', true); | ||
}; | ||
|
||
const handleCollapseClick = (event) => { | ||
apiRef.current.setItemExpansion(event, 'grid', false); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ flexGrow: 1, maxWidth: 400 }}> | ||
<Stack sx={{ mb: 1 }} spacing={2} direction="row"> | ||
<Button onClick={handleExpandClick}>Expand Data Grid</Button> | ||
<Button onClick={handleCollapseClick}>Collapse Data Grid</Button> | ||
</Stack> | ||
<Box sx={{ minHeight: 220, flexGrow: 1 }}> | ||
<RichTreeView items={MUI_X_PRODUCTS} apiRef={apiRef} /> | ||
</Box> | ||
</Box> | ||
); | ||
} |
51 changes: 51 additions & 0 deletions
51
docs/data/tree-view/rich-tree-view/expansion/ChangeItemExpansion.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,51 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
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 ChangeItemExpansion() { | ||
const apiRef = useTreeViewApiRef(); | ||
|
||
const handleExpandClick = (event: React.MouseEvent) => { | ||
apiRef.current!.setItemExpansion(event, 'grid', true); | ||
}; | ||
|
||
const handleCollapseClick = (event: React.MouseEvent) => { | ||
apiRef.current!.setItemExpansion(event, 'grid', false); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ flexGrow: 1, maxWidth: 400 }}> | ||
<Stack sx={{ mb: 1 }} spacing={2} direction="row"> | ||
<Button onClick={handleExpandClick}>Expand Data Grid</Button> | ||
<Button onClick={handleCollapseClick}>Collapse Data Grid</Button> | ||
</Stack> | ||
<Box sx={{ minHeight: 220, flexGrow: 1 }}> | ||
<RichTreeView items={MUI_X_PRODUCTS} apiRef={apiRef} /> | ||
</Box> | ||
</Box> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
docs/data/tree-view/rich-tree-view/expansion/ChangeItemExpansion.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,7 @@ | ||
<Stack sx={{ mb: 1 }} spacing={2} direction="row"> | ||
<Button onClick={handleExpandClick}>Expand Data Grid</Button> | ||
<Button onClick={handleCollapseClick}>Collapse Data Grid</Button> | ||
</Stack> | ||
<Box sx={{ minHeight: 220, flexGrow: 1 }}> | ||
<RichTreeView items={MUI_X_PRODUCTS} apiRef={apiRef} /> | ||
</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
41 changes: 41 additions & 0 deletions
41
docs/data/tree-view/simple-tree-view/expansion/ChangeItemExpansion.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,41 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; | ||
import { TreeItem } from '@mui/x-tree-view/TreeItem'; | ||
import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | ||
|
||
export default function ChangeItemExpansion() { | ||
const apiRef = useTreeViewApiRef(); | ||
|
||
const handleExpandClick = (event) => { | ||
apiRef.current.setItemExpansion(event, 'grid', true); | ||
}; | ||
|
||
const handleCollapseClick = (event) => { | ||
apiRef.current.setItemExpansion(event, 'grid', false); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ flexGrow: 1, maxWidth: 400 }}> | ||
<Stack sx={{ mb: 1 }} spacing={2} direction="row"> | ||
<Button onClick={handleExpandClick}>Expand Data Grid</Button> | ||
<Button onClick={handleCollapseClick}>Collapse Data Grid</Button> | ||
</Stack> | ||
<Box sx={{ minHeight: 220, flexGrow: 1 }}> | ||
<SimpleTreeView apiRef={apiRef}> | ||
<TreeItem itemId="grid" label="Data Grid"> | ||
<TreeItem itemId="grid-community" label="@mui/x-data-grid" /> | ||
<TreeItem itemId="grid-pro" label="@mui/x-data-grid-pro" /> | ||
<TreeItem itemId="grid-premium" label="@mui/x-data-grid-premium" /> | ||
</TreeItem> | ||
<TreeItem itemId="pickers" label="Date and Time Pickers"> | ||
<TreeItem itemId="pickers-community" label="@mui/x-date-pickers" /> | ||
<TreeItem itemId="pickers-pro" label="@mui/x-date-pickers-pro" /> | ||
</TreeItem> | ||
</SimpleTreeView> | ||
</Box> | ||
</Box> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
docs/data/tree-view/simple-tree-view/expansion/ChangeItemExpansion.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,41 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView'; | ||
import { TreeItem } from '@mui/x-tree-view/TreeItem'; | ||
import { useTreeViewApiRef } from '@mui/x-tree-view/hooks'; | ||
|
||
export default function ChangeItemExpansion() { | ||
const apiRef = useTreeViewApiRef(); | ||
|
||
const handleExpandClick = (event: React.MouseEvent) => { | ||
apiRef.current!.setItemExpansion(event, 'grid', true); | ||
}; | ||
|
||
const handleCollapseClick = (event: React.MouseEvent) => { | ||
apiRef.current!.setItemExpansion(event, 'grid', false); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ flexGrow: 1, maxWidth: 400 }}> | ||
<Stack sx={{ mb: 1 }} spacing={2} direction="row"> | ||
<Button onClick={handleExpandClick}>Expand Data Grid</Button> | ||
<Button onClick={handleCollapseClick}>Collapse Data Grid</Button> | ||
</Stack> | ||
<Box sx={{ minHeight: 220, flexGrow: 1 }}> | ||
<SimpleTreeView apiRef={apiRef}> | ||
<TreeItem itemId="grid" label="Data Grid"> | ||
<TreeItem itemId="grid-community" label="@mui/x-data-grid" /> | ||
<TreeItem itemId="grid-pro" label="@mui/x-data-grid-pro" /> | ||
<TreeItem itemId="grid-premium" label="@mui/x-data-grid-premium" /> | ||
</TreeItem> | ||
<TreeItem itemId="pickers" label="Date and Time Pickers"> | ||
<TreeItem itemId="pickers-community" label="@mui/x-date-pickers" /> | ||
<TreeItem itemId="pickers-pro" label="@mui/x-date-pickers-pro" /> | ||
</TreeItem> | ||
</SimpleTreeView> | ||
</Box> | ||
</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
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.