Skip to content

Commit 43d2dc2

Browse files
authored
Update README.md
1 parent a648744 commit 43d2dc2

File tree

1 file changed

+66
-8
lines changed

1 file changed

+66
-8
lines changed

README.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ end
207207
Just like you used matestack's core components on your own UI component, you can use your own UI components within other custom UI components.
208208
You decide when using a Ruby method partial should be replaced by another self contained UI component!
209209

210-
#### Yield components into components
211-
212-
Sometimes it's not enough to just pass simple data into a component. No worries! You can just yield a block into your components!
213-
Using this approach gives you more flexibility when using your UI components. Ofcourse yielding can be used alongside passing in simple params.
214-
215210
`app/matestack/components/card.rb`
216211

217212
```ruby
@@ -255,6 +250,7 @@ end
255250

256251
```
257252

253+
258254
`app/matestack/components/registry.rb`
259255

260256
```ruby
@@ -269,10 +265,11 @@ module Components::Registry
269265
end
270266
```
271267

272-
#### Use named slots for advanced content injection
268+
#### Yield components into components
269+
270+
Sometimes it's not enough to just pass simple data into a component. No worries! You can just yield a block into your components!
271+
Using this approach gives you more flexibility when using your UI components. Ofcourse yielding can be used alongside passing in simple params.
273272

274-
If you need to inject multiple blocks into your UI component, you can use \"slots\"!
275-
Slots help you to build complex UI components with multiple named content placeholders for highest implementation flexibility!
276273

277274
`app/matestack/components/card.rb`
278275

@@ -317,6 +314,67 @@ end
317314

318315
```
319316

317+
#### Use named slots for advanced content injection
318+
319+
If you need to inject multiple blocks into your UI component, you can use \"slots\"!
320+
Slots help you to build complex UI components with multiple named content placeholders for highest implementation flexibility!
321+
322+
`app/matestack/components/card.rb`
323+
324+
```ruby
325+
326+
class Components::Card < Matestack::Ui::Component
327+
328+
requires :body
329+
optional :title
330+
optional :image
331+
332+
def response
333+
div class: "card shadow-sm border-0 bg-light" do
334+
img path: image, class: "w-100" if image.present?
335+
card_body slots: { heading: heading_slot, body: body_slot }
336+
end
337+
end
338+
339+
def heading_slot
340+
slot do
341+
heading size: 5, text: title if title.present?
342+
end
343+
end
344+
345+
def body_slot
346+
slot do
347+
paragraph class: "card-text", text: body
348+
end
349+
end
350+
351+
end
352+
353+
```
354+
`app/matestack/components/card_body.rb`
355+
356+
```ruby
357+
358+
class Components::CardBody < Matestack::Ui::Component
359+
360+
requires :slots
361+
362+
def response
363+
# Just an example. Would make more sense, if this component had
364+
# a more complex structure
365+
div class: "card-body" do
366+
div class: "heading-section" do
367+
slot slots[:heading]
368+
end
369+
div class: "body-section" do
370+
slot slots[:body]
371+
end
372+
end
373+
end
374+
375+
end
376+
377+
```
320378

321379

322380
### 2. Use reactive UI components in pure Ruby

0 commit comments

Comments
 (0)