govuk-components 2.0.0b2 → 2.0.0b6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/govuk_component/accordion_component.html.erb +1 -11
  3. data/app/components/govuk_component/accordion_component.rb +18 -33
  4. data/app/components/govuk_component/accordion_component/section_component.html.erb +11 -0
  5. data/app/components/govuk_component/accordion_component/section_component.rb +41 -0
  6. data/app/components/govuk_component/back_link_component.rb +7 -3
  7. data/app/components/govuk_component/breadcrumbs_component.html.erb +2 -9
  8. data/app/components/govuk_component/breadcrumbs_component.rb +27 -4
  9. data/app/components/govuk_component/details_component.rb +8 -2
  10. data/app/components/govuk_component/footer_component.html.erb +4 -4
  11. data/app/components/govuk_component/footer_component.rb +45 -7
  12. data/app/components/govuk_component/header_component.html.erb +8 -8
  13. data/app/components/govuk_component/header_component.rb +30 -28
  14. data/app/components/govuk_component/inset_text_component.rb +9 -4
  15. data/app/components/govuk_component/notification_banner_component.html.erb +3 -3
  16. data/app/components/govuk_component/notification_banner_component.rb +16 -9
  17. data/app/components/govuk_component/panel_component.rb +2 -2
  18. data/app/components/govuk_component/phase_banner_component.rb +4 -4
  19. data/app/components/govuk_component/start_button_component.rb +3 -3
  20. data/app/components/govuk_component/summary_list_component.rb +13 -8
  21. data/app/components/govuk_component/tag_component.rb +13 -19
  22. data/app/components/govuk_component/warning_text_component.rb +1 -1
  23. data/app/helpers/govuk_components_helper.rb +1 -1
  24. data/app/helpers/govuk_link_helper.rb +95 -11
  25. data/app/helpers/govuk_skip_link_helper.rb +7 -2
  26. data/lib/govuk/components/version.rb +1 -1
  27. metadata +10 -23
  28. data/app/components/govuk_component/slot.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d78b72089a8fad902b686ad63ecb7b101a7353a5e59bbd70369d929eb3f9b8ab
4
- data.tar.gz: f72eff8f23f2a8a808f21ea5cb14be0574a61ba6688e8e137fec6387ea6f44d7
3
+ metadata.gz: 71ba722e8aa82977774d53d3b6d8352dbceddc1966974f356aca9e4337c9b086
4
+ data.tar.gz: 193426f137c69991e3d7bf57b005141778ea48d24026158af303450ed326b768
5
5
  SHA512:
6
- metadata.gz: bb0b5e3653d68b5e53a8931204ce9a973d6cc8f5e778ea3d8950cd8c9499eafe6c2080b7a973ca53284d9e7de9dc0fa31bda6df3c1aa908d2477b06d4f964f7c
7
- data.tar.gz: b7d8992142ec9627c957f63082b66dbacbee454e2a837209f3dd86d4fe018c929c2f113942a11d368afeb3569f210fc7ce1ed3e5c22bb211141c9ef915588912
6
+ metadata.gz: eed11ed8f35f73dcf0328cd6d9640037ba2971e105b6258f039eba78b183fb425a8aa2d1b4e632dfa6cecbadb443395659384d14a9ca657bc7fa190f7ebc2222
7
+ data.tar.gz: bc13182bb9c0ef100fe4ee4bc1ceb09ab98eedfc87a47bf538cc06d7fe5f3a01ab646fdb2f1aee96f04dd0c4760b66fc0d3a1e45b868965a11c145706a5ab5aa
@@ -1,15 +1,5 @@
1
1
  <%= tag.div(id: @id, class: classes, data: { module: 'govuk-accordion' }, **html_attributes) do %>
2
2
  <% sections.each do |section| %>
3
- <%= tag.div(id: section.id(suffix: 'section'), class: section.classes, **section.html_attributes) do %>
4
- <div class="govuk-accordion__section-header">
5
- <h2 class="govuk-accordion__section-heading">
6
- <%= tag.span(section.title, id: section.id, class: "govuk-accordion__section-button", aria: { expanded: section.expanded?, controls: section.id(suffix: 'content') }) %>
7
- </h2>
8
- <% if section.summary.present? %>
9
- <%= tag.div(section.summary, id: section.id(suffix: 'summary'), class: %w(govuk-accordion__section-summary govuk-body)) %>
10
- <% end %>
11
- </div>
12
- <%= section %>
13
- <% end %>
3
+ <%= section %>
14
4
  <% end %>
15
5
  <% end %>
@@ -1,12 +1,23 @@
1
1
  class GovukComponent::AccordionComponent < GovukComponent::Base
2
- renders_many :sections, "Section"
2
+ renders_many :sections, ->(heading_text: nil, summary_text: nil, expanded: false, classes: [], html_attributes: {}, &block) do
3
+ GovukComponent::AccordionComponent::SectionComponent.new(
4
+ classes: classes,
5
+ expanded: expanded,
6
+ heading_level: heading_level, # set once at parent level, passed to all children
7
+ html_attributes: html_attributes,
8
+ summary_text: summary_text,
9
+ heading_text: heading_text,
10
+ &block
11
+ )
12
+ end
3
13
 
4
- attr_accessor :id
14
+ attr_reader :id, :heading_level
5
15
 
6
- def initialize(id: nil, classes: [], html_attributes: {})
16
+ def initialize(id: nil, heading_level: 2, classes: [], html_attributes: {})
7
17
  super(classes: classes, html_attributes: html_attributes)
8
18
 
9
- @id = id
19
+ @id = id
20
+ @heading_level = heading_tag(heading_level)
10
21
  end
11
22
 
12
23
  private
@@ -15,35 +26,9 @@ private
15
26
  %w(govuk-accordion)
16
27
  end
17
28
 
18
- class Section < GovukComponent::Base
19
- attr_accessor :title, :summary, :expanded
20
-
21
- alias_method :expanded?, :expanded
22
-
23
- def initialize(title:, summary: nil, expanded: false, classes: [], html_attributes: {})
24
- super(classes: classes, html_attributes: html_attributes)
25
-
26
- self.title = title
27
- self.summary = summary
28
- self.expanded = expanded
29
- end
30
-
31
- def id(suffix: nil)
32
- [title.parameterize, suffix].compact.join('-')
33
- end
34
-
35
- def classes
36
- super + (expanded? ? %w(govuk-accordion__section--expanded) : [])
37
- end
38
-
39
- def call
40
- tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id })
41
- end
42
-
43
- private
29
+ def heading_tag(level)
30
+ fail(ArgumentError, "heading_level must be 1-6") unless level.in?(1..6)
44
31
 
45
- def default_classes
46
- %w(govuk-accordion__section)
47
- end
32
+ %(h#{level})
48
33
  end
49
34
  end
@@ -0,0 +1,11 @@
1
+ <%= tag.div(id: id(suffix: 'section'), class: classes, **html_attributes) do %>
2
+ <div class="govuk-accordion__section-header">
3
+ <%= content_tag(heading_level, class: "govuk-accordion__section-heading") do %>
4
+ <%= tag.span(heading_content, id: id, class: "govuk-accordion__section-button", aria: { expanded: expanded?, controls: id(suffix: 'content') }) %>
5
+ <% end %>
6
+ <% if summary_content.present? %>
7
+ <%= tag.div(summary_content, id: id(suffix: 'summary'), class: %w(govuk-accordion__section-summary govuk-body)) %>
8
+ <% end %>
9
+ </div>
10
+ <%= tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id }) %>
11
+ <% end %>
@@ -0,0 +1,41 @@
1
+ class GovukComponent::AccordionComponent::SectionComponent < GovukComponent::Base
2
+ attr_reader :heading_text, :summary_text, :expanded, :heading_level
3
+
4
+ renders_one :heading_html
5
+ renders_one :summary_html
6
+
7
+ alias_method :expanded?, :expanded
8
+
9
+ def initialize(heading_text:, summary_text:, expanded:, heading_level:, classes: [], html_attributes: {})
10
+ super(classes: classes, html_attributes: html_attributes)
11
+
12
+ @heading_text = heading_text
13
+ @summary_text = summary_text
14
+ @expanded = expanded
15
+ @heading_level = heading_level
16
+ end
17
+
18
+ def id(suffix: nil)
19
+ # generate a random number if we don't have heading_text to avoid attempting
20
+ # to parameterize a potentially-huge chunk of HTML
21
+ @prefix ||= heading_text&.parameterize || SecureRandom.hex(4)
22
+
23
+ [@prefix, suffix].compact.join('-')
24
+ end
25
+
26
+ def heading_content
27
+ heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html")
28
+ end
29
+
30
+ def summary_content
31
+ summary_html || summary_text
32
+ end
33
+
34
+ private
35
+
36
+ def default_classes
37
+ %w(govuk-accordion__section).tap do |classes|
38
+ classes.append("govuk-accordion__section--expanded") if expanded?
39
+ end
40
+ end
41
+ end
@@ -1,7 +1,7 @@
1
1
  class GovukComponent::BackLinkComponent < GovukComponent::Base
2
- attr_accessor :text, :href, :options
2
+ attr_reader :text, :href
3
3
 
4
- def initialize(text:, href:, classes: nil, html_attributes: {})
4
+ def initialize(href:, text: nil, classes: nil, html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
7
  @text = text
@@ -9,11 +9,15 @@ class GovukComponent::BackLinkComponent < GovukComponent::Base
9
9
  end
10
10
 
11
11
  def call
12
- link_to(@text, @href, class: classes, **html_attributes)
12
+ link_to(link_content, href, class: classes, **html_attributes)
13
13
  end
14
14
 
15
15
  private
16
16
 
17
+ def link_content
18
+ text || content || fail(ArgumentError, "no text or content")
19
+ end
20
+
17
21
  def default_classes
18
22
  %w(govuk-back-link)
19
23
  end
@@ -1,14 +1,7 @@
1
1
  <%= tag.div(class: classes, **html_attributes) do %>
2
2
  <ol class="govuk-breadcrumbs__list">
3
- <% @breadcrumbs.each do |text, link| %>
4
-
5
- <% if link.present? %>
6
- <li class="govuk-breadcrumbs__list-item">
7
- <%= link_to(text, link, class: "govuk-breadcrumbs__link") %>
8
- </li>
9
- <% else %>
10
- <%= tag.li(text, class: "govuk-breadcrumbs__list-item", aria: { current: "page" }) %>
11
- <% end %>
3
+ <% @breadcrumbs.each do |link| %>
4
+ <%= link %>
12
5
  <% end %>
13
6
  </ol>
14
7
  <% end %>
@@ -1,10 +1,10 @@
1
1
  class GovukComponent::BreadcrumbsComponent < GovukComponent::Base
2
- attr_accessor :breadcrumbs
2
+ attr_reader :breadcrumbs, :hide_in_print, :collapse_on_mobile
3
3
 
4
4
  def initialize(breadcrumbs:, hide_in_print: false, collapse_on_mobile: false, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
- @breadcrumbs = breadcrumbs
7
+ @breadcrumbs = build_list(breadcrumbs)
8
8
  @hide_in_print = hide_in_print
9
9
  @collapse_on_mobile = collapse_on_mobile
10
10
  end
@@ -13,8 +13,31 @@ private
13
13
 
14
14
  def default_classes
15
15
  %w(govuk-breadcrumbs).tap do |classes|
16
- classes << "govuk-!-display-none-print" if @hide_in_print
17
- classes << "govuk-breadcrumbs--collapse-on-mobile" if @collapse_on_mobile
16
+ classes << "govuk-!-display-none-print" if hide_in_print
17
+ classes << "govuk-breadcrumbs--collapse-on-mobile" if collapse_on_mobile
18
18
  end
19
19
  end
20
+
21
+ def build_list(breadcrumbs)
22
+ case breadcrumbs
23
+ when Array
24
+ breadcrumbs.map { |item| build_list_item(item) }
25
+ when Hash
26
+ breadcrumbs.map { |text, link| build_list_item(text, link) }
27
+ else
28
+ fail(ArgumentError, "breadcrumb must be an array or hash")
29
+ end
30
+ end
31
+
32
+ def build_list_item(text, link = nil)
33
+ if link.present?
34
+ list_item { link_to(text, link, class: "govuk-breadcrumbs__link") }
35
+ else
36
+ list_item(aria: { current: "page" }) { text }
37
+ end
38
+ end
39
+
40
+ def list_item(html_attributes = {}, &block)
41
+ tag.li(class: "govuk-breadcrumbs__list-item", **html_attributes, &block)
42
+ end
20
43
  end
@@ -1,5 +1,7 @@
1
1
  class GovukComponent::DetailsComponent < GovukComponent::Base
2
- attr_accessor :summary_text, :text
2
+ attr_reader :summary_text, :text
3
+
4
+ renders_one :summary_html
3
5
 
4
6
  def initialize(summary_text:, text: nil, classes: [], html_attributes: {})
5
7
  super(classes: classes, html_attributes: html_attributes)
@@ -18,10 +20,14 @@ private
18
20
 
19
21
  def summary
20
22
  tag.summary(class: "govuk-details__summary") do
21
- tag.span(summary_text, class: "govuk-details__summary-text")
23
+ tag.span(summary_content, class: "govuk-details__summary-text")
22
24
  end
23
25
  end
24
26
 
27
+ def summary_content
28
+ summary_html || summary_text
29
+ end
30
+
25
31
  def description
26
32
  tag.div(class: "govuk-details__text") do
27
33
  content.presence || text
@@ -1,6 +1,6 @@
1
1
  <%= tag.footer(class: classes, role: 'contentinfo', **html_attributes) do %>
2
- <div class="govuk-width-container ">
3
- <div class="govuk-footer__meta">
2
+ <%= tag.div(class: container_classes, **container_html_attributes) do %>
3
+ <%= tag.div(class: meta_classes, **meta_html_attributes) do %>
4
4
  <% if meta.present? %>
5
5
  <%= meta %>
6
6
  <% else %>
@@ -35,6 +35,6 @@
35
35
  <%= tag.div(copyright, class: "govuk-footer__meta-item") %>
36
36
  </div>
37
37
  <% end %>
38
- </div>
39
- </div>
38
+ <% end %>
39
+ <% end %>
40
40
  <% end %>
@@ -1,16 +1,34 @@
1
1
  class GovukComponent::FooterComponent < GovukComponent::Base
2
- renders_one :meta_content
2
+ renders_one :meta_html
3
3
  renders_one :meta
4
4
 
5
- attr_accessor :meta_items, :meta_items_title, :meta_licence, :copyright
5
+ attr_reader :meta_items, :meta_text, :meta_items_title, :meta_licence, :copyright, :custom_container_classes
6
6
 
7
- def initialize(meta_items: {}, meta_items_title: "Support links", meta_licence: nil, classes: [], html_attributes: {}, copyright_text: default_copright_text, copyright_url: default_copyright_url)
7
+ def initialize(
8
+ classes: [],
9
+ container_classes: [],
10
+ container_html_attributes: {},
11
+ copyright_text: default_copright_text,
12
+ copyright_url: default_copyright_url,
13
+ html_attributes: {},
14
+ meta_items: {},
15
+ meta_items_title: "Support links",
16
+ meta_licence: nil,
17
+ meta_text: nil,
18
+ meta_classes: [],
19
+ meta_html_attributes: {}
20
+ )
8
21
  super(classes: classes, html_attributes: html_attributes)
9
22
 
10
- @meta_items = build_meta_links(meta_items)
11
- @meta_items_title = meta_items_title
12
- @meta_licence = meta_licence
13
- @copyright = build_copyright(copyright_text, copyright_url)
23
+ @meta_text = meta_text
24
+ @meta_items = build_meta_links(meta_items)
25
+ @meta_items_title = meta_items_title
26
+ @meta_licence = meta_licence
27
+ @custom_meta_classes = meta_classes
28
+ @custom_meta_html_attributes = meta_html_attributes
29
+ @copyright = build_copyright(copyright_text, copyright_url)
30
+ @custom_container_classes = container_classes
31
+ @custom_container_html_attributes = container_html_attributes
14
32
  end
15
33
 
16
34
  private
@@ -19,6 +37,26 @@ private
19
37
  %w(govuk-footer)
20
38
  end
21
39
 
40
+ def container_classes
41
+ combine_classes(%w(govuk-width-container), custom_container_classes)
42
+ end
43
+
44
+ def meta_content
45
+ meta_html || meta_text
46
+ end
47
+
48
+ def meta_classes
49
+ %w(govuk-footer__meta).append(@custom_meta_classes)
50
+ end
51
+
52
+ def meta_html_attributes
53
+ @custom_meta_html_attributes
54
+ end
55
+
56
+ def container_html_attributes
57
+ @custom_container_html_attributes
58
+ end
59
+
22
60
  def build_meta_links(links)
23
61
  return [] if links.blank?
24
62
 
@@ -1,7 +1,7 @@
1
1
  <%= tag.header(class: classes, role: 'banner', data: { module: 'govuk-header' }, **html_attributes) do %>
2
2
  <%= tag.div(class: container_classes) do %>
3
3
  <div class="govuk-header__logo">
4
- <%= link_to(@homepage_url, class: %w(govuk-header__link govuk-header__link--homepage)) do %>
4
+ <%= link_to(homepage_url, class: %w(govuk-header__link govuk-header__link--homepage)) do %>
5
5
  <span class="govuk-header__logotype">
6
6
  <% if custom_logo.present? %>
7
7
  <%= custom_logo %>
@@ -21,22 +21,22 @@
21
21
  <% end %>
22
22
  </div>
23
23
 
24
- <% if @service_name.present? || @items.present? %>
24
+ <% if service_name.present? || navigation_items.present? %>
25
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)) %>
26
+ <% if service_name.present? %>
27
+ <%= link_to(service_name, service_url, class: %w(govuk-header__link govuk-header__link--service-name)) %>
28
28
  <% end %>
29
29
 
30
- <% if items.any? %>
30
+ <% if navigation_items.any? %>
31
31
  <%= tag.button("Menu", type: "button", class: %w(govuk-header__menu-button govuk-js-header-toggle), aria: { controls: "navigation", label: menu_button_label }) %>
32
32
  <nav>
33
33
  <%= tag.ul(class: navigation_classes, id: "navigation", aria: { label: navigation_label }) do %>
34
- <% items.each do |item| %>
34
+ <% navigation_items.each do |item| %>
35
35
  <%= tag.li(class: item.classes.append(item.active_class), **item.html_attributes) do %>
36
36
  <% if item.link? %>
37
- <%= link_to(item.title, item.href, class: "govuk-header__link") %>
37
+ <%= link_to(item.text, item.href, class: "govuk-header__link") %>
38
38
  <% else %>
39
- <%= item.title %>
39
+ <%= item.text %>
40
40
  <% end %>
41
41
  <% end %>
42
42
  <% end %>
@@ -1,15 +1,17 @@
1
1
  class GovukComponent::HeaderComponent < GovukComponent::Base
2
- renders_many :items, "Item"
2
+ renders_many :navigation_items, "NavigationItem"
3
3
  renders_one :custom_logo
4
4
  renders_one :product_name, "ProductName"
5
5
 
6
- attr_accessor :logotype,
7
- :crown,
8
- :homepage_url,
9
- :service_name,
10
- :service_url,
11
- :menu_button_label,
12
- :navigation_label
6
+ attr_reader :logotype,
7
+ :crown,
8
+ :homepage_url,
9
+ :service_name,
10
+ :service_url,
11
+ :menu_button_label,
12
+ :navigation_label,
13
+ :custom_navigation_classes,
14
+ :custom_container_classes
13
15
 
14
16
  def initialize(classes: [],
15
17
  html_attributes: {},
@@ -25,15 +27,15 @@ class GovukComponent::HeaderComponent < GovukComponent::Base
25
27
 
26
28
  super(classes: classes, html_attributes: html_attributes)
27
29
 
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
30
+ @logotype = logotype
31
+ @crown = crown
32
+ @homepage_url = homepage_url
33
+ @service_name = service_name
34
+ @service_url = service_url
35
+ @menu_button_label = menu_button_label
36
+ @custom_navigation_classes = navigation_classes
37
+ @navigation_label = navigation_label
38
+ @custom_container_classes = container_classes
37
39
  end
38
40
 
39
41
  private
@@ -43,22 +45,22 @@ private
43
45
  end
44
46
 
45
47
  def navigation_classes
46
- combine_classes(%w(govuk-header__navigation), @navigation_classes)
48
+ combine_classes(%w(govuk-header__navigation), custom_navigation_classes)
47
49
  end
48
50
 
49
51
  def container_classes
50
- combine_classes(%w(govuk-header__container govuk-width-container), @container_classes)
52
+ combine_classes(%w(govuk-header__container govuk-width-container), custom_container_classes)
51
53
  end
52
54
 
53
- class Item < GovukComponent::Base
54
- attr_accessor :title, :href, :active
55
+ class NavigationItem < GovukComponent::Base
56
+ attr_reader :text, :href, :active
55
57
 
56
- def initialize(title:, href: nil, active: false, classes: [], html_attributes: {})
58
+ def initialize(text:, href: nil, active: false, classes: [], html_attributes: {})
57
59
  super(classes: classes, html_attributes: html_attributes)
58
60
 
59
- self.title = title
60
- self.href = href
61
- self.active = active
61
+ @text = text
62
+ @href = href
63
+ @active = active
62
64
  end
63
65
 
64
66
  def active?
@@ -81,7 +83,7 @@ private
81
83
  end
82
84
 
83
85
  class ProductName < GovukComponent::Base
84
- attr_accessor :name
86
+ attr_reader :name
85
87
 
86
88
  def initialize(name: nil, html_attributes: {}, classes: [])
87
89
  super(classes: classes, html_attributes: html_attributes)
@@ -90,14 +92,14 @@ private
90
92
  end
91
93
 
92
94
  def render?
93
- @name.present? || content.present?
95
+ name.present? || content.present?
94
96
  end
95
97
 
96
98
  def call
97
99
  if content.present?
98
100
  tag.div(content, class: classes)
99
101
  else
100
- tag.span(@name, class: classes)
102
+ tag.span(name, class: classes)
101
103
  end
102
104
  end
103
105
 
@@ -1,22 +1,27 @@
1
1
  class GovukComponent::InsetTextComponent < GovukComponent::Base
2
- attr_accessor :text
2
+ attr_reader :text, :id
3
3
 
4
- def initialize(text: nil, classes: [], html_attributes: {})
4
+ def initialize(text: nil, id: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
7
  @text = text
8
+ @id = id
8
9
  end
9
10
 
10
11
  def call
11
- tag.div(class: classes, **html_attributes) { content.presence || text }
12
+ tag.div(class: classes, id: id, **html_attributes) { inset_text_content }
12
13
  end
13
14
 
14
15
  def render?
15
- text.present? || content.present?
16
+ inset_text_content.present?
16
17
  end
17
18
 
18
19
  private
19
20
 
21
+ def inset_text_content
22
+ content.presence || text
23
+ end
24
+
20
25
  def default_classes
21
26
  %w(govuk-inset-text)
22
27
  end
@@ -1,7 +1,7 @@
1
- <%= tag.div(class: classes, role: "region", aria: { labelledby: title_id }, data: data_params, **html_attributes) do %>
1
+ <%= tag.div(class: classes, role: role, aria: { labelledby: title_id }, data: data_params, **html_attributes) do %>
2
2
  <div class="govuk-notification-banner__header">
3
3
  <%= content_tag(title_tag, class: "govuk-notification-banner__title", id: title_id) do %>
4
- <%= title %>
4
+ <%= title_content %>
5
5
  <% end %>
6
6
  </div>
7
7
  <div class="govuk-notification-banner__content">
@@ -9,6 +9,6 @@
9
9
  <%= heading %>
10
10
  <% end %>
11
11
 
12
- <%= content %>
12
+ <%= content || text %>
13
13
  </div>
14
14
  <% end %>
@@ -1,20 +1,23 @@
1
1
  class GovukComponent::NotificationBannerComponent < GovukComponent::Base
2
- attr_reader :title, :title_id, :success, :title_heading_level, :disable_auto_focus
2
+ attr_reader :title_text, :title_id, :text, :success, :title_heading_level, :disable_auto_focus, :role
3
3
 
4
+ renders_one :title_html
4
5
  renders_many :headings, "Heading"
5
6
 
6
- def initialize(title:, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
7
+ def initialize(title_text: nil, text: nil, role: "region", success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
7
8
  super(classes: classes, html_attributes: html_attributes)
8
9
 
9
- @title = title
10
+ @title_text = title_text
10
11
  @title_id = title_id
12
+ @text = text
13
+ @role = role
11
14
  @success = success
12
15
  @title_heading_level = title_heading_level
13
16
  @disable_auto_focus = disable_auto_focus
14
17
  end
15
18
 
16
19
  def render?
17
- headings.any? || content.present?
20
+ headings.any? || text.present? || content.present?
18
21
  end
19
22
 
20
23
  def classes
@@ -25,6 +28,10 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
25
28
  %(govuk-notification-banner--success) if success
26
29
  end
27
30
 
31
+ def title_content
32
+ title_html || title_text
33
+ end
34
+
28
35
  def title_tag
29
36
  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)
30
37
 
@@ -32,20 +39,20 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
32
39
  end
33
40
 
34
41
  class Heading < GovukComponent::Base
35
- attr_accessor :text, :link_href, :link_text
42
+ attr_reader :text, :link_href, :link_text
36
43
 
37
44
  def initialize(text: nil, link_text: nil, link_href: nil, classes: [], html_attributes: {})
38
45
  super(classes: classes, html_attributes: html_attributes)
39
46
 
40
- @text = text
41
- @link_text = link_text
42
- @link_href = link_href
47
+ @text = text
48
+ @link_text = link_text
49
+ @link_href = link_href
43
50
  end
44
51
 
45
52
  def call
46
53
  tag.div(class: classes, **html_attributes) do
47
54
  if text.present?
48
- safe_join([text, link].compact)
55
+ safe_join([text, link].compact, " ")
49
56
  else
50
57
  content
51
58
  end
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::PanelComponent < GovukComponent::Base
2
- attr_accessor :title, :body
2
+ attr_reader :title, :body
3
3
 
4
4
  def initialize(title: nil, body: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -35,7 +35,7 @@ private
35
35
  def panel_body
36
36
  if display_body?
37
37
  tag.div(class: "govuk-panel__body") do
38
- content.presence || @body
38
+ content.presence || body
39
39
  end
40
40
  end
41
41
  end
@@ -1,15 +1,15 @@
1
1
  class GovukComponent::PhaseBannerComponent < GovukComponent::Base
2
- attr_accessor :text
2
+ attr_reader :text, :phase_tag
3
3
 
4
- def initialize(phase_tag: nil, text: nil, classes: [], html_attributes: {})
4
+ def initialize(tag: nil, text: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
- @phase_tag = phase_tag
7
+ @phase_tag = tag
8
8
  @text = text
9
9
  end
10
10
 
11
11
  def phase_tag_component
12
- GovukComponent::TagComponent.new(classes: "govuk-phase-banner__content__tag", **@phase_tag)
12
+ GovukComponent::TagComponent.new(classes: "govuk-phase-banner__content__tag", **phase_tag)
13
13
  end
14
14
 
15
15
  private
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::StartButtonComponent < GovukComponent::Base
2
- attr_accessor :text, :href
2
+ attr_reader :text, :href
3
3
 
4
4
  def initialize(text:, href:, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
@@ -9,8 +9,8 @@ class GovukComponent::StartButtonComponent < GovukComponent::Base
9
9
  end
10
10
 
11
11
  def call
12
- link_to(@href, **default_attributes, **html_attributes) do
13
- safe_join([@text, icon])
12
+ link_to(href, **default_attributes, **html_attributes) do
13
+ safe_join([text, icon])
14
14
  end
15
15
  end
16
16
 
@@ -33,19 +33,24 @@ private
33
33
  def initialize(key:, value:, action: {}, classes: [], html_attributes: {})
34
34
  super(classes: classes, html_attributes: html_attributes)
35
35
 
36
- @key = key
37
- @value = value
38
- @href = action[:href]
39
- @text = action[:text] || "Change"
40
- @visually_hidden_text = " #{action[:visually_hidden_text] || key.downcase}"
41
- @action_classes = action[:classes] || []
42
- @action_attributes = action[:html_attributes] || {}
36
+ @key = key
37
+ @value = value
38
+
39
+ if action.present?
40
+ @href = action[:href]
41
+ @text = action[:text] || "Change"
42
+ @visually_hidden_text = " #{action[:visually_hidden_text] || key.downcase}"
43
+ @action_classes = action[:classes] || []
44
+ @action_attributes = action[:html_attributes] || {}
45
+ end
43
46
  end
44
47
 
45
48
  def action
49
+ link_classes = govuk_link_classes.append(action_classes).flatten
50
+
46
51
  tag.dd(class: "govuk-summary-list__actions") do
47
52
  if href.present?
48
- govuk_link_to(href, class: action_classes, **action_attributes) do
53
+ link_to(href, class: link_classes, **action_attributes) do
49
54
  safe_join([text, tag.span(visually_hidden_text, class: "govuk-visually-hidden")])
50
55
  end
51
56
  end
@@ -1,19 +1,9 @@
1
1
  class GovukComponent::TagComponent < GovukComponent::Base
2
- attr_reader :text
3
-
4
- COLOURS = %w(
5
- grey
6
- green
7
- turquoise
8
- blue
9
- red
10
- purple
11
- pink
12
- orange
13
- yellow
14
- ).freeze
15
-
16
- def initialize(text:, colour: nil, classes: [], html_attributes: {})
2
+ attr_reader :text, :colour
3
+
4
+ COLOURS = %w(grey green turquoise blue red purple pink orange yellow).freeze
5
+
6
+ def initialize(text: nil, colour: nil, classes: [], html_attributes: {})
17
7
  super(classes: classes, html_attributes: html_attributes)
18
8
 
19
9
  @text = text
@@ -21,21 +11,25 @@ class GovukComponent::TagComponent < GovukComponent::Base
21
11
  end
22
12
 
23
13
  def call
24
- tag.strong(@text, class: classes.append(colour_class), **html_attributes)
14
+ tag.strong(tag_content, class: classes.append(colour_class), **html_attributes)
25
15
  end
26
16
 
27
17
  private
28
18
 
19
+ def tag_content
20
+ @text || content || fail(ArgumentError, "no text or content")
21
+ end
22
+
29
23
  def default_classes
30
24
  %w(govuk-tag)
31
25
  end
32
26
 
33
27
  def colour_class
34
- return nil if @colour.blank?
28
+ return nil if colour.blank?
35
29
 
36
30
  fail(ArgumentError, colour_error_message) unless valid_colour?
37
31
 
38
- %(govuk-tag--#{@colour})
32
+ %(govuk-tag--#{colour})
39
33
  end
40
34
 
41
35
  def valid_colour?
@@ -43,6 +37,6 @@ private
43
37
  end
44
38
 
45
39
  def colour_error_message
46
- "invalid tag colour #{@colour}, supported colours are #{COLOURS.to_sentence}"
40
+ "invalid tag colour #{colour}, supported colours are #{COLOURS.to_sentence}"
47
41
  end
48
42
  end
@@ -12,7 +12,7 @@ class GovukComponent::WarningTextComponent < GovukComponent::Base
12
12
 
13
13
  def call
14
14
  tag.div(class: classes, **html_attributes) do
15
- safe_join([icon, strong])
15
+ safe_join([icon, (content || strong)])
16
16
  end
17
17
  end
18
18
 
@@ -11,7 +11,7 @@ module GovukComponentsHelper
11
11
  govuk_notification_banner: 'GovukComponent::NotificationBannerComponent',
12
12
  govuk_panel: 'GovukComponent::PanelComponent',
13
13
  govuk_phase_banner: 'GovukComponent::PhaseBannerComponent',
14
- govuk_start_now_button: 'GovukComponent::StartButtonComponent',
14
+ govuk_start_button: 'GovukComponent::StartButtonComponent',
15
15
  govuk_summary_list: 'GovukComponent::SummaryListComponent',
16
16
  govuk_tabs: 'GovukComponent::TabComponent',
17
17
  govuk_tag: 'GovukComponent::TagComponent',
@@ -1,26 +1,110 @@
1
1
  module GovukLinkHelper
2
- def govuk_link_to(*args, button: false, **kwargs, &block)
3
- link_to(*args, **inject_class(kwargs, class_name: link_class(button)), &block)
2
+ LINK_STYLES = {
3
+ inverse: "govuk-link--inverse",
4
+ muted: "govuk-link--muted",
5
+ no_underline: "govuk-link--no-underline",
6
+ no_visited_state: "govuk-link--no-visited-state",
7
+ text_colour: "govuk-link--text-colour",
8
+ }.freeze
9
+
10
+ BUTTON_STYLES = {
11
+ disabled: "govuk-button--disabled",
12
+ secondary: "govuk-button--secondary",
13
+ warning: "govuk-button--warning",
14
+ }.freeze
15
+
16
+ def govuk_link_classes(*styles, default_class: 'govuk-link')
17
+ if (invalid_styles = (styles - LINK_STYLES.keys)) && invalid_styles.any?
18
+ fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{LINK_STYLES.keys.to_sentence}")
19
+ end
20
+
21
+ [default_class] + LINK_STYLES.values_at(*styles).compact
22
+ end
23
+
24
+ def govuk_button_classes(*styles, default_class: 'govuk-button')
25
+ if (invalid_styles = (styles - BUTTON_STYLES.keys)) && invalid_styles.any?
26
+ fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{BUTTON_STYLES.keys.to_sentence}")
27
+ end
28
+
29
+ [default_class] + BUTTON_STYLES.values_at(*styles).compact
30
+ end
31
+
32
+ def govuk_link_to(name = nil, options = nil, extra_options = {}, &block)
33
+ extra_options = options if block_given?
34
+ html_options = build_html_options(extra_options)
35
+
36
+ if block_given?
37
+ link_to(name, html_options, &block)
38
+ else
39
+ link_to(name, options, html_options)
40
+ end
41
+ end
42
+
43
+ def govuk_mail_to(email_address, name = nil, extra_options = {}, &block)
44
+ extra_options = name if block_given?
45
+ html_options = build_html_options(extra_options)
46
+
47
+ if block_given?
48
+ mail_to(email_address, html_options, &block)
49
+ else
50
+ mail_to(email_address, name, html_options)
51
+ end
4
52
  end
5
53
 
6
- def govuk_mail_to(*args, button: false, **kwargs, &block)
7
- mail_to(*args, **inject_class(kwargs, class_name: link_class(button)), &block)
54
+ def govuk_button_to(name = nil, options = nil, extra_options = {}, &block)
55
+ extra_options = options if block_given?
56
+ html_options = build_html_options(extra_options, style: :button)
57
+
58
+ if block_given?
59
+ button_to(name, html_options, &block)
60
+ else
61
+ button_to(name, options, html_options)
62
+ end
8
63
  end
9
64
 
10
- def govuk_button_to(*args, **kwargs)
11
- button_to(*args, **inject_class(kwargs, class_name: 'govuk-button'))
65
+ def govuk_breadcrumb_link_to(name = nil, options = nil, extra_options = {}, &block)
66
+ extra_options = options if block_given?
67
+ html_options = build_html_options(extra_options, style: :breadcrumb)
68
+
69
+ if block_given?
70
+ link_to(name, html_options, &block)
71
+ else
72
+ link_to(name, options, html_options)
73
+ end
12
74
  end
13
75
 
14
76
  private
15
77
 
16
- def inject_class(attributes, class_name:)
17
- attributes.with_indifferent_access.tap do |attrs|
18
- attrs[:class] = Array.wrap(attrs[:class]).prepend(class_name)
78
+ def build_html_options(provided_options, style: :link)
79
+ styles = case style
80
+ when :link then LINK_STYLES
81
+ when :button then BUTTON_STYLES
82
+ else {}
83
+ end
84
+
85
+ remaining_options = provided_options&.slice!(*styles.keys)
86
+
87
+ return {} unless (style_classes = build_style_classes(style, provided_options))
88
+
89
+ inject_class(remaining_options, class_name: style_classes)
90
+ end
91
+
92
+ def build_style_classes(style, provided_options)
93
+ keys = *provided_options&.keys
94
+
95
+ case style
96
+ when :link then govuk_link_classes(*keys)
97
+ when :button then govuk_button_classes(*keys)
98
+ when :breadcrumb then %w(govuk-breadcrumbs__link)
19
99
  end
20
100
  end
21
101
 
22
- def link_class(button)
23
- button ? 'govuk-button' : 'govuk-link'
102
+ def inject_class(attributes, class_name:)
103
+ attributes ||= {}
104
+
105
+ attributes.with_indifferent_access.tap do |attrs|
106
+ attrs[:class] = Array.wrap(attrs[:class]).prepend(class_name).flatten
107
+ end
24
108
  end
25
109
  end
26
110
 
@@ -1,6 +1,11 @@
1
1
  module GovukSkipLinkHelper
2
- def govuk_skip_link(text: 'Skip to main content', href: '#main-content')
3
- link_to text, href, class: 'govuk-skip-link'
2
+ def govuk_skip_link(text: 'Skip to main content', href: '#main-content', classes: [], **html_attributes, &block)
3
+ link_classes = Array.wrap(classes).append('govuk-skip-link')
4
+
5
+ return link_to(href, class: link_classes, **html_attributes, &block) if block_given?
6
+
7
+ link_to(text, href, class: link_classes, **html_attributes)
4
8
  end
5
9
  end
10
+
6
11
  ActiveSupport.on_load(:action_view) { include GovukSkipLinkHelper }
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '2.0.0b2'.freeze
3
+ VERSION = '2.0.0b6'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0b2
4
+ version: 2.0.0b6
5
5
  platform: ruby
6
6
  authors:
7
7
  - DfE developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-06 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.31.1
55
- - !ruby/object:Gem::Dependency
56
- name: capybara
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: pry-byebug
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +100,14 @@ dependencies:
114
100
  requirements:
115
101
  - - '='
116
102
  - !ruby/object:Gem::Version
117
- version: 4.0.0.pre.1
103
+ version: 4.0.0
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - '='
123
109
  - !ruby/object:Gem::Version
124
- version: 4.0.0.pre.1
110
+ version: 4.0.0
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: sassc-rails
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +163,8 @@ files:
177
163
  - Rakefile
178
164
  - app/components/govuk_component/accordion_component.html.erb
179
165
  - app/components/govuk_component/accordion_component.rb
166
+ - app/components/govuk_component/accordion_component/section_component.html.erb
167
+ - app/components/govuk_component/accordion_component/section_component.rb
180
168
  - app/components/govuk_component/back_link_component.rb
181
169
  - app/components/govuk_component/base.rb
182
170
  - app/components/govuk_component/breadcrumbs_component.html.erb
@@ -194,7 +182,6 @@ files:
194
182
  - app/components/govuk_component/panel_component.rb
195
183
  - app/components/govuk_component/phase_banner_component.html.erb
196
184
  - app/components/govuk_component/phase_banner_component.rb
197
- - app/components/govuk_component/slot.rb
198
185
  - app/components/govuk_component/start_button_component.rb
199
186
  - app/components/govuk_component/summary_list_component.html.erb
200
187
  - app/components/govuk_component/summary_list_component.rb
@@ -218,7 +205,7 @@ homepage: https://github.com/DFE-Digital/govuk-components
218
205
  licenses:
219
206
  - MIT
220
207
  metadata: {}
221
- post_install_message:
208
+ post_install_message:
222
209
  rdoc_options: []
223
210
  require_paths:
224
211
  - lib
@@ -233,8 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
220
  - !ruby/object:Gem::Version
234
221
  version: 1.3.1
235
222
  requirements: []
236
- rubygems_version: 3.1.4
237
- signing_key:
223
+ rubygems_version: 3.1.6
224
+ signing_key:
238
225
  specification_version: 4
239
226
  summary: Lightweight set of reusable GOV.UK Design System components
240
227
  test_files: []
@@ -1,9 +0,0 @@
1
- class GovukComponent::Slot < ViewComponent::Slot
2
- include GovukComponent::Traits::CustomClasses
3
- include GovukComponent::Traits::CustomHtmlAttributes
4
-
5
- def initialize(classes: [], html_attributes: {})
6
- @classes = parse_classes(classes)
7
- @html_attributes = html_attributes
8
- end
9
- end