Class: Blacklight::System::FlashMessageComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/system/flash_message_component.rb

Constant Summary

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(type:, message: nil) ⇒ FlashMessageComponent

Returns a new instance of FlashMessageComponent.



10
11
12
13
# File 'app/components/blacklight/system/flash_message_component.rb', line 10

def initialize(type:, message: nil)
  @message = message
  @classes = alert_class(type)
end

Instance Method Details

#alert_class(type) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/components/blacklight/system/flash_message_component.rb', line 28

def alert_class(type)
  case type.to_s
  when 'success' then "alert-success"
  when 'notice'  then "alert-info"
  when 'alert'   then "alert-warning"
  when 'error'   then "alert-danger"
  else "alert-#{type}"
  end
end

#before_renderObject



15
16
17
# File 'app/components/blacklight/system/flash_message_component.rb', line 15

def before_render
  with_message { @message } if @message
end

#button_contentsObject

Bootstrap 4 requires the span, but Bootstrap 5 should not have it. See getbootstrap.com/docs/4.6/components/alerts/#dismissing

https://getbootstrap.com/docs/5.1/components/alerts/#dismissing


22
23
24
25
26
# File 'app/components/blacklight/system/flash_message_component.rb', line 22

def button_contents
  return if helpers.controller.blacklight_config.bootstrap_version == 5

  tag.span '×'.html_safe, aria: { hidden: true }
end