Class: DesignSystem::Generic::NotificationComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- DesignSystem::Generic::NotificationComponent
- Defined in:
- app/components/design_system/generic/notification_component.rb
Overview
Notification banner rendered by ds_notice. Shows an "Important"/"Success" header followed by a content area with an optional heading and the message (or block) body.
Direct Known Subclasses
DesignSystem::Govuk::NotificationComponent, Nhsuk::NotificationComponent
Constant Summary collapse
- TYPES =
%i[information success].freeze
- HEADING_TAGS =
%i[h3 p].freeze
Instance Attribute Summary collapse
-
#content_heading ⇒ Object
readonly
Returns the value of attribute content_heading.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #body ⇒ Object
- #heading_tag ⇒ Object
- #heading_text ⇒ Object
-
#initialize(message: nil, type: :information, content_heading: {}) ⇒ NotificationComponent
constructor
A new instance of NotificationComponent.
Methods included from Helpers::CssHelper
Methods included from BrandDerivable
Constructor Details
#initialize(message: nil, type: :information, content_heading: {}) ⇒ NotificationComponent
Returns a new instance of NotificationComponent.
10 11 12 13 14 15 16 17 18 19 |
# File 'app/components/design_system/generic/notification_component.rb', line 10 def initialize(message: nil, type: :information, content_heading: {}) super() @message = @type = type @content_heading = content_heading || {} return if TYPES.include?(type) raise ArgumentError, "Invalid notification type: #{type}. Must be one of: #{TYPES.join(', ')}" end |
Instance Attribute Details
#content_heading ⇒ Object (readonly)
Returns the value of attribute content_heading.
21 22 23 |
# File 'app/components/design_system/generic/notification_component.rb', line 21 def content_heading @content_heading end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
21 22 23 |
# File 'app/components/design_system/generic/notification_component.rb', line 21 def @message end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'app/components/design_system/generic/notification_component.rb', line 21 def type @type end |
Instance Method Details
#body ⇒ Object
34 35 36 |
# File 'app/components/design_system/generic/notification_component.rb', line 34 def body content.presence || end |
#heading_tag ⇒ Object
23 24 25 26 27 28 |
# File 'app/components/design_system/generic/notification_component.rb', line 23 def heading_tag tag = content_heading.fetch(:tag, :h3) raise ArgumentError, "Invalid content_heading tag: #{tag}." unless HEADING_TAGS.include?(tag) tag end |
#heading_text ⇒ Object
30 31 32 |
# File 'app/components/design_system/generic/notification_component.rb', line 30 def heading_text content_heading[:text] end |