-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30807b4
commit e165b2e
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Elements::ListComponent < ViewComponent::Base | ||
renders_many :items, "ItemComponent" | ||
|
||
def call | ||
tag.ol do | ||
safe_join items | ||
end | ||
end | ||
|
||
class ItemComponent < ViewComponent::Base | ||
def call | ||
tag.li content | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
test/components/previews/elements/list_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# @label Simple list | ||
class Elements::ListComponentPreview < ViewComponent::Preview | ||
# This example uses the `with_content` helper to set inline content. | ||
# | ||
# You can read more about it in the ViewComponent [slots documentation](https://viewcomponent.org/guide/slots.html#with_content). | ||
def default | ||
render Elements::ListComponent.new do |list| | ||
list.item.with_content "One" | ||
list.item.with_content "Two" | ||
list.item.with_content "Three" | ||
end | ||
end | ||
end |