Class: Railsboot::Nav::ItemComponent

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

Overview

ViewComponent: renders the item block.

Instance Method Summary collapse

Constructor Details

#initialize(text: "", href: "", active: false, disabled: false, wrapper_item: false, wrapper_tag: "li", wrapper_html_attributes: {}, **html_attributes) ⇒ ItemComponent

Returns a new instance of ItemComponent.

Parameters:

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

    the text option

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

    the href option

  • active (Boolean) (defaults to: false)

    the active option

  • disabled (Boolean) (defaults to: false)

    the disabled option

  • wrapper_item (Boolean) (defaults to: false)

    the wrapper item option

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

    the wrapper tag option

  • wrapper_html_attributes (Hash) (defaults to: {})

    the wrapper html attributes 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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/components/railsboot/nav/item_component.rb', line 13

def initialize(text: "", href: "", active: false, disabled: false, wrapper_item: false, wrapper_tag: "li", wrapper_html_attributes: {}, **html_attributes)
  @text = text
  @href = href
  @active = active
  @disabled = disabled
  @html_attributes = html_attributes

  @wrapper_item = wrapper_item
  @wrapper_tag = wrapper_tag
  @wrapper_html_attributes = wrapper_html_attributes

  @html_attributes[:class] = class_names(
    "nav-link",
    { "active" => @active },
    { "disabled" => @disabled },
    html_attributes.delete(:class)
  )
end

Instance Method Details

#adjusted_wrapper_html_attributesHash

Merges the "nav-item" class with any user-provided wrapper classes.

Returns:

  • (Hash)

    the wrapper HTML attributes with merged classes



34
35
36
37
# File 'app/components/railsboot/nav/item_component.rb', line 34

def adjusted_wrapper_html_attributes
  @wrapper_html_attributes["class"] = ["nav-item", @wrapper_html_attributes.delete(:class)].compact_blank.uniq.join(" ")
  @wrapper_html_attributes
end