Class: DesignSystem::Generic::NotificationComponent

Inherits:
BaseComponent
  • Object
show all
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.

Constant Summary collapse

TYPES =
%i[information success].freeze
HEADING_TAGS =
%i[h3 p].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::CssHelper

#css_class_options_merge

Methods included from BrandDerivable

#brand

Constructor Details

#initialize(message: nil, type: :information, content_heading: {}) ⇒ NotificationComponent

Returns a new instance of NotificationComponent.

Raises:

  • (ArgumentError)


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 = 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_headingObject (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

#messageObject (readonly)

Returns the value of attribute message.



21
22
23
# File 'app/components/design_system/generic/notification_component.rb', line 21

def message
  @message
end

#typeObject (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

#bodyObject



34
35
36
# File 'app/components/design_system/generic/notification_component.rb', line 34

def body
  content.presence || message
end

#heading_tagObject

Raises:

  • (ArgumentError)


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_textObject



30
31
32
# File 'app/components/design_system/generic/notification_component.rb', line 30

def heading_text
  content_heading[:text]
end