Class: DsfrComponent::AlertComponent
- Defined in:
- app/components/dsfr_component/alert_component.rb
Constant Summary collapse
- TYPES =
%i[error success info warning].freeze
- SIZES =
%i[sm md].freeze
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(type:, title: nil, size: :md, close_button: false, classes: [], html_attributes: {}) ⇒ AlertComponent
constructor
A new instance of AlertComponent.
Constructor Details
#initialize(type:, title: nil, size: :md, close_button: false, classes: [], html_attributes: {}) ⇒ AlertComponent
Note:
in size MD the title is required but the content is optional. In size SM there should be not title but the content is required
Returns a new instance of AlertComponent.
10 11 12 13 14 15 16 17 |
# File 'app/components/dsfr_component/alert_component.rb', line 10 def initialize(type:, title: nil, size: :md, close_button: false, classes: [], html_attributes: {}) @title = title @type = type @size = size @close_button = super(classes: classes, html_attributes: html_attributes) end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/components/dsfr_component/alert_component.rb', line 19 def call raise ArgumentError, "SM alerts cannot have titles but must have a content" if @size == :sm && (@title.present? || content.blank?) raise ArgumentError, "MD Alerts must have a title" if @size == :md && @title.blank? tag.div(**html_attributes) do safe_join([title_tag, content_tag, ]) end end |