Class: GovukComponent::NotificationBannerComponent::Heading

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/notification_banner_component.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand

Constructor Details

#initialize(text: nil, link_text: nil, link_href: nil, classes: [], html_attributes: {}) ⇒ Heading

Returns a new instance of Heading.



36
37
38
39
40
41
42
# File 'app/components/govuk_component/notification_banner_component.rb', line 36

def initialize(text: nil, link_text: nil, link_href: nil, classes: [], html_attributes: {})
  @text      = text
  @link_text = link_text
  @link_href = link_href

  super(classes:, html_attributes:)
end

Instance Attribute Details

Returns the value of attribute link_href.



34
35
36
# File 'app/components/govuk_component/notification_banner_component.rb', line 34

def link_href
  @link_href
end

Returns the value of attribute link_text.



34
35
36
# File 'app/components/govuk_component/notification_banner_component.rb', line 34

def link_text
  @link_text
end

#textObject (readonly)

Returns the value of attribute text.



34
35
36
# File 'app/components/govuk_component/notification_banner_component.rb', line 34

def text
  @text
end

Instance Method Details

#callObject



44
45
46
47
48
49
50
51
52
# File 'app/components/govuk_component/notification_banner_component.rb', line 44

def call
  tag.div(**html_attributes) do
    if text.present?
      safe_join([text, link].compact, " ")
    else
      content
    end
  end
end

#default_attributesObject



58
59
60
# File 'app/components/govuk_component/notification_banner_component.rb', line 58

def default_attributes
  { class: ["#{brand}-notification-banner__heading"] }
end


54
55
56
# File 'app/components/govuk_component/notification_banner_component.rb', line 54

def link
  link_to(link_text, link_href, class: "#{brand}-notification-banner__link") if link_text.present? && link_href.present?
end