Class: Railsboot::Toast::HeaderComponent

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

Overview

ViewComponent: renders the header block of a Bootstrap toast, including
the close button that dismisses it.

Instance Method Summary collapse

Constructor Details

#initialize(**html_attributes) ⇒ HeaderComponent

Returns a new instance of HeaderComponent.

Parameters:

  • 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 for the element



9
10
11
12
13
14
15
16
17
# File 'app/components/railsboot/toast/header_component.rb', line 9

def initialize(**html_attributes)
  @html_attributes = html_attributes

  @html_attributes[:tag] = "div"
  @html_attributes[:class] = class_names(
    "toast-header",
    html_attributes.delete(:class)
  )
end

Instance Method Details

#callString

Renders the header element wrapping the content and a toast-dismiss close button.

Returns:

  • (String)

    rendered HTML for the toast header



22
23
24
25
26
# File 'app/components/railsboot/toast/header_component.rb', line 22

def call
  render(Railsboot::BaseComponent.new(**@html_attributes)) do
    content.to_s + render(Railsboot::CloseButtonComponent.new(data: { bs_dismiss: "toast" }))
  end
end