Skip to content

Commit 50639e5

Browse files
author
Nils Henning
committed
[TASK] add transition guide
1 parent 9f72d36 commit 50639e5

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

docs/guides/400-transitions/README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
# Transitions
22

3-
![Coming Soon](../../images/coming_soon.png)
3+
![Coming Soon](../../images/coming_soon.png)
4+
5+
Matestack `transition` component enables switching between pages without a website reload. It works similar to links, but instead of reloading the complete website, including the layout like Rails usually does, it only asynchronously reloads the page without the app and replaces it dynamically.
6+
7+
The `transition` component is therefore one of the key components for you to use. You should use them instead of a link if the target path of that link belongs to the same app. Given a shopping application with a shop app, links to our root, products index or details page should be transitions, because they belong to the shop app. The use of transitions enables the app to switch between pages without website reloads, instead asynchronously requesting the new page in the background and switching it after a successful response from the server.
8+
9+
Using the `transition` component is pretty straight forward. Let's take the above mentioned shop app as an example and implement it and add a navigation with transitions to the home or products page. `transition`s are ofcourse usable in apps, pages and components.
10+
11+
```ruby
12+
class Shop::App < Matestack::Ui::App
13+
14+
def response
15+
nav do
16+
transition path: root_path, text: 'Matestack Shop'
17+
transition path: root_path, text: 'Products'
18+
end
19+
yield_page
20+
end
21+
22+
end
23+
```
24+
25+
Styling a transition which is _active_ is simple, because it automatically gets the `active` class on the clientside when the current path equals it's target path. When a sub page of a parent `transition` component is currently active, the parent `transition` component gets a `active-child` class.
26+
27+
Let's add the products page which simply lists all products and adds a transition to their show page for each one.
28+
29+
```ruby
30+
class Shop::Pages::Products::Index < Matestack::Ui::Page
31+
32+
def response
33+
Products.all.each do |product|
34+
div do
35+
paragraph text: product.name
36+
transition path: product_path(product), text: 'Details'
37+
end
38+
end
39+
end
40+
41+
end
42+
```
43+
44+
If you want to know all details about the `transition` component, like how you can delay it or what events it emits, checkout it's [api documentation](docs/api/100-components/transition.md)

0 commit comments

Comments
 (0)