-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Drawer] Add simpler demo for default behavior (#40980)
Signed-off-by: Victor Zanivan Monteiro <victorzanivan@gmail.com> Co-authored-by: Danilo Leal <67129314+danilo-leal@users.noreply.github.com>
- Loading branch information
1 parent
36db6ed
commit bd64817
Showing
7 changed files
with
213 additions
and
83 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
docs/data/material/components/drawers/AnchorTemporaryDrawer.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,81 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Drawer from '@mui/material/Drawer'; | ||
import Button from '@mui/material/Button'; | ||
import List from '@mui/material/List'; | ||
import Divider from '@mui/material/Divider'; | ||
import ListItem from '@mui/material/ListItem'; | ||
import ListItemButton from '@mui/material/ListItemButton'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import InboxIcon from '@mui/icons-material/MoveToInbox'; | ||
import MailIcon from '@mui/icons-material/Mail'; | ||
|
||
export default function AnchorTemporaryDrawer() { | ||
const [state, setState] = React.useState({ | ||
top: false, | ||
left: false, | ||
bottom: false, | ||
right: false, | ||
}); | ||
|
||
const toggleDrawer = (anchor, open) => (event) => { | ||
if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) { | ||
return; | ||
} | ||
|
||
setState({ ...state, [anchor]: open }); | ||
}; | ||
|
||
const list = (anchor) => ( | ||
<Box | ||
sx={{ width: anchor === 'top' || anchor === 'bottom' ? 'auto' : 250 }} | ||
role="presentation" | ||
onClick={toggleDrawer(anchor, false)} | ||
onKeyDown={toggleDrawer(anchor, false)} | ||
> | ||
<List> | ||
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( | ||
<ListItem key={text} disablePadding> | ||
<ListItemButton> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItemButton> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Divider /> | ||
<List> | ||
{['All mail', 'Trash', 'Spam'].map((text, index) => ( | ||
<ListItem key={text} disablePadding> | ||
<ListItemButton> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItemButton> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Box> | ||
); | ||
|
||
return ( | ||
<div> | ||
{['left', 'right', 'top', 'bottom'].map((anchor) => ( | ||
<React.Fragment key={anchor}> | ||
<Button onClick={toggleDrawer(anchor, true)}>{anchor}</Button> | ||
<Drawer | ||
anchor={anchor} | ||
open={state[anchor]} | ||
onClose={toggleDrawer(anchor, false)} | ||
> | ||
{list(anchor)} | ||
</Drawer> | ||
</React.Fragment> | ||
))} | ||
</div> | ||
); | ||
} |
89 changes: 89 additions & 0 deletions
89
docs/data/material/components/drawers/AnchorTemporaryDrawer.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,89 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Drawer from '@mui/material/Drawer'; | ||
import Button from '@mui/material/Button'; | ||
import List from '@mui/material/List'; | ||
import Divider from '@mui/material/Divider'; | ||
import ListItem from '@mui/material/ListItem'; | ||
import ListItemButton from '@mui/material/ListItemButton'; | ||
import ListItemIcon from '@mui/material/ListItemIcon'; | ||
import ListItemText from '@mui/material/ListItemText'; | ||
import InboxIcon from '@mui/icons-material/MoveToInbox'; | ||
import MailIcon from '@mui/icons-material/Mail'; | ||
|
||
type Anchor = 'top' | 'left' | 'bottom' | 'right'; | ||
|
||
export default function AnchorTemporaryDrawer() { | ||
const [state, setState] = React.useState({ | ||
top: false, | ||
left: false, | ||
bottom: false, | ||
right: false, | ||
}); | ||
|
||
const toggleDrawer = | ||
(anchor: Anchor, open: boolean) => | ||
(event: React.KeyboardEvent | React.MouseEvent) => { | ||
if ( | ||
event.type === 'keydown' && | ||
((event as React.KeyboardEvent).key === 'Tab' || | ||
(event as React.KeyboardEvent).key === 'Shift') | ||
) { | ||
return; | ||
} | ||
|
||
setState({ ...state, [anchor]: open }); | ||
}; | ||
|
||
const list = (anchor: Anchor) => ( | ||
<Box | ||
sx={{ width: anchor === 'top' || anchor === 'bottom' ? 'auto' : 250 }} | ||
role="presentation" | ||
onClick={toggleDrawer(anchor, false)} | ||
onKeyDown={toggleDrawer(anchor, false)} | ||
> | ||
<List> | ||
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( | ||
<ListItem key={text} disablePadding> | ||
<ListItemButton> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItemButton> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Divider /> | ||
<List> | ||
{['All mail', 'Trash', 'Spam'].map((text, index) => ( | ||
<ListItem key={text} disablePadding> | ||
<ListItemButton> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItemButton> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Box> | ||
); | ||
|
||
return ( | ||
<div> | ||
{(['left', 'right', 'top', 'bottom'] as const).map((anchor) => ( | ||
<React.Fragment key={anchor}> | ||
<Button onClick={toggleDrawer(anchor, true)}>{anchor}</Button> | ||
<Drawer | ||
anchor={anchor} | ||
open={state[anchor]} | ||
onClose={toggleDrawer(anchor, false)} | ||
> | ||
{list(anchor)} | ||
</Drawer> | ||
</React.Fragment> | ||
))} | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
docs/data/material/components/drawers/AnchorTemporaryDrawer.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 @@ | ||
{(['left', 'right', 'top', 'bottom'] as const).map((anchor) => ( | ||
<React.Fragment key={anchor}> | ||
<Button onClick={toggleDrawer(anchor, true)}>{anchor}</Button> | ||
<Drawer | ||
anchor={anchor} | ||
open={state[anchor]} | ||
onClose={toggleDrawer(anchor, false)} | ||
> | ||
{list(anchor)} | ||
</Drawer> | ||
</React.Fragment> | ||
))} |
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
16 changes: 4 additions & 12 deletions
16
docs/data/material/components/drawers/TemporaryDrawer.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 |
---|---|---|
@@ -1,12 +1,4 @@ | ||
{(['left', 'right', 'top', 'bottom'] as const).map((anchor) => ( | ||
<React.Fragment key={anchor}> | ||
<Button onClick={toggleDrawer(anchor, true)}>{anchor}</Button> | ||
<Drawer | ||
anchor={anchor} | ||
open={state[anchor]} | ||
onClose={toggleDrawer(anchor, false)} | ||
> | ||
{list(anchor)} | ||
</Drawer> | ||
</React.Fragment> | ||
))} | ||
<Button onClick={toggleDrawer(true)}>Open drawer</Button> | ||
<Drawer open={open} onClose={toggleDrawer(false)}> | ||
{DrawerList} | ||
</Drawer> |
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