|
1 | 1 | # react-css-transition
|
2 | 2 |
|
3 |
| -Take back control of CSS Transitions for React! |
4 |
| - |
5 | 3 | [![NPM Version Widget]][npm version]
|
6 | 4 | [![Build Status Widget]][build status]
|
7 | 5 | [![Coverage Widget]][coverage]
|
8 | 6 |
|
| 7 | +_React CSS Transition_ provides a reliable way to transition your components between two states across browers. |
| 8 | + |
| 9 | +[Read the full documentation](https://wikiwi.github.io/react-css-transition/) |
| 10 | + |
9 | 11 | ## Installation
|
10 | 12 |
|
11 | 13 | ```sh
|
12 | 14 | npm install react-css-transition --save
|
13 | 15 | ```
|
14 | 16 |
|
| 17 | +## Features |
| 18 | + |
| 19 | +- Transition between the _default state_ and the _active state_ |
| 20 | +- Perform a reverse transition when interrupted |
| 21 | +- Define transitions using inline styles or CSS classes |
| 22 | +- Transition components when entering or leaving the DOM |
| 23 | +- Notifiy when a transition has finished |
| 24 | +- Support the application of initial values before a transition |
| 25 | +- Includes typescript definitions |
| 26 | + |
| 27 | +## Examples |
| 28 | + |
| 29 | +A component that fades in when props changes to `active=true` and fades out when `active=false`: |
| 30 | + |
| 31 | +```js |
| 32 | +import * as React from "react"; |
| 33 | +import { CSSTransition, transit } from "react-css-transition"; |
| 34 | + |
| 35 | +const FadeInOutComponent = ({active, ...rest}) => ( |
| 36 | + <CSSTransition |
| 37 | + defaultStyle={{ opacity: 0 }} |
| 38 | + enterStyle={{ opacity: transit(1.0, 500, "ease-in-out") }} |
| 39 | + leaveStyle={{ opacity: transit(0, 500, "ease-in-out") }} |
| 40 | + activeStyle={{ opacity: 1.0 }} |
| 41 | + active={props.active} |
| 42 | + > |
| 43 | + <MyComponent {...rest} /> |
| 44 | + </CSSTransition> |
| 45 | +); |
| 46 | +``` |
| 47 | + |
| 48 | +A transition group that fades in and out its children: |
| 49 | + |
| 50 | +```js |
| 51 | +import { CSSTransitionGroup, CSSTransition, transit } from "react-css-transition"; |
| 52 | + |
| 53 | +const FadeInOut = (props) => ( |
| 54 | + <CSSTransition |
| 55 | + {...props} |
| 56 | + defaultStyle={{ opacity: 0 }} |
| 57 | + enterStyle={{ opacity: transit(1.0, 500, "ease-in-out") }} |
| 58 | + leaveStyle={{ opacity: transit(0, 500, "ease-in-out") }} |
| 59 | + activeStyle={{ opacity: 1.0 }} |
| 60 | + /> |
| 61 | +); |
| 62 | + |
| 63 | +const FadeInOutGroup = (props) => ( |
| 64 | + <CSSTransitionGroup {...props}> |
| 65 | + { |
| 66 | + React.Children.map( |
| 67 | + props.children, |
| 68 | + (child) => <FadeInOut>{child}</FadeInOut>, |
| 69 | + ) |
| 70 | + } |
| 71 | + </CSSTransitionGroup> |
| 72 | +); |
| 73 | +``` |
| 74 | + |
| 75 | +## License |
| 76 | + |
| 77 | +MIT |
| 78 | + |
15 | 79 |
|
16 | 80 | [npm version]: https://www.npmjs.com/package/react-css-transition
|
17 | 81 |
|
|
0 commit comments