Class: Railsboot::AlertComponent

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

Overview

ViewComponent: renders the alert block.

Instance Method Summary collapse

Constructor Details

#initialize(color: DEFAULT_COLOR, dismissible: false, **html_attributes) ⇒ AlertComponent

Returns a new instance of AlertComponent.

Parameters:

  • color (String) (defaults to: DEFAULT_COLOR)

    Bootstrap color variant (one of COLORS)

  • dismissible (Boolean) (defaults to: false)

    whether the alert can be dismissed

  • 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



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

def initialize(color: DEFAULT_COLOR, dismissible: false, **html_attributes)
  @color = fetch_or_raise(color, COLORS)
  @dismissible = dismissible
  @html_attributes = html_attributes

  @html_attributes[:tag] = "div"
  @html_attributes[:class] = class_names(
    "alert",
    "alert-#{@color}",
    { "alert-dismissible fade show" => @dismissible },
    html_attributes.delete(:class)
  )
end

Instance Method Details

#before_rendervoid (protected)

This method returns an undefined value.

Sets the ARIA role attribute before rendering.



27
28
29
# File 'app/components/railsboot/alert_component.rb', line 27

def before_render
  @html_attributes["role"] = "alert"
end