Class: Railsboot::Accordion::ItemComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/accordion/item_component.rb

Overview

ViewComponent: renders the item block.

Instance Method Summary collapse

Constructor Details

#initialize(id:, parent_id: "", expanded: false, **html_attributes) ⇒ ItemComponent

Returns a new instance of ItemComponent.

Parameters:

  • id (String)

    the id option

  • parent_id (String) (defaults to: "")

    the parent id option

  • expanded (Boolean) (defaults to: false)

    the expanded option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes

  • :tag (String)

    HTML tag to render for the element



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 = 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_referenceHash

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.

Returns:

  • (Hash)

    { bs_parent: "#<parent_id>" } when parent_id is present, otherwise an empty hash



29
30
31
# File 'app/components/railsboot/accordion/item_component.rb', line 29

def parent_reference
  @parent_id.present? ? { bs_parent: "##{@parent_id}" } : {}
end