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] Automatic parents and children selection (mui#14899)
- Loading branch information
1 parent
5febda9
commit 0ffbbe8
Showing
35 changed files
with
802 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { TreeViewBaseItem } from '@mui/x-tree-view/models'; | ||
|
||
export const EMPLOYEES_DATASET: TreeViewBaseItem[] = [ | ||
{ | ||
id: '0', | ||
label: 'Sarah', | ||
}, | ||
{ | ||
id: '1', | ||
label: 'Thomas', | ||
children: [ | ||
{ id: '2', label: 'Robert' }, | ||
{ id: '3', label: 'Karen' }, | ||
{ id: '4', label: 'Nancy' }, | ||
{ id: '5', label: 'Daniel' }, | ||
{ id: '6', label: 'Christopher' }, | ||
{ id: '7', label: 'Donald' }, | ||
], | ||
}, | ||
{ | ||
id: '8', | ||
label: 'Mary', | ||
children: [ | ||
{ | ||
id: '9', | ||
label: 'Jennifer', | ||
children: [{ id: '10', label: 'Anna' }], | ||
}, | ||
{ id: '11', label: 'Michael' }, | ||
{ | ||
id: '12', | ||
label: 'Linda', | ||
children: [ | ||
{ id: '13', label: 'Elizabeth' }, | ||
{ id: '14', label: 'William' }, | ||
], | ||
}, | ||
], | ||
}, | ||
]; |
98 changes: 0 additions & 98 deletions
98
docs/data/tree-view/rich-tree-view/selection/ParentChildrenSelectionRelationship.js
This file was deleted.
Oops, something went wrong.
106 changes: 0 additions & 106 deletions
106
docs/data/tree-view/rich-tree-view/selection/ParentChildrenSelectionRelationship.tsx
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
docs/data/tree-view/rich-tree-view/selection/ParentChildrenSelectionRelationship.tsx.preview
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
docs/data/tree-view/rich-tree-view/selection/SelectionPropagation.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,59 @@ | ||
import * as React from 'react'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Checkbox from '@mui/material/Checkbox'; | ||
import Stack from '@mui/material/Stack'; | ||
import Box from '@mui/material/Box'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
|
||
import { EMPLOYEES_DATASET } from '../../datasets/employees'; | ||
|
||
export default function SelectionPropagation() { | ||
const [selectionPropagation, setSelectionPropagation] = React.useState({ | ||
parents: true, | ||
descendants: true, | ||
}); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<Stack direction="row" spacing={2}> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={selectionPropagation.descendants} | ||
onChange={(event) => | ||
setSelectionPropagation((prev) => ({ | ||
...prev, | ||
descendants: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select descendants" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={selectionPropagation.parents} | ||
onChange={(event) => | ||
setSelectionPropagation((prev) => ({ | ||
...prev, | ||
parents: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select parents" | ||
/> | ||
</Stack> | ||
<Box sx={{ height: 256, minWidth: 250, overflowY: 'auto' }}> | ||
<RichTreeView | ||
items={EMPLOYEES_DATASET} | ||
checkboxSelection | ||
multiSelect | ||
selectionPropagation={selectionPropagation} | ||
defaultExpandedItems={['8', '12']} | ||
/> | ||
</Box> | ||
</div> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
docs/data/tree-view/rich-tree-view/selection/SelectionPropagation.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,60 @@ | ||
import * as React from 'react'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import Checkbox from '@mui/material/Checkbox'; | ||
import Stack from '@mui/material/Stack'; | ||
import Box from '@mui/material/Box'; | ||
import { RichTreeView } from '@mui/x-tree-view/RichTreeView'; | ||
import { TreeViewSelectionPropagation } from '@mui/x-tree-view/models'; | ||
import { EMPLOYEES_DATASET } from '../../datasets/employees'; | ||
|
||
export default function SelectionPropagation() { | ||
const [selectionPropagation, setSelectionPropagation] = | ||
React.useState<TreeViewSelectionPropagation>({ | ||
parents: true, | ||
descendants: true, | ||
}); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<Stack direction="row" spacing={2}> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={selectionPropagation.descendants} | ||
onChange={(event) => | ||
setSelectionPropagation((prev) => ({ | ||
...prev, | ||
descendants: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select descendants" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={selectionPropagation.parents} | ||
onChange={(event) => | ||
setSelectionPropagation((prev) => ({ | ||
...prev, | ||
parents: event.target.checked, | ||
})) | ||
} | ||
/> | ||
} | ||
label="Auto select parents" | ||
/> | ||
</Stack> | ||
<Box sx={{ height: 256, minWidth: 250, overflowY: 'auto' }}> | ||
<RichTreeView | ||
items={EMPLOYEES_DATASET} | ||
checkboxSelection | ||
multiSelect | ||
selectionPropagation={selectionPropagation} | ||
defaultExpandedItems={['8', '12']} | ||
/> | ||
</Box> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.