Skip to content

Commit b7b17ef

Browse files
authored
📝 Update README.md
1 parent 39359dd commit b7b17ef

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

README.md

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/Dogstudio/highway/issues)
99
[![license](https://img.shields.io/github/license/Dogstudio/highway.svg)](https://github.com/Dogstudio/highway/blob/master/LICENSE)
1010

11-
1211
<p align="center"><img src="https://i.imgur.com/AOEVomM.png" alt="Banner" /></p>
1312

1413
**Highway** is a *modern*, *flexible* and *lightweight* library that will let you create **AJAX navigations** with beautiful **transitions** on your websites. It's been a while we were trying to build this kind of library to fits our needs at [**Dogstudio**](https://www.dogstudio.co) and that hopefully will fit yours now we're releasing it!
@@ -39,7 +38,9 @@ or *require* it if you prefer:
3938
```javascript
4039
const Highway = require('@dogstudio/highway');
4140
```
42-
Now **Highway** is available you need to create an instance of `Highway.Core` and give it your [**renderers**]() and [**transitions**]().
41+
42+
Now **Highway** is available you need to create an instance of `Highway.Core` and give it your [**renderers**](https://github.com/Dogstudio/highway#renderers) and [**transitions**](https://github.com/Dogstudio/highway#transitions).
43+
4344
```javascript
4445
const H = new Highway.Core({
4546
renderers: {
@@ -91,6 +92,9 @@ import Highway from '@dogstudio/highway';
9192
class Home extends Highway.renderer {
9293
[...]
9394
}
95+
96+
// Don`t forget to export your renderer
97+
export default Home;
9498
```
9599
Besides the required methods from **Highway** present in the `Highway.renderer` you have access to **optional** ones that are called all along the process of the navigation. Here is the list of these **optional** methods:
96100

@@ -114,7 +118,9 @@ class Home extends Highway.renderer {
114118
// Don`t forget to export your renderer
115119
export default Home;
116120
```
117-
Now your custom renderer is created you need to add it to the renderers list of `Highway.Core`... Remember the name you gave to you `router-view`, it's now time to use it to relate your renderer in Javascript to you `router-view` in HTML.
121+
122+
Now your custom renderer is created you need to add it to the renderers list of `Highway.Core`...
123+
Remember the name you gave to you `router-view`, it's now time to relate it to your renderer.
118124

119125
```javascript
120126
// Import Renderers
@@ -131,6 +137,73 @@ const H = new Highway.Core({
131137
});
132138
```
133139

140+
## Transitions
141+
142+
OK so now you have your custom renderers but you are sad because there are no transitions between your pages...
143+
Don't be afraid, let's now see how to create our first transition!
144+
145+
Transitions in **Highway** are really simple, these are objects with two methods:
146+
147+
- `in`: The `in` method should contain the transition to show a `[router-view]`.
148+
- `out`: The `out` method should contain the transition to hide a `[router-view]`.
149+
150+
Each one get two parameters you can call how you want but here are good defaults:
151+
152+
- `view`: The `[router-view]` you will show/hide.
153+
- `done`: The callback method **you have to** call once the `in` and `out` transitions are over.
154+
155+
**transition.js**
156+
```javascript
157+
const Transition = {
158+
in: (view, done) => {
159+
// [...]
160+
},
161+
out: (view, done) => {
162+
// [...]
163+
}
164+
};
165+
166+
// Don't forget to export your transition
167+
export default Transition;
168+
```
169+
170+
Now your transition is created you need to add it to the transitions list of `Highway.Core`...
171+
Remember the name you gave to you `router-view`, it's now time to relate it to your transition.
172+
173+
```javascript
174+
// Import Renderers
175+
import Home from 'path/to/home.js';
176+
177+
// Import Transitions
178+
import Transition from 'path/to/transition.js';
179+
180+
// Relate you transition to your [router-view] name
181+
const H = new Highway.Core({
182+
renderers: {
183+
home: Home
184+
},
185+
transitions: {
186+
home: Transition
187+
}
188+
});
189+
```
190+
191+
Last but not least, you might want to use the same transition for all the pages across your website. This is possible by adding a `default` key to your transitions list. When you do so for each page **Highway** will look for a transition in the list related to your `router-view` name and fallback to the `default` one if none is found.
192+
193+
```javascript
194+
// [...]
195+
const H = new Highway.Core({
196+
renderers: {
197+
home: Home
198+
},
199+
transitions: {
200+
default: Transition
201+
}
202+
});
203+
```
204+
205+
Check out the [**examples**](https://github.com/Dogstudio/highway#examples) for more details about transitions in **Highway**.
206+
134207
## Examples
135208

136209
- [Basic Setup](https://github.com/Dogstudio/highway/tree/master/examples/basic-setup)

0 commit comments

Comments
 (0)