You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/200-basic_building_blocks/README.md
+78-4Lines changed: 78 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,11 +191,13 @@ There are two different types of core components. Simple components and so calle
191
191
192
192
**Using core components**
193
193
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.
195
195
196
196
```ruby
197
197
defresponse
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
199
201
paragraph text:'I am a p tag', class: 'highlight text-light'
@@ -393,16 +397,86 @@ To learn more about the event hub head over to our [event hub api](/docs/api/000
393
397
394
398
## Core Features
395
399
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.
397
401
398
402
**transition**
399
403
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:
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
+
400
419
**onclick**
401
420
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
+
402
431
**toggle**
403
432
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:2000do
438
+
paragraph text:'Your notification content'
439
+
end
440
+
```
441
+
442
+
Read more about the [transition component](/docs/api/100-components/toggle.md).
443
+
404
444
**action**
405
445
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
+
defresponse
450
+
action action_config do
451
+
button text:'Delete'
452
+
end
453
+
end
454
+
455
+
defaction_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).
0 commit comments