207
207
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.
208
208
You decide when using a Ruby method partial should be replaced by another self contained UI component!
209
209
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
-
215
210
` app/matestack/components/card.rb `
216
211
217
212
``` ruby
255
250
256
251
```
257
252
253
+
258
254
` app/matestack/components/registry.rb `
259
255
260
256
``` ruby
@@ -269,10 +265,11 @@ module Components::Registry
269
265
end
270
266
```
271
267
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.
273
272
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!
276
273
277
274
` app/matestack/components/card.rb `
278
275
317
314
318
315
```
319
316
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
+ ```
320
378
321
379
322
380
### 2. Use reactive UI components in pure Ruby
0 commit comments