-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dialog] Fix animated dialog example to remove memory leak warning (#786
- Loading branch information
1 parent
1ee681c
commit 54764b1
Showing
2 changed files
with
104 additions
and
37 deletions.
There are no files selected for viewing
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,58 @@ | ||
import React from "react"; | ||
import { DialogOverlay, DialogContent } from "@reach/dialog"; | ||
import { animated, useTransition } from "react-spring"; | ||
import "@reach/dialog/styles.css"; | ||
|
||
let name = "Animated"; | ||
|
||
const AnimatedDialogOverlay = animated(DialogOverlay); | ||
const AnimatedDialogContent = animated(DialogContent); | ||
|
||
function Example() { | ||
const [showDialog, setShowDialog] = React.useState(false); | ||
const transitions = useTransition(showDialog, null, { | ||
from: { opacity: 0, y: -10 }, | ||
enter: { opacity: 1, y: 0 }, | ||
leave: { opacity: 0, y: 10 }, | ||
}); | ||
|
||
return ( | ||
<div> | ||
<button onClick={() => setShowDialog(true)}>Show Dialog</button> | ||
{transitions.map( | ||
({ item, key, props: styles }) => | ||
item && ( | ||
<AnimatedDialogOverlay | ||
key={key} | ||
style={{ opacity: styles.opacity }} | ||
> | ||
<AnimatedDialogContent | ||
aria-labelledby="dialog-title" | ||
style={{ | ||
transform: styles.y.interpolate( | ||
(value) => `translate3d(0px, ${value}px, 0px)` | ||
), | ||
border: "4px solid hsla(0, 0%, 0%, 0.5)", | ||
borderRadius: 10, | ||
}} | ||
> | ||
<button onClick={() => setShowDialog(false)}> | ||
Close Dialog | ||
</button> | ||
<h2 id="dialog-title">Animated Dialog</h2> | ||
<p>React Spring makes it too easy!</p> | ||
<input type="text" /> | ||
<br /> | ||
<input type="text" /> | ||
<button>Ayyyyyy</button> | ||
</AnimatedDialogContent> | ||
</AnimatedDialogOverlay> | ||
) | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
Example.story = { name }; | ||
export const Comp = Example; | ||
export default { title: "Dialog" }; |
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