Class: Railsboot::FlashComponent

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

Overview

ViewComponent: renders the flash block.

Constant Summary collapse

FLASH_TYPES =

Recognised flash types.

%i[notice alert info].freeze
FLASH_MAPPING =

Flash mapping.

{
  notice: "success",
  alert: "danger",
  info: "info"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(flash:, **html_attributes) ⇒ FlashComponent

Returns a new instance of FlashComponent.

Parameters:

  • flash (String)

    the flash option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    CSS classes applied to the rendered tag



16
17
18
19
# File 'app/components/railsboot/flash_component.rb', line 16

def initialize(flash:, **html_attributes)
  @flash = flash
  @html_attributes = html_attributes
end

Instance Method Details

#render?Boolean

Whether the flash block should be rendered.

Returns:

  • (Boolean)

    true when a flash message is present



23
24
25
# File 'app/components/railsboot/flash_component.rb', line 23

def render?
  @flash.present?
end