Class: Railsboot::Accordion::ItemComponent
- Inherits:
-
Component
- Object
- Component
- Railsboot::Accordion::ItemComponent
- Defined in:
- app/components/railsboot/accordion/item_component.rb
Overview
ViewComponent: renders the item block.
Instance Method Summary collapse
-
#initialize(id:, parent_id: "", expanded: false, **html_attributes) ⇒ ItemComponent
constructor
A new instance of ItemComponent.
-
#parent_reference ⇒ Hash
Builds the Bootstrap
data-bs-parentattribute hash linking this item to its parent accordion, or an empty hash when no parent id was given.
Constructor Details
#initialize(id:, parent_id: "", expanded: false, **html_attributes) ⇒ ItemComponent
Returns a new instance of ItemComponent.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/components/railsboot/accordion/item_component.rb', line 13 def initialize(id:, parent_id: "", expanded: false, **html_attributes) @id = id @parent_id = parent_id @expanded = @html_attributes = html_attributes @html_attributes[:tag] = "div" @html_attributes[:class] = class_names( "accordion-item", html_attributes.delete(:class) ) end |
Instance Method Details
#parent_reference ⇒ Hash
Builds the Bootstrap data-bs-parent attribute hash linking this item to
its parent accordion, or an empty hash when no parent id was given.
29 30 31 |
# File 'app/components/railsboot/accordion/item_component.rb', line 29 def parent_reference @parent_id.present? ? { bs_parent: "##{@parent_id}" } : {} end |