diff --git a/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.js b/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.js index 01ede3560ce286..416a08548341db 100644 --- a/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.js +++ b/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.js @@ -1,4 +1,5 @@ import React from 'react'; +import clsx from 'clsx'; import { makeStyles } from '@material-ui/core/styles'; import SwipeableDrawer from '@material-ui/core/SwipeableDrawer'; import Button from '@material-ui/core/Button'; @@ -28,47 +29,22 @@ export default function SwipeableTemporaryDrawer() { right: false, }); - const toggleDrawer = (side, open) => event => { + const toggleDrawer = (anchor, open) => event => { if (event && event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) { return; } - setState({ ...state, [side]: open }); + setState({ ...state, [anchor]: open }); }; - const sideList = side => ( + const list = anchor => (
- - {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - - - - {['All mail', 'Trash', 'Spam'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - -
- ); - - const fullList = side => ( -
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( @@ -92,41 +68,19 @@ export default function SwipeableTemporaryDrawer() { return (
- - - - - - {sideList('left')} - - - {fullList('top')} - - - {fullList('bottom')} - - - {sideList('right')} - + {['left', 'right', 'top', 'bottom'].map(anchor => ( + + + + {list(anchor)} + + + ))}
); } diff --git a/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.tsx b/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.tsx index 4494b62210ac4e..ab5019b10d4cc8 100644 --- a/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.tsx +++ b/docs/src/pages/components/drawers/SwipeableTemporaryDrawer.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import clsx from 'clsx'; import { makeStyles } from '@material-ui/core/styles'; import SwipeableDrawer from '@material-ui/core/SwipeableDrawer'; import Button from '@material-ui/core/Button'; @@ -19,6 +20,8 @@ const useStyles = makeStyles({ }, }); +type Anchor = 'top' | 'left' | 'bottom' | 'right'; + export default function SwipeableTemporaryDrawer() { const classes = useStyles(); const [state, setState] = React.useState({ @@ -28,8 +31,7 @@ export default function SwipeableTemporaryDrawer() { right: false, }); - type DrawerSide = 'top' | 'left' | 'bottom' | 'right'; - const toggleDrawer = (side: DrawerSide, open: boolean) => ( + const toggleDrawer = (anchor: Anchor, open: boolean) => ( event: React.KeyboardEvent | React.MouseEvent, ) => { if ( @@ -41,42 +43,17 @@ export default function SwipeableTemporaryDrawer() { return; } - setState({ ...state, [side]: open }); + setState({ ...state, [anchor]: open }); }; - const sideList = (side: DrawerSide) => ( -
- - {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - - - - {['All mail', 'Trash', 'Spam'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - -
- ); - - const fullList = (side: DrawerSide) => ( + const list = (anchor: Anchor) => (
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( @@ -100,41 +77,19 @@ export default function SwipeableTemporaryDrawer() { return (
- - - - - - {sideList('left')} - - - {fullList('top')} - - - {fullList('bottom')} - - - {sideList('right')} - + {(['left', 'right', 'top', 'bottom'] as Anchor[]).map(anchor => ( + + + + {list(anchor)} + + + ))}
); } diff --git a/docs/src/pages/components/drawers/TemporaryDrawer.js b/docs/src/pages/components/drawers/TemporaryDrawer.js index 790aa1bc0bdc06..5b732909c221d0 100644 --- a/docs/src/pages/components/drawers/TemporaryDrawer.js +++ b/docs/src/pages/components/drawers/TemporaryDrawer.js @@ -1,4 +1,5 @@ import React from 'react'; +import clsx from 'clsx'; import { makeStyles } from '@material-ui/core/styles'; import Drawer from '@material-ui/core/Drawer'; import Button from '@material-ui/core/Button'; @@ -28,47 +29,22 @@ export default function TemporaryDrawer() { right: false, }); - const toggleDrawer = (side, open) => event => { + const toggleDrawer = (anchor, open) => event => { if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) { return; } - setState({ ...state, [side]: open }); + setState({ ...state, [anchor]: open }); }; - const sideList = side => ( + const list = anchor => (
- - {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - - - - {['All mail', 'Trash', 'Spam'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - -
- ); - - const fullList = side => ( -
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( @@ -92,22 +68,14 @@ export default function TemporaryDrawer() { return (
- - - - - - {sideList('left')} - - - {fullList('top')} - - - {fullList('bottom')} - - - {sideList('right')} - + {['left', 'right', 'top', 'bottom'].map(anchor => ( + + + + {list(anchor)} + + + ))}
); } diff --git a/docs/src/pages/components/drawers/TemporaryDrawer.tsx b/docs/src/pages/components/drawers/TemporaryDrawer.tsx index 515d56d6447d34..0bf2584b11d595 100644 --- a/docs/src/pages/components/drawers/TemporaryDrawer.tsx +++ b/docs/src/pages/components/drawers/TemporaryDrawer.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import clsx from 'clsx'; import { makeStyles } from '@material-ui/core/styles'; import Drawer from '@material-ui/core/Drawer'; import Button from '@material-ui/core/Button'; @@ -19,6 +20,8 @@ const useStyles = makeStyles({ }, }); +type Anchor = 'top' | 'left' | 'bottom' | 'right'; + export default function TemporaryDrawer() { const classes = useStyles(); const [state, setState] = React.useState({ @@ -28,8 +31,7 @@ export default function TemporaryDrawer() { right: false, }); - type DrawerSide = 'top' | 'left' | 'bottom' | 'right'; - const toggleDrawer = (side: DrawerSide, open: boolean) => ( + const toggleDrawer = (anchor: Anchor, open: boolean) => ( event: React.KeyboardEvent | React.MouseEvent, ) => { if ( @@ -40,42 +42,17 @@ export default function TemporaryDrawer() { return; } - setState({ ...state, [side]: open }); + setState({ ...state, [anchor]: open }); }; - const sideList = (side: DrawerSide) => ( -
- - {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - - - - {['All mail', 'Trash', 'Spam'].map((text, index) => ( - - {index % 2 === 0 ? : } - - - ))} - -
- ); - - const fullList = (side: DrawerSide) => ( + const list = (anchor: Anchor) => (
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => ( @@ -99,22 +76,14 @@ export default function TemporaryDrawer() { return (
- - - - - - {sideList('left')} - - - {fullList('top')} - - - {fullList('bottom')} - - - {sideList('right')} - + {(['left', 'right', 'top', 'bottom'] as Anchor[]).map(anchor => ( + + + + {list(anchor)} + + + ))}
); } diff --git a/docs/src/pages/components/drawers/drawers.md b/docs/src/pages/components/drawers/drawers.md index 13ffac584020ce..af75b1878a25bd 100644 --- a/docs/src/pages/components/drawers/drawers.md +++ b/docs/src/pages/components/drawers/drawers.md @@ -20,7 +20,7 @@ It closes when an item is selected, handled by controlling the `open` prop. {{"demo": "pages/components/drawers/TemporaryDrawer.js"}} -## Swipeable Temporary drawer +### Swipeable You can make the drawer swipeable with the `SwipeableDrawer` component.