Skip to content

Commit 23cab8b

Browse files
committed
Improve documentation
1 parent af4d046 commit 23cab8b

File tree

3 files changed

+136
-2
lines changed

3 files changed

+136
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Unreleased
44

5+
### [v2.5.0] - 2020-01-18
6+
* implement animated-outlet component
7+
58
### [v2.4.0] - 2020-01-04
69
* routerLinks: implement replace option
710
* wc: fix rendering when transitioning from a child to a parent route

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ Slick Router is a powerful, flexible router that translates URL changes into rou
1212
* Define path dynamic segments (uses path-to-regexp under the hood)
1313
* Supports custom query string parser
1414
* Trigger router navigate programatically
15-
* With builtin middlewares:
15+
* With builtin middlewares/components:
1616
* Render nested UI using web components
1717
* Streamlined support for code spliting and lazy loading
1818
* Expose route state to components
1919
* Declarative handling of router links
20+
* Allow to animate route transitions
2021

2122
## Installation
2223

@@ -36,12 +37,16 @@ wc and routerLinks middlewares accounts for 3kb each. See [webpack test project]
3637
* [Changelog](CHANGELOG.md)
3738

3839

39-
## Buitins middlewares
40+
## Builtin middlewares
4041

4142
* [wc](docs/middlewares/wc.md) (advanced Web Component rendering and lifecycle)
4243
* [routerLinks](docs/middlewares/router-links.md) (handle route related links state)
4344
* [events](docs/middlewares/events.md) (fires route events on window)
4445

46+
## Builtin components
47+
48+
* [animated-outlet](docs/components/animated-outlet.md) (enable animation on route transitions)
49+
4550
## Usage
4651

4752
```js

docs/components/animated-outlet.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# animated-outlet component
2+
3+
Enable animation on web component swapping triggered by route transitions.
4+
5+
## Usage
6+
7+
1) Register a `AnimatedOutlet` web component to the tag to be used as router outlet. wc middleware uses 'router-outlet' tag as default, but any tag can be used.
8+
9+
```javascript
10+
import { AnimatedOutlet } from 'slick-router/components/animated-outlet'
11+
12+
customElements.define('router-outlet', AnimatedOutlet)
13+
```
14+
15+
2) Add an 'animation' attribute to the outlet that will be animated
16+
17+
```html
18+
<router-outlet animation></router-outlet>
19+
```
20+
21+
3) Write the animation using CSS transition or animation
22+
23+
```css
24+
.outlet-enter-active,
25+
.outlet-leave-active {
26+
transition: opacity 0.5s;
27+
}
28+
29+
.outlet-enter, .outlet-leave-to {
30+
opacity: 0;
31+
}
32+
```
33+
34+
The above example adds a fading effect to the element that is entering and the one which is leaving
35+
36+
> The API is based on [Vue one](https://vuejs.org/v2/guide/transitions.html#Transition-Classes) and most of the Vue animations can be converted with little changes
37+
38+
Is possible to configure the CSS classes prefix through animation attribute, allowing to create more than one animation in same app:
39+
40+
```html
41+
<router-outlet animation="bounce"></router-outlet>
42+
```
43+
44+
```css
45+
.bounce-enter {
46+
opacity: 0;
47+
}
48+
49+
.bounce-enter-active {
50+
animation: bounce-in 0.5s;
51+
}
52+
53+
.bounce-leave-active {
54+
animation: bounce-in 0.5s reverse;
55+
}
56+
57+
@keyframes bounce-in {
58+
0% {
59+
transform: scale(0);
60+
}
61+
50% {
62+
transform: scale(1.5);
63+
}
64+
100% {
65+
transform: scale(1);
66+
}
67+
}
68+
```
69+
70+
The example above uses classes prefixed with 'bounce-' instead of 'outlet-'
71+
72+
[Live Demo](https://codesandbox.io/s/slick-router-css-animations-q0fzs)
73+
74+
## Customization
75+
76+
Is possible to customize how animation is done by creating and registering animation hook classes. It must extend from AnimationHook:
77+
78+
```js
79+
import { AnimationHook } from 'slick-router/components/animated-outlet.js'
80+
81+
class MyAnimation extends AnimationHook {
82+
beforeEnter (outlet, el) {
83+
// prepare element before is connected
84+
}
85+
86+
enter (outlet, el) {
87+
// run enter animation
88+
}
89+
90+
leave (outlet, el, done) {
91+
// run leave animation and call done on finish
92+
done()
93+
}
94+
}
95+
```
96+
97+
The hook class can be registered as default with `setDefaultAnimation` or to predefined animations using `registerAnimation`
98+
99+
Out of box, is provided the `AnimateCSS` class that allows to use [animate.css](https://github.com/daneden/animate.css)
100+
101+
```js
102+
import {
103+
AnimatedOutlet,
104+
AnimateCSS,
105+
setDefaultAnimation,
106+
registerAnimation
107+
} from 'slick-router/components/animated-outlet.js'
108+
109+
setDefaultAnimation(AnimateCSS, { enter: 'fadeIn', leave: 'fadeOut' })
110+
111+
registerAnimation('funky', AnimateCSS, { enter: 'rotateInDownRight', leave: 'hinge' })
112+
```
113+
114+
```html
115+
<router-outlet animation></router-outlet> <!-- the default animate.css fade -->
116+
117+
<router-outlet animation enter="zoomIn" leave="zoomOut"></router-outlet> <!-- override animation using enter and leave attrs -->
118+
119+
<router-outlet animation="funky"></router-outlet> <!-- use the predefined funky animation -->
120+
```
121+
122+
[Live demo](https://codesandbox.io/s/slick-router-animate-css-zpg96)
123+
124+
It's possible to use JS animation libraries like [GSAP](https://codesandbox.io/s/slick-router-gsap-animations-oqbp5) or even as [standalone component](https://codesandbox.io/s/animated-outlet-page-transitions-7vgcy) (without routing envolved)
125+
126+

0 commit comments

Comments
 (0)