-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Improve the Popper demos to be more selling
- Loading branch information
1 parent
ddece9b
commit 89135f2
Showing
11 changed files
with
250 additions
and
164 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Popper from '@material-ui/core/Popper'; | ||
import { useSpring, animated } from 'react-spring'; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
paper: { | ||
border: '1px solid', | ||
padding: theme.spacing(1), | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
const Fade = React.forwardRef(function Fade(props, ref) { | ||
const { in: open, children, onEnter, onExited, ...other } = props; | ||
const style = useSpring({ | ||
from: { opacity: 0 }, | ||
to: { opacity: open ? 1 : 0 }, | ||
onStart: () => { | ||
if (open && onEnter) { | ||
onEnter(); | ||
} | ||
}, | ||
onRest: () => { | ||
if (!open && onExited) { | ||
onExited(); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<animated.div ref={ref} style={style} {...other}> | ||
{children} | ||
</animated.div> | ||
); | ||
}); | ||
|
||
export default function SpringPopper() { | ||
const classes = useStyles(); | ||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
|
||
const handleClick = event => { | ||
setAnchorEl(anchorEl ? null : event.currentTarget); | ||
}; | ||
|
||
const open = Boolean(anchorEl); | ||
const id = open ? 'spring-popper' : undefined; | ||
|
||
return ( | ||
<div> | ||
<button aria-describedby={id} type="button" onClick={handleClick}> | ||
Toggle Popper | ||
</button> | ||
<Popper id={id} open={open} anchorEl={anchorEl} transition> | ||
{({ TransitionProps }) => ( | ||
<Fade {...TransitionProps} timeout={350}> | ||
<div className={classes.paper}>The content of the Popper.</div> | ||
</Fade> | ||
)} | ||
</Popper> | ||
</div> | ||
); | ||
} |
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,73 @@ | ||
import React from 'react'; | ||
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'; | ||
import Popper from '@material-ui/core/Popper'; | ||
import { useSpring, animated } from 'react-spring'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
paper: { | ||
border: '1px solid', | ||
padding: theme.spacing(1), | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
}), | ||
); | ||
|
||
interface FadeProps { | ||
children: React.ReactElement; | ||
in: boolean; | ||
onEnter?: () => {}; | ||
onExited?: () => {}; | ||
} | ||
|
||
const Fade = React.forwardRef<HTMLDivElement, FadeProps>(function Fade(props, ref) { | ||
const { in: open, children, onEnter, onExited, ...other } = props; | ||
const style = useSpring({ | ||
from: { opacity: 0 }, | ||
to: { opacity: open ? 1 : 0 }, | ||
onStart: () => { | ||
if (open && onEnter) { | ||
onEnter(); | ||
} | ||
}, | ||
onRest: () => { | ||
if (!open && onExited) { | ||
onExited(); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<animated.div ref={ref} style={style} {...other}> | ||
{children} | ||
</animated.div> | ||
); | ||
}); | ||
|
||
|
||
export default function SpringPopper() { | ||
const classes = useStyles(); | ||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(anchorEl ? null : event.currentTarget); | ||
}; | ||
|
||
const open = Boolean(anchorEl); | ||
const id = open ? 'spring-popper' : undefined; | ||
|
||
return ( | ||
<div> | ||
<button aria-describedby={id} type="button" onClick={handleClick}> | ||
Toggle Popper | ||
</button> | ||
<Popper id={id} open={open} anchorEl={anchorEl} transition> | ||
{({ TransitionProps }) => ( | ||
<Fade {...TransitionProps} timeout={350}> | ||
<div className={classes.paper}>The content of the Popper.</div> | ||
</Fade> | ||
)} | ||
</Popper> | ||
</div> | ||
); | ||
} |
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 React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Popper from '@material-ui/core/Popper'; | ||
|
||
import Fade from '@material-ui/core/Fade'; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
paper: { | ||
border: '1px solid', | ||
padding: theme.spacing(1), | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
})); | ||
|
||
export default function TransitionsPopper() { | ||
const classes = useStyles(); | ||
const [anchorEl, setAnchorEl] = React.useState(null); | ||
|
||
const handleClick = event => { | ||
setAnchorEl(anchorEl ? null : event.currentTarget); | ||
}; | ||
|
||
const open = Boolean(anchorEl); | ||
const id = open ? 'transitions-popper' : undefined; | ||
|
||
return ( | ||
<div> | ||
<button aria-describedby={id} type="button" onClick={handleClick}> | ||
Toggle Popper | ||
</button> | ||
<Popper id={id} open={open} anchorEl={anchorEl} transition> | ||
{({ TransitionProps }) => ( | ||
<Fade {...TransitionProps} timeout={350}> | ||
<div className={classes.paper}>The content of the Popper.</div> | ||
</Fade> | ||
)} | ||
</Popper> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.