Skip to content
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

[Dialog] Fix animated dialog warning #786

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/dialog/examples/animated.example.js
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" };
83 changes: 46 additions & 37 deletions website/src/pages/dialog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -518,46 +518,55 @@ If you'd like to animate the content, give [React Spring](https://github.com/drc

```jsx
// jsx-demo
function Example(props) {
(() => {
const AnimatedDialogOverlay = animated(DialogOverlay);
const AnimatedDialogContent = animated(DialogContent);
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 style={{ opacity: styles.opacity }}>
<AnimatedDialogContent
style={{
transform: styles.y.interpolate(
(value) => `translate3d(0px, ${value}px, 0px)`
),
border: "4px solid hsla(0, 0%, 0%, 0.5)",
borderRadius: 10,
}}

function Example(props) {
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 }}
>
<button onClick={() => setShowDialog(false)}>
Close Dialog
</button>
<p>React Spring makes it too easy!</p>
<input type="text" />
<br />
<input type="text" />
<button>Ayyyyyy</button>
</AnimatedDialogContent>
</AnimatedDialogOverlay>
)
)}
</div>
);
}
<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>
);
}
return <Example />;
})();
```

## Accessibility
Expand Down