Skip to content

Instantly share code, notes, and snippets.

@jsteenkamp
Forked from ryanflorence/foo.js
Last active August 27, 2018 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsteenkamp/1b1b1c69c653248fc000fbd0b9c2a215 to your computer and use it in GitHub Desktop.
Save jsteenkamp/1b1b1c69c653248fc000fbd0b9c2a215 to your computer and use it in GitHub Desktop.
Animation/transition using react spring
// Adds a lovely fade in of the modal
// and a gentle slide-down of the modal content
class Demo extends React.Component {
state = { showDialog: false };
render() {
return (
<div>
<button onClick={() => this.setState({ showDialog: true })}>
Show Dialog
</button>
<Transition
from={{ opacity: 0, y: -10 }}
enter={{ opacity: 1, y: 0 }}
leave={{ opacity: 0, y: 10 }}
>
{this.state.showDialog &&
(styles => (
<DialogOverlay style={{ opacity: styles.opacity }}>
<DialogContent
style={{
transform: `translate3d(0px, ${styles.y}px, 0px)`,
border: "4px solid hsla(0, 0%, 0%, 0.5)",
borderRadius: 10
}}
>
<button onClick={() => this.setState({ showDialog: false })}>
Close Dialog
</button>
<p>React Spring makes it too easy!</p>
</DialogContent>
</DialogOverlay>
))}
</Transition>
</div>
);
}
}
@jsteenkamp
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment