Class: Railsboot::NavComponent

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

Constant Summary collapse

STYLES =
["", "tabs", "pills", "underline"].freeze
DEFAULT_STYLE =
"".freeze
WIDTHS =
["", "fill", "justified"].freeze
DEFAULT_WIDTH =
"".freeze

Constants inherited from Component

Component::COLORS, Component::DEFAULT_COLOR

Instance Method Summary collapse

Constructor Details

#initialize(tag: "nav", style: DEFAULT_STYLE, width: DEFAULT_WIDTH, **html_attributes) ⇒ NavComponent

Returns a new instance of NavComponent.



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

def initialize(tag: "nav", style: DEFAULT_STYLE, width: DEFAULT_WIDTH, **html_attributes)
  @tag = tag
  @style = fetch_or_fallback(style, STYLES, DEFAULT_STYLE)
  @width = fetch_or_fallback(width, WIDTHS, DEFAULT_WIDTH)
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "nav",
    {"nav-#{@style}" => @style.present?},
    {"nav-#{@width}" => @width.present?},
    html_attributes.delete(:class)
  )
end