govuk-components 2.0.0b7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 841141c88cfcaed118afa205d0b0cee4652d73367807e19568325bc751d87e7b
4
- data.tar.gz: 6fa945dffee2ad40ca4b94b1c3847e1324442580611f1b9e372b684b0ea4ecd7
3
+ metadata.gz: 39ac79b41b17e5f17f5f6b80e195595ae1396f5d83a3a14c14564412831fdbc8
4
+ data.tar.gz: 587e0b9a9688c4c239e1e8cbdf44111c88aa82cd1014197293b308d0b2409f36
5
5
  SHA512:
6
- metadata.gz: d2a5f01d9e108932a99fdf57d8bfd0837151a8ff96254f2115dc8a4a02d50e16b60539749705fc9b3e54ee8a75269901ffc9ff9965a67fcb5f68b05ab5374d6b
7
- data.tar.gz: 767021e9a660ddcf0b6ce3df61f7363341ec0181d4f16fb0584a6c8ac19978eb717997a7c1773dad1ccda68e6a141225c7f67f2fde0ed99e841a6ca2cbac7c71
6
+ metadata.gz: 826c5c80a39daefff656c96139c8f3c0ad6ceaffa7c8000a482f5b35a085b0f3251c7ded964c5bff0bc7a977287f77ed4ca2f5e4684d73e279d589de946e97a3
7
+ data.tar.gz: cb1e686cf23ef788c4d45544bd1c4cc97cdb91a560a9ca7653d71b299dedfc735721b67b7d22062823f21283f56889e43e6a3b8e35eac29d8395cf9b1dfc169c
data/README.md CHANGED
@@ -4,61 +4,86 @@
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/cbcbc140f300b920d833/maintainability)](https://codeclimate.com/github/DFE-Digital/govuk-components/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cbcbc140f300b920d833/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk-components/test_coverage)
6
6
  [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk-components)](https://github.com/DFE-Digital/govuk-components/blob/master/LICENSE)
7
- [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=DFE-Digital/govuk-components)](https://dependabot.com)
8
- [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.10.2-brightgreen)](https://design-system.service.gov.uk)
7
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-3.13.0-brightgreen)](https://design-system.service.gov.uk)
9
8
 
10
9
  This gem provides a suite of reusable components for the [GOV.UK Design System](https://design-system.service.gov.uk/). It is intended to provide a lightweight alternative to the [GOV.UK Publishing Components](https://github.com/alphagov/govuk_publishing_components) library and is built with Github's [ViewComponent](https://github.com/github/view_component) framework.
11
10
 
12
- ## What's included
13
-
14
- | Component name | Helper |
15
- | -------------- | ------ |
16
- | [Accordion](app/components/govuk_component/accordion.rb) | `govuk_accordion` |
17
- | [Back link](app/components/govuk_component/back_link.rb) | `govuk_back_link` |
18
- | [Breadcrumbs](app/components/govuk_component/breadcrumbs.rb) | `govuk_breadcrumbs` |
19
- | [Cookie banner](app/components/govuk_component/cookie_banner.rb) | `govuk_cookie_banner` |
20
- | [Details](app/components/govuk_component/details.rb) | `govuk_details` |
21
- | [Footer](app/components/govuk_component/footer.rb) | `govuk_footer` |
22
- | [Header](app/components/govuk_component/header.rb) | `govuk_header` |
23
- | [Inset text](app/components/govuk_component/inset_text.rb) | `govuk_inset_text` |
24
- | [Notification banner](app/components/govuk_component/notification_banner.rb) | `govuk_notification_banner` |
25
- | [Panel](app/components/govuk_component/panel.rb) | `govuk_panel` |
26
- | [Phase banner](app/components/govuk_component/phase_banner.rb) | `govuk_phase_banner` |
27
- | [Start now button](app/components/govuk_component/start_now_button.rb) | `govuk_start_now_button` |
28
- | [Summary list](app/components/govuk_component/summary_list.rb) | `govuk_summary_list` |
29
- | [Tabs](app/components/govuk_component/tabs.rb) | `govuk_tabs` |
30
- | [Tag](app/components/govuk_component/tag.rb) | `govuk_tag` |
31
- | [Warning text](app/components/govuk_component/warning.rb) | `govuk_warning` |
32
-
33
- ### Helpers
34
-
35
- * `#govuk_link_to`
36
- * `#govuk_mail_to`
37
- * `#govuk_button_to`
38
- * `#govuk_back_to_top_link`
39
- * `#govuk_skip_link`
11
+ It aims to implement the functionality from the original Nunjucks macros in a way that will feel more familiar to Rails developers. Blocks are preferred over strings of HTML, beneath the surface each component is just a Ruby object, everything is inheritable and overrideable.
12
+
13
+ ## What's included?
14
+
15
+ All of the non-form components from the GOV.UK Design System are implmented by this library as ViewComponents. Form components are implemented by the [form builder](https://govuk-form-builder.netlify.app/).
16
+
17
+ The provided components are:
18
+
19
+ * [Accordion](https://dfe-digital.github.io/govuk-components/#accordion)
20
+ * [Back link](https://dfe-digital.github.io/govuk-components/#back-links)
21
+ * [Back to top link](https://dfe-digital.github.io/govuk-components/#back-to-top-link)
22
+ * [Breadcrumbs](https://dfe-digital.github.io/govuk-components/#breadcrumbs)
23
+ * [Cookie banner](https://dfe-digital.github.io/govuk-components/#cookie-banner)
24
+ * [Details](https://dfe-digital.github.io/govuk-components/#details)
25
+ * [Footer](https://dfe-digital.github.io/govuk-components/#footer)
26
+ * [Header](https://dfe-digital.github.io/govuk-components/#header)
27
+ * [Inset text](https://dfe-digital.github.io/govuk-components/#inset-text)
28
+ * [Notification banner](https://dfe-digital.github.io/govuk-components/#notification-banner)
29
+ * [Panel](https://dfe-digital.github.io/govuk-components/#panel)
30
+ * [Phase banner](https://dfe-digital.github.io/govuk-components/#phase-banner)
31
+ * [Skip link](https://dfe-digital.github.io/govuk-components/#skip-link)
32
+ * [Start button](https://dfe-digital.github.io/govuk-components/#start-button)
33
+ * [Summary list](https://dfe-digital.github.io/govuk-components/#summary-list)
34
+ * [Tabs](https://dfe-digital.github.io/govuk-components/#tabs)
35
+ * [Tags](https://dfe-digital.github.io/govuk-components/#tags)
36
+ * [Warning text](https://dfe-digital.github.io/govuk-components/#warning-text)
37
+
38
+ This library also provides [several link helpers](https://dfe-digital.github.io/govuk-components/#links-and-buttons) that are commonly used in services, including `#govuk_link_to` and `#govuk_button_to`.
39
+
40
+ ## Alternative syntax
41
+
42
+ All of the components can be rendered in two ways:
43
+
44
+ * directly using Rails' `#render` method:
45
+
46
+ ```erb
47
+ <%= render GovukComponent::GovukComponent::WarningTextComponent.new do %>
48
+ A serious warning
49
+ <% end %>
50
+ ```
51
+
52
+ * via the helper wrapper:
53
+
54
+ ```erb
55
+ <%= govuk_warning_text do %>
56
+ A serious warning
57
+ <% end %>
58
+ ```
59
+
60
+ The naming convention for helpers is `govuk_` followed by the component's name in snake case. You can
61
+ see the full list in [GovukComponentsHelper](app/helpers/govuk_components_helper.rb).
40
62
 
41
63
  ## Example use
42
64
 
43
- This library allows components to be rendered with Rails' `render` method or via the provided helpers. Here we'll use the `govuk_accordion` to render an accordion.
65
+ This library allows components to be rendered with Rails' `render` method or via the provided helpers. Here we'll use the `govuk_tabs` to render three tabbed sections:
44
66
 
45
67
  ```erb
46
- <%= govuk_accordion(id: 'def234') do |accordion| %>
47
- <%= accordion.add_section(title: 'Section 1') do %>
48
- <p class="govuk-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
68
+ <%= govuk_tabs(title: 'Days of the week') do |component| %>
69
+ <% component.tab(label: 'Monday') do %>
70
+ <p>Monday's child is fair of face</p>
49
71
  <% end %>
50
- <%= accordion.add_section(title: 'Section 2') do %>
51
- <p class="govuk-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
72
+
73
+ <% component.tab(label: 'Tuesday') do %>
74
+ <p>Tuesday's child is full of grace</p>
52
75
  <% end %>
53
- <%= accordion.add_section(title: 'Section 3') do %>
54
- <p class="govuk-body">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
76
+
77
+ <% component.tab(label: 'Wednesday') do %>
78
+ <p>Wednesday's child is full of woe</p>
55
79
  <% end %>
56
80
  <% end %>
81
+
57
82
  ```
58
83
 
59
- Here is the rendered accordion.
84
+ Here are the rendered tabs:
60
85
 
61
- ![Accordion preview](docs/images/accordion.png)
86
+ ![Tabs preview](docs/images/tabs.png)
62
87
 
63
88
  For examples on usage see the [guide page](https://dfe-digital.github.io/govuk-components/).
64
89
 
@@ -70,6 +95,15 @@ Add this line to your `config/application.rb`:
70
95
  require "govuk/components"
71
96
  ```
72
97
 
98
+ ## Services using this library
99
+
100
+ * [Apply for teacher training](https://github.com/DFE-Digital/apply-for-teacher-training)
101
+ * [Find postgraduate teacher training](https://github.com/DFE-Digital/find-teacher-training)
102
+ * [Get help with technology](https://github.com/DFE-Digital/get-help-with-tech)
103
+ * [Publish teacher training courses](https://github.com/DFE-Digital/publish-teacher-training)
104
+ * [Register trainee teachers](https://github.com/DFE-Digital/register-trainee-teachers)
105
+ * [Teaching Vacancies](https://github.com/DFE-Digital/teaching-vacancies)
106
+
73
107
  ## Installation
74
108
 
75
109
  Add this line to your application's Gemfile:
@@ -1,14 +1,19 @@
1
1
  class GovukComponent::CookieBannerComponent < GovukComponent::Base
2
- renders_one :body
3
- renders_one :actions
2
+ renders_many :messages, GovukComponent::CookieBannerComponent::MessageComponent
4
3
 
5
- attr_accessor :title, :aria_label
4
+ attr_accessor :aria_label, :hidden
6
5
 
7
- def initialize(title: nil, aria_label: "Cookie banner", classes: [], html_attributes: {})
6
+ def initialize(aria_label: "Cookie banner", hidden: false, classes: [], html_attributes: {})
8
7
  super(classes: classes, html_attributes: html_attributes)
9
8
 
10
- @title = title
11
9
  @aria_label = aria_label
10
+ @hidden = hidden
11
+ end
12
+
13
+ def call
14
+ tag.div(class: classes, role: "region", aria: { label: aria_label }, hidden: hidden, **html_attributes) do
15
+ safe_join(messages)
16
+ end
12
17
  end
13
18
 
14
19
  private
@@ -0,0 +1,62 @@
1
+ class GovukComponent::CookieBannerComponent::MessageComponent < GovukComponent::Base
2
+ attr_reader :heading_text, :text, :hidden, :role
3
+
4
+ renders_many :actions
5
+ renders_one :heading_html
6
+
7
+ def initialize(heading_text: nil, text: nil, hidden: false, role: nil, classes: [], html_attributes: {})
8
+ super(classes: classes, html_attributes: html_attributes)
9
+
10
+ @heading_text = heading_text
11
+ @text = text
12
+ @hidden = hidden
13
+ @role = role
14
+ end
15
+
16
+ def call
17
+ tag.div(class: classes, role: role, hidden: hidden, **html_attributes) do
18
+ safe_join([
19
+ tag.div(class: "govuk-grid-row") do
20
+ tag.div(class: "govuk-grid-column-two-thirds") { safe_join([heading_element, message_element]) }
21
+ end,
22
+ actions_element
23
+ ])
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def default_classes
30
+ %w(govuk-cookie-banner__message govuk-width-container)
31
+ end
32
+
33
+ def heading_element
34
+ return if heading_content.blank?
35
+
36
+ tag.h2(heading_content, class: %w(govuk-cookie-banner__heading govuk-heading-m))
37
+ end
38
+
39
+ def heading_content
40
+ heading_html || heading_text
41
+ end
42
+
43
+ def message_element
44
+ tag.div(message_content, class: "govuk-cookie-banner__content")
45
+ end
46
+
47
+ def message_content
48
+ content || wrap_in_p(text) || fail(ArgumentError, "no text or content")
49
+ end
50
+
51
+ def wrap_in_p(message_text)
52
+ return if message_text.blank?
53
+
54
+ tag.p(message_text)
55
+ end
56
+
57
+ def actions_element
58
+ return if actions.none?
59
+
60
+ tag.div(class: "govuk-button-group") { safe_join(actions) }
61
+ end
62
+ end
@@ -1,17 +1,19 @@
1
1
  class GovukComponent::DetailsComponent < GovukComponent::Base
2
- attr_reader :summary_text, :text
2
+ attr_reader :summary_text, :text, :id, :open
3
3
 
4
4
  renders_one :summary_html
5
5
 
6
- def initialize(summary_text:, text: nil, classes: [], html_attributes: {})
6
+ def initialize(summary_text:, text: nil, classes: [], id: nil, open: nil, html_attributes: {})
7
7
  super(classes: classes, html_attributes: html_attributes)
8
8
 
9
9
  @summary_text = summary_text
10
10
  @text = text
11
+ @id = id
12
+ @open = open
11
13
  end
12
14
 
13
15
  def call
14
- tag.details(class: classes, data: { module: "govuk-details" }, **html_attributes) do
16
+ tag.details(class: classes, data: { module: "govuk-details" }, id: id, open: open, **html_attributes) do
15
17
  safe_join([summary, description])
16
18
  end
17
19
  end
@@ -4,14 +4,14 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
4
4
  renders_one :title_html
5
5
  renders_many :headings, "Heading"
6
6
 
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
+ def initialize(title_text: nil, text: nil, role: nil, success: false, title_heading_level: 2, title_id: "govuk-notification-banner-title", disable_auto_focus: nil, classes: [], html_attributes: {})
8
8
  super(classes: classes, html_attributes: html_attributes)
9
9
 
10
10
  @title_text = title_text
11
11
  @title_id = title_id
12
12
  @text = text
13
- @role = role
14
13
  @success = success
14
+ @role = role || default_role
15
15
  @title_heading_level = title_heading_level
16
16
  @disable_auto_focus = disable_auto_focus
17
17
  end
@@ -20,24 +20,6 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
20
20
  headings.any? || text.present? || content.present?
21
21
  end
22
22
 
23
- def classes
24
- super.append(success_class).compact
25
- end
26
-
27
- def success_class
28
- %(govuk-notification-banner--success) if success
29
- end
30
-
31
- def title_content
32
- title_html || title_text
33
- end
34
-
35
- def title_tag
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)
37
-
38
- "h#{title_heading_level}"
39
- end
40
-
41
23
  class Heading < GovukComponent::Base
42
24
  attr_reader :text, :link_href, :link_text
43
25
 
@@ -77,4 +59,26 @@ private
77
59
  def data_params
78
60
  { "module" => "govuk-notification-banner", "disable-auto-focus" => disable_auto_focus }.compact
79
61
  end
62
+
63
+ def classes
64
+ super.append(success_class).compact
65
+ end
66
+
67
+ def success_class
68
+ %(govuk-notification-banner--success) if success
69
+ end
70
+
71
+ def title_content
72
+ title_html || title_text
73
+ end
74
+
75
+ def title_tag
76
+ 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)
77
+
78
+ "h#{title_heading_level}"
79
+ end
80
+
81
+ def default_role
82
+ success ? "alert" : "region"
83
+ end
80
84
  end
@@ -1,15 +1,19 @@
1
1
  class GovukComponent::PanelComponent < GovukComponent::Base
2
- attr_reader :title, :body
2
+ attr_reader :id, :title_text, :text, :heading_level
3
3
 
4
- def initialize(title: nil, body: nil, classes: [], html_attributes: {})
4
+ renders_one :title_html
5
+
6
+ def initialize(title_text: nil, text: nil, heading_level: 1, id: nil, classes: [], html_attributes: {})
5
7
  super(classes: classes, html_attributes: html_attributes)
6
8
 
7
- @title = title
8
- @body = body
9
+ @heading_level = heading_level
10
+ @title_text = title_text
11
+ @text = text
12
+ @id = id
9
13
  end
10
14
 
11
15
  def call
12
- tag.div(class: classes, **html_attributes) do
16
+ tag.div(id: id, class: classes, **html_attributes) do
13
17
  safe_join([panel_title, panel_body].compact)
14
18
  end
15
19
  end
@@ -20,27 +24,33 @@ private
20
24
  %w(govuk-panel govuk-panel--confirmation)
21
25
  end
22
26
 
23
- def display_title?
24
- title.present?
27
+ def heading_tag
28
+ "h#{heading_level}"
29
+ end
30
+
31
+ def panel_content
32
+ content || text
25
33
  end
26
34
 
27
- def display_body?
28
- body.present? || content.present?
35
+ def title
36
+ title_html || title_text
29
37
  end
30
38
 
31
39
  def panel_title
32
- tag.h1(title, class: "govuk-panel__title") if display_title?
40
+ return if title.blank?
41
+
42
+ content_tag(heading_tag, title, class: "govuk-panel__title")
33
43
  end
34
44
 
35
45
  def panel_body
36
- if display_body?
37
- tag.div(class: "govuk-panel__body") do
38
- content.presence || body
39
- end
46
+ return if panel_content.blank?
47
+
48
+ tag.div(class: "govuk-panel__body") do
49
+ panel_content
40
50
  end
41
51
  end
42
52
 
43
53
  def render?
44
- display_title? || display_body?
54
+ title.present? || panel_content.present?
45
55
  end
46
56
  end
@@ -1,11 +1,5 @@
1
1
  <%= tag.dl(class: classes, **html_attributes) do %>
2
2
  <% rows.each do |row| %>
3
- <%= tag.div(class: row.classes, **row.html_attributes) do %>
4
- <%= tag.dt(row.key, class: "govuk-summary-list__key") %>
5
- <%= tag.dd(row.value, class: "govuk-summary-list__value") %>
6
- <% if any_row_has_actions? %>
7
- <%= row.action %>
8
- <% end %>
9
- <% end %>
3
+ <%= row %>
10
4
  <% end %>
11
5
  <% end %>
@@ -1,7 +1,7 @@
1
1
  class GovukComponent::SummaryListComponent < GovukComponent::Base
2
2
  attr_reader :borders
3
3
 
4
- renders_many :rows, "Row"
4
+ renders_many :rows, GovukComponent::SummaryListComponent::RowComponent
5
5
 
6
6
  def initialize(borders: true, classes: [], html_attributes: {})
7
7
  super(classes: classes, html_attributes: html_attributes)
@@ -26,41 +26,4 @@ private
26
26
  def default_classes
27
27
  %w(govuk-summary-list)
28
28
  end
29
-
30
- class Row < GovukComponent::Base
31
- attr_reader :key, :value, :href, :text, :visually_hidden_text, :action_classes, :action_attributes
32
-
33
- def initialize(key:, value:, action: {}, classes: [], html_attributes: {})
34
- super(classes: classes, html_attributes: html_attributes)
35
-
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
46
- end
47
-
48
- def action
49
- link_classes = govuk_link_classes.append(action_classes).flatten
50
-
51
- tag.dd(class: "govuk-summary-list__actions") do
52
- if href.present?
53
- link_to(href, class: link_classes, **action_attributes) do
54
- safe_join([text, tag.span(visually_hidden_text, class: "govuk-visually-hidden")])
55
- end
56
- end
57
- end
58
- end
59
-
60
- private
61
-
62
- def default_classes
63
- %w(govuk-summary-list__row)
64
- end
65
- end
66
29
  end
@@ -0,0 +1,34 @@
1
+ class GovukComponent::SummaryListComponent::ActionComponent < GovukComponent::Base
2
+ attr_reader :href, :text, :visually_hidden_text, :attributes, :classes
3
+
4
+ def initialize(href: nil, text: 'Change', visually_hidden_text: nil, classes: [], html_attributes: {})
5
+ super(classes: classes, html_attributes: html_attributes)
6
+
7
+ @href = href
8
+ @text = text
9
+ @visually_hidden_text = visually_hidden_text
10
+ end
11
+
12
+ def call
13
+ # when no href is provided return an empty string so the dd container
14
+ # will render, it's useful in lists where some rows have actions
15
+ # and others don't
16
+ return "" if href.blank?
17
+
18
+ link_classes = govuk_link_classes.append(classes).flatten
19
+
20
+ link_to(href, class: link_classes, **html_attributes) do
21
+ safe_join([action_text, visually_hidden_span].compact, " ")
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def action_text
28
+ content || text || fail(ArgumentError, "no text or content")
29
+ end
30
+
31
+ def visually_hidden_span
32
+ tag.span(visually_hidden_text, class: "govuk-visually-hidden") if visually_hidden_text.present?
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ class GovukComponent::SummaryListComponent::KeyComponent < GovukComponent::Base
2
+ attr_reader :text
3
+
4
+ def initialize(text: nil, classes: [], html_attributes: {})
5
+ super(classes: classes, html_attributes: html_attributes)
6
+
7
+ @text = text
8
+ end
9
+
10
+ def call
11
+ tag.dt(key_content, class: classes, **html_attributes)
12
+ end
13
+
14
+ private
15
+
16
+ def default_classes
17
+ %w(govuk-summary-list__key)
18
+ end
19
+
20
+ def key_content
21
+ content || text || fail(ArgumentError, "no text or content")
22
+ end
23
+ end
@@ -0,0 +1,45 @@
1
+ class GovukComponent::SummaryListComponent::RowComponent < GovukComponent::Base
2
+ attr_reader :href, :visually_hidden_text
3
+
4
+ renders_one :key, GovukComponent::SummaryListComponent::KeyComponent
5
+ renders_one :value, GovukComponent::SummaryListComponent::ValueComponent
6
+ renders_many :actions, GovukComponent::SummaryListComponent::ActionComponent
7
+
8
+ def initialize(classes: [], html_attributes: {})
9
+ super(classes: classes, html_attributes: html_attributes)
10
+ end
11
+
12
+ def call
13
+ tag.div(class: classes, **html_attributes) do
14
+ safe_join([key, value, actions_content])
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def actions_content
21
+ return if actions.blank?
22
+
23
+ (actions.one?) ? single_action : actions_list
24
+ end
25
+
26
+ def single_action
27
+ tag.dd(class: actions_class) { safe_join(actions) }
28
+ end
29
+
30
+ def actions_list
31
+ tag.dd(class: actions_class) do
32
+ tag.ul(class: "govuk-summary-list__actions-list") do
33
+ safe_join(actions.map { |action| tag.li(action, class: "govuk-summary-list__actions-list-item") })
34
+ end
35
+ end
36
+ end
37
+
38
+ def default_classes
39
+ %w(govuk-summary-list__row)
40
+ end
41
+
42
+ def actions_class
43
+ "govuk-summary-list__actions"
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ class GovukComponent::SummaryListComponent::ValueComponent < GovukComponent::Base
2
+ attr_reader :text
3
+
4
+ def initialize(text: nil, classes: [], html_attributes: {})
5
+ super(classes: classes, html_attributes: html_attributes)
6
+
7
+ @text = text
8
+ end
9
+
10
+ def call
11
+ tag.dd(value_content, class: classes, **html_attributes)
12
+ end
13
+
14
+ private
15
+
16
+ def default_classes
17
+ %w(govuk-summary-list__value)
18
+ end
19
+
20
+ def value_content
21
+ content || text || ""
22
+ end
23
+ end
@@ -1,4 +1,4 @@
1
- <%= tag.div(class: classes, data: { module: 'govuk-tabs' }, **html_attributes) do %>
1
+ <%= tag.div(id: id, class: classes, data: { module: 'govuk-tabs' }, **html_attributes) do %>
2
2
  <%= tag.h2(title, class: "govuk-tabs__title") %>
3
3
  <ul class="govuk-tabs__list">
4
4
  <% tabs.each.with_index do |tab, i| %>
@@ -1,12 +1,13 @@
1
1
  class GovukComponent::TabComponent < GovukComponent::Base
2
2
  renders_many :tabs, "Tab"
3
3
 
4
- attr_reader :title
4
+ attr_reader :title, :id
5
5
 
6
- def initialize(title:, classes: [], html_attributes: {})
6
+ def initialize(title:, id: nil, classes: [], html_attributes: {})
7
7
  super(classes: classes, html_attributes: html_attributes)
8
8
 
9
9
  @title = title
10
+ @id = id
10
11
  end
11
12
 
12
13
  private
@@ -16,16 +17,17 @@ private
16
17
  end
17
18
 
18
19
  class Tab < GovukComponent::Base
19
- attr_reader :title
20
+ attr_reader :label, :text
20
21
 
21
- def initialize(title:, classes: [], html_attributes: {})
22
+ def initialize(label:, text: nil, classes: [], html_attributes: {})
22
23
  super(classes: classes, html_attributes: html_attributes)
23
24
 
24
- @title = title
25
+ @label = label
26
+ @text = text
25
27
  end
26
28
 
27
29
  def id(prefix: nil)
28
- [prefix, title.parameterize].join
30
+ [prefix, label.parameterize].join
29
31
  end
30
32
 
31
33
  def hidden_class(i = nil)
@@ -39,7 +41,7 @@ private
39
41
  end
40
42
 
41
43
  def li_link
42
- link_to(title, id(prefix: '#'), class: "govuk-tabs__tab")
44
+ link_to(label, id(prefix: '#'), class: "govuk-tabs__tab")
43
45
  end
44
46
 
45
47
  def default_classes
@@ -47,7 +49,7 @@ private
47
49
  end
48
50
 
49
51
  def call
50
- content
52
+ content || text || fail(ArgumentError, "no text or content")
51
53
  end
52
54
  end
53
55
  end
@@ -1,13 +1,13 @@
1
1
  class GovukComponent::WarningTextComponent < GovukComponent::Base
2
- attr_reader :text, :assistive_text
2
+ attr_reader :text, :icon_fallback_text
3
3
 
4
4
  ICON = '!'.freeze
5
5
 
6
- def initialize(text:, assistive_text: 'Warning', classes: [], html_attributes: {})
6
+ def initialize(text:, icon_fallback_text: 'Warning', classes: [], html_attributes: {})
7
7
  super(classes: classes, html_attributes: html_attributes)
8
8
 
9
9
  @text = text
10
- @assistive_text = assistive_text
10
+ @icon_fallback_text = icon_fallback_text
11
11
  end
12
12
 
13
13
  def call
@@ -29,7 +29,7 @@ private
29
29
  end
30
30
 
31
31
  def assistive
32
- tag.span(assistive_text, class: 'govuk-warning-text__assistive')
32
+ tag.span(icon_fallback_text, class: 'govuk-warning-text__assistive')
33
33
  end
34
34
 
35
35
  def default_classes
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '2.0.0b7'.freeze
3
+ VERSION = '2.0.0'.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.0b7
4
+ version: 2.0.0
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-07-23 00:00:00.000000000 Z
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.31.1
47
+ version: 2.36.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.31.1
54
+ version: 2.36.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -169,8 +169,8 @@ files:
169
169
  - app/components/govuk_component/base.rb
170
170
  - app/components/govuk_component/breadcrumbs_component.html.erb
171
171
  - app/components/govuk_component/breadcrumbs_component.rb
172
- - app/components/govuk_component/cookie_banner_component.html.erb
173
172
  - app/components/govuk_component/cookie_banner_component.rb
173
+ - app/components/govuk_component/cookie_banner_component/message_component.rb
174
174
  - app/components/govuk_component/details_component.rb
175
175
  - app/components/govuk_component/footer_component.html.erb
176
176
  - app/components/govuk_component/footer_component.rb
@@ -185,6 +185,10 @@ files:
185
185
  - app/components/govuk_component/start_button_component.rb
186
186
  - app/components/govuk_component/summary_list_component.html.erb
187
187
  - app/components/govuk_component/summary_list_component.rb
188
+ - app/components/govuk_component/summary_list_component/action_component.rb
189
+ - app/components/govuk_component/summary_list_component/key_component.rb
190
+ - app/components/govuk_component/summary_list_component/row_component.rb
191
+ - app/components/govuk_component/summary_list_component/value_component.rb
188
192
  - app/components/govuk_component/tab_component.html.erb
189
193
  - app/components/govuk_component/tab_component.rb
190
194
  - app/components/govuk_component/tag_component.rb
@@ -205,7 +209,7 @@ homepage: https://github.com/DFE-Digital/govuk-components
205
209
  licenses:
206
210
  - MIT
207
211
  metadata: {}
208
- post_install_message:
212
+ post_install_message:
209
213
  rdoc_options: []
210
214
  require_paths:
211
215
  - lib
@@ -216,12 +220,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
220
  version: '0'
217
221
  required_rubygems_version: !ruby/object:Gem::Requirement
218
222
  requirements:
219
- - - ">"
223
+ - - ">="
220
224
  - !ruby/object:Gem::Version
221
- version: 1.3.1
225
+ version: '0'
222
226
  requirements: []
223
227
  rubygems_version: 3.1.6
224
- signing_key:
228
+ signing_key:
225
229
  specification_version: 4
226
230
  summary: Lightweight set of reusable GOV.UK Design System components
227
231
  test_files: []
@@ -1,17 +0,0 @@
1
- <%= tag.div(class: classes, role: "region", aria: { label: aria_label }, **html_attributes) do %>
2
- <div class="govuk-cookie-banner__message govuk-width-container">
3
- <div class="govuk-grid-row">
4
- <div class="govuk-grid-column-two-thirds">
5
- <% if title.present? %>
6
- <%= tag.h2(title, class: %w(govuk-cookie-banner__heading govuk-heading-m)) %>
7
- <% end %>
8
-
9
- <%= tag.div(body, class: "govuk-cookie-banner__content") %>
10
- </div>
11
- </div>
12
-
13
- <div class="govuk-button-group">
14
- <%= actions %>
15
- </div>
16
- </div>
17
- <% end %>