Class: GovukComponent::NotificationBanner

Inherits:
Base
  • Object
show all
Includes:
ViewComponent::Slotable
Defined in:
app/components/govuk_component/notification_banner.rb

Defined Under Namespace

Classes: Heading

Instance Attribute Summary collapse

Attributes included from Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

wrap_slot

Methods included from Traits::CustomClasses

#classes

Constructor Details

#initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {}) ⇒ NotificationBanner

Returns a new instance of NotificationBanner.



8
9
10
11
12
13
14
15
16
# File 'app/components/govuk_component/notification_banner.rb', line 8

def initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
  super(classes: classes, html_attributes: html_attributes)

  @title               = title
  @title_id            = title_id
  @success             = success
  @title_heading_level = title_heading_level
  @disable_auto_focus  = disable_auto_focus
end

Instance Attribute Details

#disable_auto_focusObject (readonly)

Returns the value of attribute disable_auto_focus.



2
3
4
# File 'app/components/govuk_component/notification_banner.rb', line 2

def disable_auto_focus
  @disable_auto_focus
end

#successObject (readonly)

Returns the value of attribute success.



2
3
4
# File 'app/components/govuk_component/notification_banner.rb', line 2

def success
  @success
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'app/components/govuk_component/notification_banner.rb', line 2

def title
  @title
end

#title_heading_levelObject (readonly)

Returns the value of attribute title_heading_level.



2
3
4
# File 'app/components/govuk_component/notification_banner.rb', line 2

def title_heading_level
  @title_heading_level
end

#title_idObject (readonly)

Returns the value of attribute title_id.



2
3
4
# File 'app/components/govuk_component/notification_banner.rb', line 2

def title_id
  @title_id
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/components/govuk_component/notification_banner.rb', line 26

def render?
  headings.any? || content.present?
end

#success?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/components/govuk_component/notification_banner.rb', line 22

def success?
  @success
end

#success_classObject



18
19
20
# File 'app/components/govuk_component/notification_banner.rb', line 18

def success_class
  %(govuk-notification-banner--success) if success?
end

#title_tagObject



30
31
32
33
34
# File 'app/components/govuk_component/notification_banner.rb', line 30

def title_tag
  fail "title_heading_level must be a number between 1 and 6" unless title_heading_level.is_a?(Integer) && title_heading_level.in?(1..6)

  "h#{title_heading_level}"
end