Skip to content

Commit

Permalink
Add list example with item slots
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed Feb 22, 2022
1 parent 30807b4 commit e165b2e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/components/elements/list_component.rb
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 test/components/previews/elements/list_component_preview.rb
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

0 comments on commit e165b2e

Please sign in to comment.