Skip to content

Commit ab68d36

Browse files
author
Nils Henning
committed
[TASK] extend basic building blocks guide
1 parent ed2e38d commit ab68d36

File tree

1 file changed

+78
-4
lines changed
  • docs/guides/200-basic_building_blocks

1 file changed

+78
-4
lines changed

docs/guides/200-basic_building_blocks/README.md

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ There are two different types of core components. Simple components and so calle
191191

192192
**Using core components**
193193

194-
Like already mentioned core components are automatically available in apps, pages and components, which means you can right ahead write your UI with apps, pages and components in pure ruby. Just use them like in the examples above. Core components always take a hash as parameter which can contain all corresponding w3c specified html attributes in order to set them.
194+
Like already mentioned core components are automatically available in apps, pages and components, which means you can right ahead write your UI with apps, pages and components in pure ruby. Just use them like in the examples above. Core components always take a hash as parameter which can contain all corresponding w3c specified html attributes in order to set them. Most components can also take either a `:text` option for their content or a block if they can have nested html content.
195195

196196
```ruby
197197
def response
198-
div id: 'product-1', class: 'product-teaser', data: { foo: 'bar' }
198+
div id: 'product-1', class: 'product-teaser', data: { foo: 'bar' } do
199+
heading text: 'A Product', size: 2
200+
end
199201
paragraph text: 'I am a p tag', class: 'highlight text-light'
200202
span text: 'I am a span', style: 'color: red;'
201203
end
@@ -204,7 +206,9 @@ end
204206
Rendered Result:
205207

206208
```html
207-
<div id="product-1" class="product-teaser", data-foo="bar"></div>
209+
<div id="product-1" class="product-teaser", data-foo="bar">
210+
<h1>A product</h1>
211+
</div>
208212
<p class="highlight text-light">I am a p tag</p>
209213
<span style="color: red;">I am a span</span>
210214
```
@@ -393,16 +397,86 @@ To learn more about the event hub head over to our [event hub api](/docs/api/000
393397

394398
## Core Features
395399

396-
* prebuild vue.js components for usual and advanced functionality
400+
You learned about matestack apps, pages, components, custom components, custom vue.js components, the event hub and you have heard about matestacks core vue.js components. They are vue.js components that implement useful features which would else require you to write javascript. Following up is a short introduction to matestacks unique components that enable you to write rich, modern UIs with ease.
397401

398402
**transition**
399403

404+
Starting off with the `transition` component. The transition component is 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 the example from above, links to our root, products index or details page should be transitions, because they will be rendered in the same 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.
405+
406+
The `transition` component requires a path. Use for example rails routes helpers to provide this. For example:
407+
408+
```ruby
409+
transition path: root_path, text: 'Home'
410+
transition path: products_path, class: 'card-link' do
411+
div class: 'card' do
412+
paragraph text: 'Transition with a more complex structure'
413+
end
414+
end
415+
```
416+
417+
Read more about the [transition component](/docs/api/100-components/transition.md).
418+
400419
**onclick**
401420

421+
The `onclick` component is very simple. It can emit an event if the contents of the `onclick` component gets clicked. This component shows its potential when used with other components that can react to events like `toggle`, `async`, `isolated`.
422+
423+
```ruby
424+
onclick emit: 'my-event' do
425+
button text: 'Click me!'
426+
end
427+
```
428+
429+
Read more about the [transition component](/docs/api/100-components/onclick.md).
430+
402431
**toggle**
403432

433+
The `toggle` component can toggle its view state according to either events or timers. It can show or hide its content after one of the specified events is received or hide its content after a certain amount of time. You can use it for example to show a notification if a special event occurs and automatically hide the notification after a certain period.
434+
435+
```ruby
436+
# showing content after 'my-event' was received and hiding it after 2s
437+
toggle show_on: 'my-event', hide_after: 2000 do
438+
paragraph text: 'Your notification content'
439+
end
440+
```
441+
442+
Read more about the [transition component](/docs/api/100-components/toggle.md).
443+
404444
**action**
405445

446+
The `action` component can be used to trigger a asynchronous request from for example a button click. Let's assume we want a delete button on our products show page in the management app. Deleting a product would require us to send a DELETE request to the `product_path(product.id)`. The `action` components let's us wrap content which is then clickable and triggers a request with the configured request method to the configured path and with the given params (giving you the ability to add whatever params you want) and let's us react to the server response. It can distinguish between a successful and failed response and emit events, transition somewhere, completely redirect and more for both. You only need to configure it according to your needs.
447+
448+
```ruby
449+
def response
450+
action action_config do
451+
button text: 'Delete'
452+
end
453+
end
454+
455+
def action_config
456+
{
457+
path: product_path(product.id),
458+
method: :delete,
459+
params: {
460+
foo: :bar
461+
},
462+
sucess: {
463+
transition: {
464+
follow_response: true
465+
}
466+
},
467+
failure: {
468+
emit: 'deletion-failed'
469+
}
470+
}
471+
end
472+
```
473+
474+
In the example above, clicking the "Delete" button will trigger an asynchronous DELETE request to the `products_path(id)` with params `foo: :bar`. If successful the action component will trigger a transition to the pass the controller redirected us to. If it failed we will emit the "deletion-failed" event.
475+
476+
We recommend defining the expected hash parameter for `action` components in a method, because they can get quite large.
477+
478+
Read more about the [transition component](/docs/api/100-components/action.md).
479+
406480
**forms**
407481

408482
**async**

0 commit comments

Comments
 (0)