Skip to content

Commit 4800498

Browse files
author
Setsun
committed
fix(readme): update readme
1 parent 2348af4 commit 4800498

File tree

1 file changed

+89
-34
lines changed

1 file changed

+89
-34
lines changed

README.md

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,49 @@
22

33
An animation component library & higher-order component for generating easily configurable `<Transition>` components from `react-transition-group`.
44

5-
`react-transition-components` is roughly 3 kB gzipped, has peer dependencies on `react` and `react-transition-group`, and supports `webpack` tree-shaking by default: https://bundlephobia.com/result?p=react-transition-components
5+
`react-transition-components` is 3 kB gzipped, has peer dependencies on `react` and `react-transition-group`, and supports `webpack` tree-shaking by default: https://bundlephobia.com/result?p=react-transition-components
66

7-
`npm i react-transition-components`
7+
```
8+
yarn install react-transition-components
9+
```
810

9-
# Motivation
10-
The drive behind `react-transition-components` comes from being able to create common transition components for React easily using the tried and true `react-transition-group`.
11+
## Motivation
1112

12-
Not only that, but these components need to be easily configurable with a simple API, and minimal context switching.
13+
`react-transition-components` has 2 goals:
14+
- Provide a component library of common lightweight UI transitions that are configurable on durations, delays, easings, and other animation values.
15+
- Make it easy to create configurable transition components by providing a `createTransition` higher-order component.
1316

14-
`react-transition-components` aims to provide a component library of common UI transitions, and to make it easier to create re-usable transition components by providing a `createTransition` higher-order component for wrapping `<Transition>` and providing a very simple API for allowing you to express a transition in **6** lines of code in the simplest case:
17+
The aforementioned `createTransition` higher-order component wraps `<Transition>` from `react-transition-group`, maintains backwards compatibility with its props, and enhances it with configurable timings, delays, and easings. It provides a concise API, allowing you to express an enter/exit CSS transition in **6** lines of code in the simplest case:
1518

1619
```jsx
1720
import { createTransition } from 'react-transition-components';
1821

19-
export const ScaleTransition = createTransition({
20-
from: { transform: 'scale(0)' },
21-
enter: { transform: 'scale(1)' }
22+
const CustomTransition = createTransition({
23+
from: { transform: 'scale(0) skew(45deg)', opacity: 0 },
24+
enter: { transform: 'scale(1) skew(0deg)', opacity: 1 }
2225
});
2326
```
2427

25-
# Components
26-
`react-transition-components` comes out of the box with multiple components that work out of the box. A Storybook is live at: https://setsun.io/react-transition-components
28+
## Component Library
29+
`react-transition-components` comes with multiple components that work out of the box. A Storybook is live at: https://setsun.io/react-transition-components
30+
31+
The following components are included, and implement the most common CSS transitions:
32+
- FadeTransition for `opacity` animations
33+
- HeightTransition for `height` animations
34+
- TranslateTransition for `translate3d` animations
35+
- ScaleTransition for `scale3d` animations
36+
- RotateTransition for `rotate3d` animations
37+
- SkewTransition for `skew` animations
38+
- ClipTransition for `clip-path` animations
39+
40+
## Higher-order component API
41+
### `createTransition(config: TransitionConfig)`
2742

28-
Additionally, all components created via `createTransition` will support all props from the `<Transition>` component from `react-transition-group` (https://reactcommunity.org/react-transition-group/transition).
43+
The `createTransition` higher-order component returns a pre-configured `<Transition>` component that allows you to create transition components that can be used immediately, and can be configured via `props` as your animation needs change.
2944

30-
The components also have extended functionality and have the following base props for customizing transition properties and timings:
45+
All components created via `createTransition` support all props from the `<Transition>` component from `react-transition-group` (https://reactcommunity.org/react-transition-group/transition).
3146

47+
These generated components also have extended functionality and have the following base props for customizing transition properties and timings:
3248
```ts
3349
type Props = {
3450
// a custom duration for your transition, with the ability
@@ -54,11 +70,7 @@ type Props = {
5470
}
5571
```
5672
57-
# API
58-
### `createTransition(config: TransitionConfig)`
59-
60-
The `createTransition` higher-order component returns a pre-configured `<Transition>` component that allows you to create transition components that can be used immediately, and can be configured via `props` as your animation needs change. `createTransition` has the following type signature:
61-
73+
`createTransition` has the following type signature:
6274
```ts
6375
type TransitionConfig = {
6476
from: React.CSSProperties | LazyCSSProperties;
@@ -70,35 +82,78 @@ type TransitionConfig = {
7082
type createTransition = (config: TransitionConfig) => React.SFC<TransitionProps>
7183
```
7284
73-
Full TypeScript typings can be found at: https://github.com/Setsun/react-transition-components/blob/master/src/types/index.ts
74-
7585
#### `from: React.CSSProperties | LazyCSSProperties`
76-
The `from` property is the starting style of your transition component. This is the state where your component animation will start. If the `exit` property is not specified, this is also the style that your component will transition to when it is exiting.
86+
The `from` property is the starting style of your transition component. This is the first state that your component animation will animate from. If the `exit` property is not specified, the `from` property is also used for the exit animation.
7787
7888
#### `enter: React.CSSProperties | LazyCSSProperties`
79-
The `enter` property is the entering style of your transition component. This is the state where your component animation will animate to, and it's final resting state.
89+
The `enter` property is the entering style of your transition component. This is the state where your component animation will animate to, and its final resting state.
8090
8191
#### `exit?: React.CSSProperties | LazyCSSProperties`
82-
The `exit` property is the exiting style of your transition component. This is an optional property, and can be useful for specifying a state to animate to, that isn't necessarily the same as your `from` state.
92+
The `exit` property is the exiting style of your transition component. This is an optional property for explicitly specifying a state to animate to when exiting, especially if you want an `exit` animation that is asymmetric from your `enter` animation.
8393
94+
### Example Recipes
8495
85-
# Example Recipes
86-
87-
### Symmetric Enter/Exit Transition
96+
#### Symmetric Enter/Exit Transition
8897
```jsx
8998
const FadeTransition = createTransition({
90-
from: (props) => ({ opacity: props.start }),
91-
enter: (props) => ({ opacity: props.end })
99+
from: { opacity: 0 },
100+
enter: { opacity: 1 }
92101
});
93-
94-
FadeTransition.defaultProps = { start: 0, end: 1 };
95102
```
96103

97-
### Asymmetric Enter/Exit Transition
104+
#### Asymmetric Enter/Exit Transition
98105
```jsx
99106
const ScaleEnterClipExitTransition = createTransition({
100-
from: { transform: 'scale(0.5)', opacity: 0, clipPath: 'circle(100% at 50% 50%)' },
101-
enter: { transform: 'scale(1)', opacity: 1, clipPath: 'circle(100% at 50% 50%)' },
102-
exit: { transform: 'scale(1)', opacity: 0, clipPath: 'circle(0% at 50% 50%)' },
107+
from: {
108+
transform: 'scale(0.5)',
109+
opacity: 0,
110+
clipPath: 'circle(100% at 50% 50%)'
111+
},
112+
enter: {
113+
transform: 'scale(1)',
114+
opacity: 1,
115+
clipPath: 'circle(100% at 50% 50%)'
116+
},
117+
exit: {
118+
transform: 'scale(1)',
119+
opacity: 0,
120+
clipPath: 'circle(0% at 50% 50%)'
121+
},
103122
});
104123
```
124+
125+
#### Configurable Transition
126+
```jsx
127+
const ClipScaleFadeTransition = createTransition({
128+
from: (props) => {
129+
return {
130+
opacity: props.fade ? 0 : 1,
131+
transform: `scale(${props.scale.start})`,
132+
clipPath: 'circle(100% at 50% 50%)'
133+
}
134+
},
135+
enter: (props) => {
136+
return {
137+
opacity: 1,
138+
transform: `scale(${props.scale.end})`
139+
clipPath: 'circle(100% at 50% 50%)'
140+
}
141+
},
142+
exit: (props) => {
143+
return {
144+
opacity: props.fade ? 0 : 1,
145+
transform: `scale(${props.scale.start})`,
146+
clipPath: 'circle(0% at 50% 50%)'
147+
}
148+
},
149+
});
150+
151+
ClipScaleFadeTransition.defaultProps = {
152+
fade: true,
153+
scale: {
154+
start: 0.5,
155+
end: 1,
156+
}
157+
}
158+
159+
```

0 commit comments

Comments
 (0)