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

Add overlay/content example #966

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
79 changes: 75 additions & 4 deletions docs/styles/transitions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Using [CSS classes](classes.md), it is possible to implement transitions for
when the modal is opened or closed. By placing the following CSS somewhere in
your project's styles, you can make the modal content fade in when it is opened
and fade out when it is closed:
when the modal is opened or closed.

#### Basic overlay styling

By placing the following CSS somewhere in your project's styles, you can make the
modal content fade in when it is opened and fade out when it is closed:

```css
.ReactModal__Overlay {
Expand All @@ -18,13 +21,14 @@ and fade out when it is closed:
}
```


The above example will apply the fade transition globally, affecting all modals
whose `afterOpen` and `beforeClose` classes have not been set via the
`className` prop. To apply the transition to one modal only, you can change
the above class names and pass an object to your modal's `className` prop as
described in the [previous section](classes.md).

#### Gracefully closing the modal

In order for the fade transition to work, you need to inform the `<Modal />` about the transition time required for the animation.

Like this
Expand Down Expand Up @@ -72,6 +76,73 @@ Instead of this
}
```

#### Styling the overlay and content

It is possible to independently style the transitions for the modal
overlay and modal content.

Keep in mind that inline styles will take precedence over those defined
as CSS rules. In case you need to use both at the same time, you'll need to use the css `!important`.

The example below will fade the overlay
in and slide the modal content on-screen from the bottom of the page:

```javascript
{
<Modal
style={{
overlay: { background: 'rgba(0, 0, 0, 0.3)' },
content: {
top: '50%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
// transform: 'translate(-50%, -50%)', if you use inline styles instead of css
},
}}
closeTimeoutMS={800}
isOpen={this.state.showModal}
contentLabel="modal"
onRequestClose={() => this.toggleModal()}
>
<h2>Add modal content here</h2>
</Modal>
}
```

Corresponding CSS:

```css
.ReactModal__Overlay {
opacity: 0;
transition: opacity 800ms ease-in-out;
}

.ReactModal__Overlay--after-open{
opacity: 1;
}

.ReactModal__Overlay--before-close{
opacity: 0;
}

.ReactModal__Content {
transform: translate(-50%, 150%);
transition: transform 800ms ease-in-out;
}

.ReactModal__Content--after-open {
transform: translate(-50%, -50%);
}

.ReactModal__Content--before-close {
transform: translate(-50%, 150%);
}
```

#### Notes

React Modal has adopted the [stable Portal API](https://reactjs.org/docs/portals.html) as exposed in React 16.

And `createProtal` API from React 16 [no longer allow](https://github.com/facebook/react/issues/10826#issuecomment-355719729) developers to intervene the unmounting of the portal component.