govuk-components 2.0.0b7 → 2.0.0rc1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 841141c88cfcaed118afa205d0b0cee4652d73367807e19568325bc751d87e7b
4
- data.tar.gz: 6fa945dffee2ad40ca4b94b1c3847e1324442580611f1b9e372b684b0ea4ecd7
3
+ metadata.gz: f5515548e238de9a79246999e6690822115fd16a02a6122205b3c79622e2c8fd
4
+ data.tar.gz: 046d7a25d4c6e80c04dce6064c96f38b655e00d69d9cafaecb598da66f5526a7
5
5
  SHA512:
6
- metadata.gz: d2a5f01d9e108932a99fdf57d8bfd0837151a8ff96254f2115dc8a4a02d50e16b60539749705fc9b3e54ee8a75269901ffc9ff9965a67fcb5f68b05ab5374d6b
7
- data.tar.gz: 767021e9a660ddcf0b6ce3df61f7363341ec0181d4f16fb0584a6c8ac19978eb717997a7c1773dad1ccda68e6a141225c7f67f2fde0ed99e841a6ca2cbac7c71
6
+ metadata.gz: 61b82755a3220d4323abfba65e4f4473dfa98bb5cdd7712066e74b18c17360e6fae854db1bb713705ec5467cdb45b59d4d6d692052d5c9b3cee13df8bcabc242
7
+ data.tar.gz: 93d9ae24e9b26dc2f49899369fc0bc92eae4b0439740fb6406d314c1f57dff435b5d7f4b13f62bc50f0a93c4671dc7c311f57feaef225878fdc9988971df693c
@@ -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,59 @@
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
+ tag.div(class: "govuk-grid-row") do
19
+ tag.div(class: "govuk-grid-column-two-thirds") do
20
+ safe_join([heading_element, message_element, actions_element])
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def default_classes
29
+ %w(govuk-cookie-banner__message govuk-width-container)
30
+ end
31
+
32
+ def heading_element
33
+ tag.h2(heading_content, class: "govuk-cookie-banner__heading")
34
+ end
35
+
36
+ def heading_content
37
+ heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html")
38
+ end
39
+
40
+ def message_element
41
+ tag.div(message_content, class: "govuk-cookie-banner__content")
42
+ end
43
+
44
+ def message_content
45
+ content || wrap_in_p(text) || fail(ArgumentError, "no text or content")
46
+ end
47
+
48
+ def wrap_in_p(message_text)
49
+ return if message_text.blank?
50
+
51
+ tag.p(message_text)
52
+ end
53
+
54
+ def actions_element
55
+ return if actions.none?
56
+
57
+ tag.div(class: "govuk-button-group") { safe_join(actions) }
58
+ end
59
+ 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])
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, :text, :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 || fail(ArgumentError, "no text or content")
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.0rc1'.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.0rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DfE developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-23 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -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
@@ -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 %>