govuk-components 1.2.0 → 2.0.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/govuk_component/{accordion.html.erb → accordion_component.html.erb} +1 -1
  3. data/app/components/govuk_component/{accordion.rb → accordion_component.rb} +7 -6
  4. data/app/components/govuk_component/{back_link.rb → back_link_component.rb} +5 -1
  5. data/app/components/govuk_component/base.rb +9 -7
  6. data/app/components/govuk_component/{breadcrumbs.html.erb → breadcrumbs_component.html.erb} +3 -6
  7. data/app/components/govuk_component/{breadcrumbs.rb → breadcrumbs_component.rb} +1 -1
  8. data/app/components/govuk_component/{cookie_banner.html.erb → cookie_banner_component.html.erb} +2 -6
  9. data/app/components/govuk_component/{cookie_banner.rb → cookie_banner_component.rb} +1 -1
  10. data/app/components/govuk_component/details_component.rb +34 -0
  11. data/app/components/govuk_component/{footer.html.erb → footer_component.html.erb} +3 -5
  12. data/app/components/govuk_component/{footer.rb → footer_component.rb} +3 -8
  13. data/app/components/govuk_component/header_component.html.erb +49 -0
  14. data/app/components/govuk_component/header_component.rb +110 -0
  15. data/app/components/govuk_component/{inset_text.rb → inset_text_component.rb} +3 -3
  16. data/app/components/govuk_component/notification_banner_component.html.erb +14 -0
  17. data/app/components/govuk_component/{notification_banner.rb → notification_banner_component.rb} +28 -14
  18. data/app/components/govuk_component/panel_component.rb +46 -0
  19. data/app/components/govuk_component/phase_banner_component.html.erb +6 -0
  20. data/app/components/govuk_component/phase_banner_component.rb +20 -0
  21. data/app/components/govuk_component/start_button_component.rb +47 -0
  22. data/app/components/govuk_component/summary_list_component.html.erb +11 -0
  23. data/app/components/govuk_component/summary_list_component.rb +61 -0
  24. data/app/components/govuk_component/tab_component.html.erb +11 -0
  25. data/app/components/govuk_component/{tabs.rb → tab_component.rb} +23 -12
  26. data/app/components/govuk_component/{tag.rb → tag_component.rb} +21 -3
  27. data/app/components/govuk_component/warning_text_component.rb +38 -0
  28. data/app/helpers/govuk_components_helper.rb +15 -15
  29. data/lib/govuk/components.rb +1 -0
  30. data/lib/govuk/components/helpers/css_utilities.rb +22 -0
  31. data/lib/govuk/components/version.rb +1 -1
  32. metadata +52 -42
  33. data/app/components/govuk_component/back_link.html.erb +0 -1
  34. data/app/components/govuk_component/details.html.erb +0 -10
  35. data/app/components/govuk_component/details.rb +0 -16
  36. data/app/components/govuk_component/header.html.erb +0 -50
  37. data/app/components/govuk_component/header.rb +0 -66
  38. data/app/components/govuk_component/notification_banner.html.erb +0 -23
  39. data/app/components/govuk_component/panel.html.erb +0 -13
  40. data/app/components/govuk_component/panel.rb +0 -28
  41. data/app/components/govuk_component/phase_banner.html.erb +0 -8
  42. data/app/components/govuk_component/phase_banner.rb +0 -16
  43. data/app/components/govuk_component/start_now_button.html.erb +0 -6
  44. data/app/components/govuk_component/start_now_button.rb +0 -16
  45. data/app/components/govuk_component/summary_list.html.erb +0 -19
  46. data/app/components/govuk_component/summary_list.rb +0 -34
  47. data/app/components/govuk_component/tabs.html.erb +0 -19
  48. data/app/components/govuk_component/warning.html.erb +0 -7
  49. data/app/components/govuk_component/warning.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f842d29dfabae4169ed1b2105df65c7f951e53001c3b8850f0f45c1f80f581c
4
- data.tar.gz: '048b188612f81942b978fac451b4777f8076f6e459275f84b6eab70effa2f9df'
3
+ metadata.gz: 8ad67b5ee3f9a3aaee804bc7288895ed9257ef360cf6abf670a4588371175aec
4
+ data.tar.gz: 175e6a998b895051513a99d288f0d63a3ce833a78dff4a25333bb1ba1d5bbf84
5
5
  SHA512:
6
- metadata.gz: 52fc5f481b7daf4472a3b25a98d588b4195071063b3c2283e7c6da75ec818ac4561bd41f1e33689d96bf4e98415c8bb7f3f836e4303075ca9af1a9020377ce97
7
- data.tar.gz: 2c3ad6f877a3466a0407567c0eaa3c181f37ea3b657dd79633ec7b1fde020bf4d9b9aa9212943d190620e26ff80723726f0b50ffb6c6a7c60f7812dbd1c33edb
6
+ metadata.gz: fc34eba228b9aa71024cf2f83025e6b8034b38394adccd7597b3cacccf636a9fc098262e89f956edadfd72b00f9367e923b6ddd92439de74c02d3095d4d5c385
7
+ data.tar.gz: 3f65d509d475c8ceb07e2bfd81ecc3197ea54c958678f3f8db87ad20baf9da80c792cf1967c215b08dbb3daf3a62985edd33643d7583fa988584c4a305481ef9
@@ -9,7 +9,7 @@
9
9
  <%= tag.div(section.summary, id: section.id(suffix: 'summary'), class: %w(govuk-accordion__section-summary govuk-body)) %>
10
10
  <% end %>
11
11
  </div>
12
- <%= tag.div(section.content, id: section.id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: section.id }) %>
12
+ <%= section %>
13
13
  <% end %>
14
14
  <% end %>
15
15
  <% end %>
@@ -1,8 +1,5 @@
1
- class GovukComponent::Accordion < GovukComponent::Base
2
- include ViewComponent::Slotable
3
-
4
- with_slot :section, collection: true, class_name: 'Section'
5
- wrap_slot :section
1
+ class GovukComponent::AccordionComponent < GovukComponent::Base
2
+ renders_many :sections, "Section"
6
3
 
7
4
  attr_accessor :id
8
5
 
@@ -18,7 +15,7 @@ private
18
15
  %w(govuk-accordion)
19
16
  end
20
17
 
21
- class Section < GovukComponent::Slot
18
+ class Section < GovukComponent::Base
22
19
  attr_accessor :title, :summary, :expanded
23
20
 
24
21
  alias_method :expanded?, :expanded
@@ -39,6 +36,10 @@ private
39
36
  super + (expanded? ? %w(govuk-accordion__section--expanded) : [])
40
37
  end
41
38
 
39
+ def call
40
+ tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id })
41
+ end
42
+
42
43
  private
43
44
 
44
45
  def default_classes
@@ -1,4 +1,4 @@
1
- class GovukComponent::BackLink < GovukComponent::Base
1
+ class GovukComponent::BackLinkComponent < GovukComponent::Base
2
2
  attr_accessor :text, :href, :options
3
3
 
4
4
  def initialize(text:, href:, classes: nil, html_attributes: {})
@@ -8,6 +8,10 @@ class GovukComponent::BackLink < GovukComponent::Base
8
8
  @href = href
9
9
  end
10
10
 
11
+ def call
12
+ link_to(@text, @href, class: classes, **html_attributes)
13
+ end
14
+
11
15
  private
12
16
 
13
17
  def default_classes
@@ -1,17 +1,19 @@
1
1
  class GovukComponent::Base < ViewComponent::Base
2
+ include Govuk::Components::Helpers::CssUtilities
3
+
2
4
  include GovukComponent::Traits::CustomClasses
3
5
  include GovukComponent::Traits::CustomHtmlAttributes
4
6
 
5
- def initialize(classes: [], html_attributes: {})
7
+ attr_reader :html_attributes
8
+
9
+ def initialize(classes:, html_attributes:)
6
10
  @classes = parse_classes(classes)
7
11
  @html_attributes = html_attributes
12
+
13
+ super
8
14
  end
9
15
 
10
- # Redirect #add_name to #slot(:name) to make building components
11
- # with slots feel more DSL-like
12
- def self.wrap_slot(name)
13
- define_method(%(add_#{name})) do |*args, **kwargs, &block|
14
- slot(name, *args, **kwargs, &block)
15
- end
16
+ def default_classes
17
+ []
16
18
  end
17
19
  end
@@ -1,17 +1,14 @@
1
1
  <%= tag.div(class: classes, **html_attributes) do %>
2
2
  <ol class="govuk-breadcrumbs__list">
3
- <%- @breadcrumbs.each do |text, link| %>
3
+ <% @breadcrumbs.each do |text, link| %>
4
4
 
5
- <%- if link.present? -%>
5
+ <% if link.present? %>
6
6
  <li class="govuk-breadcrumbs__list-item">
7
7
  <%= link_to(text, link, class: "govuk-breadcrumbs__link") %>
8
8
  </li>
9
9
  <% else %>
10
- <li class="govuk-breadcrumbs__list-item" aria-current="page">
11
- <%= text %>
12
- </li>
10
+ <%= tag.li(text, class: "govuk-breadcrumbs__list-item", aria: { current: "page" }) %>
13
11
  <% end %>
14
-
15
12
  <% end %>
16
13
  </ol>
17
14
  <% end %>
@@ -1,4 +1,4 @@
1
- class GovukComponent::Breadcrumbs < GovukComponent::Base
1
+ class GovukComponent::BreadcrumbsComponent < GovukComponent::Base
2
2
  attr_accessor :breadcrumbs
3
3
 
4
4
  def initialize(breadcrumbs:, hide_in_print: false, collapse_on_mobile: false, classes: [], html_attributes: {})
@@ -3,14 +3,10 @@
3
3
  <div class="govuk-grid-row">
4
4
  <div class="govuk-grid-column-two-thirds">
5
5
  <% if title.present? %>
6
- <h2 class="govuk-cookie-banner__heading govuk-heading-m">
7
- <%= title %>
8
- </h2>
6
+ <%= tag.h2(title, class: %w(govuk-cookie-banner__heading govuk-heading-m)) %>
9
7
  <% end %>
10
8
 
11
- <div class="govuk-cookie-banner__content">
12
- <%= body %>
13
- </div>
9
+ <%= tag.div(body, class: "govuk-cookie-banner__content") %>
14
10
  </div>
15
11
  </div>
16
12
 
@@ -1,4 +1,4 @@
1
- class GovukComponent::CookieBanner < GovukComponent::Base
1
+ class GovukComponent::CookieBannerComponent < GovukComponent::Base
2
2
  renders_one :body
3
3
  renders_one :actions
4
4
 
@@ -0,0 +1,34 @@
1
+ class GovukComponent::DetailsComponent < GovukComponent::Base
2
+ attr_accessor :summary_text, :text
3
+
4
+ def initialize(summary_text:, text: nil, classes: [], html_attributes: {})
5
+ super(classes: classes, html_attributes: html_attributes)
6
+
7
+ @summary_text = summary_text
8
+ @text = text
9
+ end
10
+
11
+ def call
12
+ tag.details(class: classes, data: { module: "govuk-details" }, **html_attributes) do
13
+ safe_join([summary, description])
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def summary
20
+ tag.summary(class: "govuk-details__summary") do
21
+ tag.span(summary_text, class: "govuk-details__summary-text")
22
+ end
23
+ end
24
+
25
+ def description
26
+ tag.div(class: "govuk-details__text") do
27
+ content.presence || text
28
+ end
29
+ end
30
+
31
+ def default_classes
32
+ %w(govuk-details)
33
+ end
34
+ end
@@ -2,7 +2,7 @@
2
2
  <div class="govuk-width-container ">
3
3
  <div class="govuk-footer__meta">
4
4
  <% if meta.present? %>
5
- <%= meta.content %>
5
+ <%= meta %>
6
6
  <% else %>
7
7
  <div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
8
8
  <% if meta_items.any? %>
@@ -28,13 +28,11 @@
28
28
  <% end %>
29
29
 
30
30
  <% if meta_content.present? %>
31
- <%= meta_content.content %>
31
+ <%= meta_content %>
32
32
  <% end %>
33
33
  </div>
34
34
  <div class="govuk-footer__meta">
35
- <div class="govuk-footer__meta-item">
36
- <%= copyright %>
37
- </div>
35
+ <%= tag.div(copyright, class: "govuk-footer__meta-item") %>
38
36
  </div>
39
37
  <% end %>
40
38
  </div>
@@ -1,11 +1,6 @@
1
- class GovukComponent::Footer < GovukComponent::Base
2
- include ViewComponent::Slotable
3
-
4
- with_slot :meta_content
5
- wrap_slot :meta_content
6
-
7
- with_slot :meta
8
- wrap_slot :meta
1
+ class GovukComponent::FooterComponent < GovukComponent::Base
2
+ renders_one :meta_content
3
+ renders_one :meta
9
4
 
10
5
  attr_accessor :meta_items, :meta_items_title, :meta_licence, :copyright
11
6
 
@@ -0,0 +1,49 @@
1
+ <%= tag.header(class: classes, role: 'banner', data: { module: 'govuk-header' }, **html_attributes) do %>
2
+ <%= tag.div(class: container_classes) do %>
3
+ <div class="govuk-header__logo">
4
+ <%= link_to(@homepage_url, class: %w(govuk-header__link govuk-header__link--homepage)) do %>
5
+ <span class="govuk-header__logotype">
6
+ <% if custom_logo.present? %>
7
+ <%= custom_logo %>
8
+ <% else %>
9
+ <% if crown %>
10
+ <svg aria-hidden="true" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 132 97" height="30" width="36">
11
+ <path fill="currentColor" fill-rule="evenodd" d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"></path>
12
+ <image src="/assets/images/govuk-logotype-crown.png" xlink:href="" class="govuk-header__logotype-crown-fallback-image" width="36" height="32"></image>
13
+ </svg>
14
+ <% end %>
15
+ <%= tag.span(logotype, class: "govuk-header__logotype-text") %>
16
+ <% end %>
17
+ </span>
18
+ <% if product_name.present? %>
19
+ <%= product_name %>
20
+ <% end %>
21
+ <% end %>
22
+ </div>
23
+
24
+ <% if @service_name.present? || @items.present? %>
25
+ <div class="govuk-header__content">
26
+ <% if @service_name.present? %>
27
+ <%= link_to(@service_name, @service_url, class: %w(govuk-header__link govuk-header__link--service-name)) %>
28
+ <% end %>
29
+
30
+ <% if items.any? %>
31
+ <%= tag.button("Menu", type: "button", class: %w(govuk-header__menu-button govuk-js-header-toggle), aria: { controls: "navigation", label: menu_button_label }) %>
32
+ <nav>
33
+ <%= tag.ul(class: navigation_classes, id: "navigation", aria: { label: navigation_label }) do %>
34
+ <% items.each do |item| %>
35
+ <%= tag.li(class: item.classes.append(item.active_class), **item.html_attributes) do %>
36
+ <% if item.link? %>
37
+ <%= link_to(item.title, item.href, class: "govuk-header__link") %>
38
+ <% else %>
39
+ <%= item.title %>
40
+ <% end %>
41
+ <% end %>
42
+ <% end %>
43
+ <% end %>
44
+ </nav>
45
+ <% end %>
46
+ </div>
47
+ <% end %>
48
+ <% end %>
49
+ <% end %>
@@ -0,0 +1,110 @@
1
+ class GovukComponent::HeaderComponent < GovukComponent::Base
2
+ renders_many :items, "Item"
3
+ renders_one :custom_logo
4
+ renders_one :product_name, "ProductName"
5
+
6
+ attr_accessor :logotype,
7
+ :crown,
8
+ :homepage_url,
9
+ :service_name,
10
+ :service_url,
11
+ :menu_button_label,
12
+ :navigation_label
13
+
14
+ def initialize(classes: [],
15
+ html_attributes: {},
16
+ logotype: 'GOV.UK',
17
+ crown: true,
18
+ homepage_url: '/',
19
+ menu_button_label: 'Show or hide navigation menu',
20
+ navigation_classes: [],
21
+ navigation_label: 'Navigation menu',
22
+ service_name: nil,
23
+ service_url: '/',
24
+ container_classes: nil)
25
+
26
+ super(classes: classes, html_attributes: html_attributes)
27
+
28
+ @logotype = logotype
29
+ @crown = crown
30
+ @homepage_url = homepage_url
31
+ @service_name = service_name
32
+ @service_url = service_url
33
+ @menu_button_label = menu_button_label
34
+ @navigation_classes = navigation_classes
35
+ @navigation_label = navigation_label
36
+ @container_classes = container_classes
37
+ end
38
+
39
+ private
40
+
41
+ def default_classes
42
+ %w(govuk-header)
43
+ end
44
+
45
+ def navigation_classes
46
+ combine_classes(%w(govuk-header__navigation), @navigation_classes)
47
+ end
48
+
49
+ def container_classes
50
+ combine_classes(%w(govuk-header__container govuk-width-container), @container_classes)
51
+ end
52
+
53
+ class Item < GovukComponent::Base
54
+ attr_accessor :title, :href, :active
55
+
56
+ def initialize(title:, href: nil, active: false, classes: [], html_attributes: {})
57
+ super(classes: classes, html_attributes: html_attributes)
58
+
59
+ self.title = title
60
+ self.href = href
61
+ self.active = active
62
+ end
63
+
64
+ def active?
65
+ active
66
+ end
67
+
68
+ def active_class
69
+ %w(govuk-header__navigation-item--active) if active?
70
+ end
71
+
72
+ def link?
73
+ href.present?
74
+ end
75
+
76
+ private
77
+
78
+ def default_classes
79
+ %w(govuk-header__navigation-item)
80
+ end
81
+ end
82
+
83
+ class ProductName < GovukComponent::Base
84
+ attr_accessor :name
85
+
86
+ def initialize(name: nil, html_attributes: {}, classes: [])
87
+ super(classes: classes, html_attributes: html_attributes)
88
+
89
+ @name = name
90
+ end
91
+
92
+ def render?
93
+ @name.present? || content.present?
94
+ end
95
+
96
+ def call
97
+ if content.present?
98
+ tag.div(content, class: classes)
99
+ else
100
+ tag.span(@name, class: classes)
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def default_classes
107
+ %w(govuk-header__product-name)
108
+ end
109
+ end
110
+ end
@@ -1,4 +1,4 @@
1
- class GovukComponent::InsetText < GovukComponent::Base
1
+ class GovukComponent::InsetTextComponent < GovukComponent::Base
2
2
  attr_accessor :text
3
3
 
4
4
  def initialize(text: nil, classes: [], html_attributes: {})
@@ -8,11 +8,11 @@ class GovukComponent::InsetText < GovukComponent::Base
8
8
  end
9
9
 
10
10
  def call
11
- tag.div(class: classes, **html_attributes) { content.presence || @text }
11
+ tag.div(class: classes, **html_attributes) { content.presence || text }
12
12
  end
13
13
 
14
14
  def render?
15
- @text.present? || content.present?
15
+ text.present? || content.present?
16
16
  end
17
17
 
18
18
  private
@@ -0,0 +1,14 @@
1
+ <%= tag.div(class: classes, role: "region", aria: { labelledby: title_id }, data: data_params, **html_attributes) do %>
2
+ <div class="govuk-notification-banner__header">
3
+ <%= content_tag(title_tag, class: "govuk-notification-banner__title", id: title_id) do %>
4
+ <%= title %>
5
+ <% end %>
6
+ </div>
7
+ <div class="govuk-notification-banner__content">
8
+ <% headings.each do |heading| %>
9
+ <%= heading %>
10
+ <% end %>
11
+
12
+ <%= content %>
13
+ </div>
14
+ <% end %>
@@ -1,9 +1,7 @@
1
- class GovukComponent::NotificationBanner < GovukComponent::Base
1
+ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
2
2
  attr_reader :title, :title_id, :success, :title_heading_level, :disable_auto_focus
3
3
 
4
- include ViewComponent::Slotable
5
- with_slot :heading, collection: true, class_name: 'Heading'
6
- wrap_slot(:heading)
4
+ renders_many :headings, "Heading"
7
5
 
8
6
  def initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
9
7
  super(classes: classes, html_attributes: html_attributes)
@@ -15,16 +13,16 @@ class GovukComponent::NotificationBanner < GovukComponent::Base
15
13
  @disable_auto_focus = disable_auto_focus
16
14
  end
17
15
 
18
- def success_class
19
- %(govuk-notification-banner--success) if success?
16
+ def render?
17
+ headings.any? || content.present?
20
18
  end
21
19
 
22
- def success?
23
- @success
20
+ def classes
21
+ super.append(success_class).compact
24
22
  end
25
23
 
26
- def render?
27
- headings.any? || content.present?
24
+ def success_class
25
+ %(govuk-notification-banner--success) if success
28
26
  end
29
27
 
30
28
  def title_tag
@@ -33,13 +31,29 @@ class GovukComponent::NotificationBanner < GovukComponent::Base
33
31
  "h#{title_heading_level}"
34
32
  end
35
33
 
36
- class Heading < ViewComponent::Slot
37
- attr_accessor :text, :link_target, :link_text
34
+ class Heading < GovukComponent::Base
35
+ attr_accessor :text, :link_href, :link_text
36
+
37
+ def initialize(text: nil, link_text: nil, link_href: nil, classes: [], html_attributes: {})
38
+ super(classes: classes, html_attributes: html_attributes)
38
39
 
39
- def initialize(text: nil, link_text: nil, link_target: nil)
40
40
  @text = text
41
41
  @link_text = link_text
42
- @link_target = link_target
42
+ @link_href = link_href
43
+ end
44
+
45
+ def call
46
+ tag.div(class: classes, **html_attributes) do
47
+ if text.present?
48
+ safe_join([text, link].compact)
49
+ else
50
+ content
51
+ end
52
+ end
53
+ end
54
+
55
+ def link
56
+ link_to(link_text, link_href, class: 'govuk-notification-banner__link') if link_text.present? && link_href.present?
43
57
  end
44
58
 
45
59
  def default_classes