Class: SdrViewComponents::Elements::AlertComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Elements::AlertComponent
- Defined in:
- app/components/sdr_view_components/elements/alert_component.rb
Overview
Component for rendering an alert.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
- #classes ⇒ Object
- #dismissible? ⇒ Boolean
- #dismissible_class ⇒ Object
- #icon ⇒ Object
- #icon? ⇒ Boolean
-
#initialize(title: nil, variant: :info, dismissible: false, data: {}, classes: [], id: nil, role: 'alert', text: nil) ⇒ AlertComponent
constructor
Variants are :danger, :success, :note, :info, :warning, :input input is not part of the component library.
- #render? ⇒ Boolean
- #variant_class ⇒ Object
Methods inherited from BaseComponent
#args_for, #merge_actions, #merge_classes
Constructor Details
#initialize(title: nil, variant: :info, dismissible: false, data: {}, classes: [], id: nil, role: 'alert', text: nil) ⇒ AlertComponent
Variants are :danger, :success, :note, :info, :warning, :input input is not part of the component library
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 9 def initialize(title: nil, variant: :info, dismissible: false, # rubocop:disable Metrics/ParameterLists data: {}, classes: [], id: nil, role: 'alert', text: nil) raise ArgumentError, 'Invalid variant' unless %i[danger success note info warning input].include?(variant.to_sym) @title = title @variant = variant @dismissible = dismissible @data = data @classes = classes @id = id @role = role @text = text super() end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
24 25 26 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 24 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 24 def id @id end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
24 25 26 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 24 def role @role end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
24 25 26 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 24 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
24 25 26 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 24 def title @title end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
24 25 26 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 24 def variant @variant end |
Instance Method Details
#classes ⇒ Object
26 27 28 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 26 def classes merge_classes(%w[alert d-flex shadow-sm align-items-center], variant_class, dismissible_class, @classes) end |
#dismissible? ⇒ Boolean
38 39 40 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 38 def dismissible? @dismissible end |
#dismissible_class ⇒ Object
34 35 36 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 34 def dismissible_class 'alert-dismissible' if dismissible? end |
#icon ⇒ Object
46 47 48 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 46 def icon helpers.public_send(:"#{variant}_icon", role: 'img', aria: { label: "#{variant} alert icon" }) end |
#icon? ⇒ Boolean
42 43 44 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 42 def icon? helpers.respond_to?(:"#{variant}_icon") end |
#render? ⇒ Boolean
50 51 52 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 50 def render? title.present? || content.present? || text.present? end |
#variant_class ⇒ Object
30 31 32 |
# File 'app/components/sdr_view_components/elements/alert_component.rb', line 30 def variant_class "alert-#{variant}" end |