-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SwipeableDrawer] Add appearOffset
prop
#30763
Changes from 5 commits
58c2aef
0674c0d
895331a
5552c0c
e1d3513
c8b12c6
52dace7
9faf1bb
b8e2946
4bc395a
78fafdd
1f025f7
6bf4849
687b22f
6e5e936
e68654d
fcfcd13
c37f0af
7cdf04b
85171b5
0cb3d90
66f8626
b9311f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import SwipeableDrawer from '@mui/material/SwipeableDrawer'; | ||
import Radio from '@mui/material/Radio'; | ||
import RadioGroup from '@mui/material/RadioGroup'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import List from '@mui/material/List'; | ||
import Divider from '@mui/material/Divider'; | ||
import ListItem from '@mui/material/ListItem'; | ||
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 SwipeableDiscoveryAmount() { | ||
const [state, setState] = React.useState({ | ||
top: false, | ||
left: false, | ||
bottom: false, | ||
right: false, | ||
}); | ||
|
||
const [discoveryAmount, setDiscoveryAmount] = React.useState(20); | ||
|
||
const toggleDrawer = (anchor, open) => (event) => { | ||
if ( | ||
event && | ||
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 button key={text}> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Divider /> | ||
<List> | ||
{['All mail', 'Trash', 'Spam'].map((text, index) => ( | ||
<ListItem button key={text}> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Box> | ||
); | ||
|
||
return ( | ||
<div> | ||
<RadioGroup | ||
row | ||
name="justifyContent" | ||
aria-label="justifyContent" | ||
value={discoveryAmount} | ||
onChange={(event) => { | ||
setDiscoveryAmount(parseInt(event.target.value, 10)); | ||
}} | ||
> | ||
<FormControlLabel value={0} control={<Radio />} label="0px" /> | ||
<FormControlLabel value={20} control={<Radio />} label="20px" /> | ||
<FormControlLabel value={50} control={<Radio />} label="50px" /> | ||
<FormControlLabel value={100} control={<Radio />} label="100px" /> | ||
</RadioGroup> | ||
{['left', 'right', 'top', 'bottom'].map((anchor) => ( | ||
<React.Fragment key={anchor}> | ||
<SwipeableDrawer | ||
discoveryAmount={discoveryAmount} | ||
anchor={anchor} | ||
open={state[anchor]} | ||
onClose={toggleDrawer(anchor, false)} | ||
onOpen={toggleDrawer(anchor, true)} | ||
> | ||
{list(anchor)} | ||
</SwipeableDrawer> | ||
</React.Fragment> | ||
))} | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import SwipeableDrawer from '@mui/material/SwipeableDrawer'; | ||
import Radio from '@mui/material/Radio'; | ||
import RadioGroup from '@mui/material/RadioGroup'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import List from '@mui/material/List'; | ||
import Divider from '@mui/material/Divider'; | ||
import ListItem from '@mui/material/ListItem'; | ||
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 SwipeableDiscoveryAmount() { | ||
const [state, setState] = React.useState({ | ||
top: false, | ||
left: false, | ||
bottom: false, | ||
right: false, | ||
}); | ||
const [discoveryAmount, setDiscoveryAmount] = React.useState(20); | ||
|
||
const toggleDrawer = | ||
(anchor: Anchor, open: boolean) => | ||
(event: React.KeyboardEvent | React.MouseEvent) => { | ||
if ( | ||
event && | ||
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 button key={text}> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
<Divider /> | ||
<List> | ||
{['All mail', 'Trash', 'Spam'].map((text, index) => ( | ||
<ListItem button key={text}> | ||
<ListItemIcon> | ||
{index % 2 === 0 ? <InboxIcon /> : <MailIcon />} | ||
</ListItemIcon> | ||
<ListItemText primary={text} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Box> | ||
); | ||
|
||
return ( | ||
<div> | ||
<RadioGroup | ||
row | ||
name="justifyContent" | ||
aria-label="justifyContent" | ||
value={discoveryAmount} | ||
onChange={(event) => { | ||
setDiscoveryAmount(parseInt((event.target as HTMLInputElement).value, 10)); | ||
}} | ||
> | ||
<FormControlLabel value={0} control={<Radio />} label="0px" /> | ||
<FormControlLabel value={20} control={<Radio />} label="20px" /> | ||
<FormControlLabel value={50} control={<Radio />} label="50px" /> | ||
<FormControlLabel value={100} control={<Radio />} label="100px" /> | ||
</RadioGroup> | ||
{(['left', 'right', 'top', 'bottom'] as const).map((anchor) => ( | ||
<React.Fragment key={anchor}> | ||
<SwipeableDrawer | ||
discoveryAmount={discoveryAmount} | ||
anchor={anchor} | ||
open={state[anchor]} | ||
onClose={toggleDrawer(anchor, false)} | ||
onOpen={toggleDrawer(anchor, true)} | ||
> | ||
{list(anchor)} | ||
</SwipeableDrawer> | ||
</React.Fragment> | ||
))} | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,16 @@ const iOS = | |
<SwipeableDrawer disableBackdropTransition={!iOS} disableDiscovery={iOS} />; | ||
``` | ||
|
||
### Drawer Discovery | ||
|
||
You can make the drawer appear slightly when the user touches the screen near where the drawer is located. | ||
|
||
The amount the drawer appears by can be configured using `discoveryAmount`, and it can be disabled using `disableDiscovery`. | ||
|
||
If you are on mobile, you can click near the edge of the screen to discover the drawers. | ||
|
||
{{"demo": "pages/components/drawers/SwipeableDiscoveryAmount.js"}} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a note that the demo only works on the mobile viewport? Also, I try to play this feature in iOS chrome but it does not work (Swipe on the left seems to navigate to the previous page instead). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that's because disableDiscovery is disabled by default on iOS, so it wont work. |
||
### Swipeable edge | ||
|
||
You can configure the `SwipeableDrawer` to have a visible edge when closed. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only need to edit
drawers.md
and this file will be translated later.