Class: Railsboot::ListGroup::ItemComponent

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

Overview

ViewComponent: renders the item block.

Instance Method Summary collapse

Constructor Details

#initialize(tag: "li", active: false, disabled: false, color: nil, **html_attributes) ⇒ ItemComponent

Returns a new instance of ItemComponent.

Parameters:

  • tag (String) (defaults to: "li")

    HTML tag to render

  • active (Boolean) (defaults to: false)

    whether the item is marked active

  • disabled (Boolean) (defaults to: false)

    whether the item is marked disabled

  • color (String, nil) (defaults to: nil)

    Bootstrap color variant (one of COLORS)

  • 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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/railsboot/list_group/item_component.rb', line 10

def initialize(tag: "li", active: false, disabled: false, color: nil, **html_attributes)
  @tag = tag
  @active = active
  @disabled = disabled
  @color = fetch_or_fallback(color, COLORS, "")
  @html_attributes = html_attributes

  @html_attributes[:tag] = @tag
  @html_attributes[:class] = class_names(
    "list-group-item",
    { "list-group-item-#{color}" => @color.present? },
    { "active" => @active },
    { "disabled" => @disabled },
    html_attributes.delete(:class)
  )
end

Instance Method Details

#callString

Renders the list group item.

Returns:

  • (String)

    the rendered HTML



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

def call
  render(Railsboot::BaseComponent.new(tag: "li", **@html_attributes)) { content }
end