Skip to content

Commit b2ab75a

Browse files
introduce basic inline styling guide
1 parent 32c488e commit b2ab75a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

guides/30_inline_styling.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Inline styling of Matestack components
2+
3+
*Prerequisite:* We assume you have read and followed the [installation guide](/docs/install), either in a new or existing Rails application.
4+
5+
## General approach
6+
7+
Matestack components can easily be styled through the `attributes` parameter. In a growing application, you will most probably work with a (S)CSS framework/library and often style your pages and components through `id`s and `classes`. Inline styles allow for dynamic styling and can come in handy in certain use cases - as shown below:
8+
9+
```ruby
10+
# [...]
11+
12+
def prepare
13+
@colors = ['green', 'blue', 'red']
14+
end
15+
16+
def response
17+
components {
18+
@colors.each do |color|
19+
paragraph attributes: { style: "color: #{color};" }, text: "I will be displayed as #{color} text."
20+
end
21+
}
22+
end
23+
24+
# [...]
25+
```
26+
## Accessing videos and images with inline styling
27+
28+
For now, we have to resort to an `ActionController` helper in order to work with our assets. See a working example below:
29+
30+
```ruby
31+
# [...]
32+
33+
def response
34+
components {
35+
div attributes: { style: "background-image: url(#{ActionController::Base.helpers.asset_path('image.png')});" } do
36+
# [...]
37+
end
38+
}
39+
end
40+
41+
# [...]
42+
```

0 commit comments

Comments
 (0)