Class: Railsboot::NavComponent

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

Overview

ViewComponent: renders the nav block.

Constant Summary collapse

STYLES =

Styles.

["", "tabs", "pills", "underline"].freeze
DEFAULT_STYLE =

Default style.

"".freeze
WIDTHS =

Widths.

["", "fill", "justified"].freeze
DEFAULT_WIDTH =

Default width.

"".freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of NavComponent.

Parameters:

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

    the tag option

  • style (String) (defaults to: DEFAULT_STYLE)

    the style option

  • width (String) (defaults to: DEFAULT_WIDTH)

    the width 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



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/railsboot/nav_component.rb', line 21

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