Class: SdrViewComponents::Elements::BannerComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/elements/banner_component.rb

Overview

Banner component for displaying messages, welcomes, etc.

Constant Summary collapse

ICONS =
{
  note: 'bi bi-exclamation-circle-fill',
  success: 'bi bi-check-circle-fill',
  warning: 'bi bi-exclamation-triangle-fill',
  info: 'bi bi-info-circle-fill',
  danger: 'bi bi-exclamation-triangle-fill'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #merge_actions, #merge_classes

Constructor Details

#initialize(title: nil, variant: :note, classes: [], role: 'banner', aria_label: nil) ⇒ BannerComponent

Returns a new instance of BannerComponent.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 18

def initialize(title: nil, variant: :note, classes: [], role: 'banner', aria_label: nil)
  @title = title
  @variant = variant.to_sym
  @classes = classes
  @role = role
  @aria_label = aria_label
  raise ArgumentError, "Unknown variant: #{variant}" unless ICONS.key?(variant)

  super()
end

Instance Attribute Details

#aria_labelObject (readonly)

Returns the value of attribute aria_label.



29
30
31
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 29

def aria_label
  @aria_label
end

#roleObject (readonly)

Returns the value of attribute role.



29
30
31
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 29

def role
  @role
end

#titleObject (readonly)

Returns the value of attribute title.



29
30
31
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 29

def title
  @title
end

#variantObject (readonly)

Returns the value of attribute variant.



29
30
31
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 29

def variant
  @variant
end

Instance Method Details

#classesObject



35
36
37
38
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 35

def classes
  merge_classes('alert banner d-flex shadow-sm align-items-center p-3 mb-3 border-start', "alert-#{variant}",
                @classes)
end

#icon_classesObject



31
32
33
# File 'app/components/sdr_view_components/elements/banner_component.rb', line 31

def icon_classes
  merge_classes('fs-3 me-3 align-self-center d-flex justify-content-center', ICONS[variant])
end