govuk-components 4.0.0a1 → 4.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/components/govuk_component/accordion_component/section_component.rb +7 -4
  4. data/app/components/govuk_component/accordion_component.rb +4 -2
  5. data/app/components/govuk_component/header_component.rb +2 -2
  6. data/app/components/govuk_component/notification_banner_component.rb +1 -1
  7. data/app/components/govuk_component/pagination_component.rb +3 -3
  8. data/app/components/govuk_component/summary_list_component/action_component.rb +2 -2
  9. data/app/components/govuk_component/summary_list_component/card_component.html.erb +16 -0
  10. data/app/components/govuk_component/summary_list_component/card_component.rb +19 -0
  11. data/app/components/govuk_component/summary_list_component.rb +20 -6
  12. data/app/components/govuk_component/table_component/body_component.rb +1 -1
  13. data/app/components/govuk_component/table_component/cell_component.rb +32 -14
  14. data/app/components/govuk_component/table_component/col_group_component.rb +45 -0
  15. data/app/components/govuk_component/table_component/foot_component.rb +44 -0
  16. data/app/components/govuk_component/table_component/head_component.rb +1 -1
  17. data/app/components/govuk_component/table_component/row_component.rb +15 -2
  18. data/app/components/govuk_component/table_component.rb +11 -7
  19. data/app/helpers/govuk_components_helper.rb +1 -0
  20. data/app/helpers/govuk_link_helper.rb +8 -28
  21. data/lib/govuk/components/version.rb +1 -1
  22. metadata +18 -15
  23. data/app/components/govuk_component/summary_list_component.html.erb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5498c871090fc7b01a2bf8b6caf80a29a00d713917173e6c7350d47e99b3f56
4
- data.tar.gz: 86369759dd515ef9fd7a9826be8c95ce3dacbcd987c59cdcc253cdb1e32648b5
3
+ metadata.gz: bd7e8066fccea2b88cdf610a3311daf69e72552d2025e740417a8716851866bc
4
+ data.tar.gz: 506bd4f0a292bae9d908038af9597c83adca6e3b2a8cc912adb79566977d238c
5
5
  SHA512:
6
- metadata.gz: ec79d90aeab7f907b61a3105ac2a05595846d05d5af481489160aa3da47020459044c77dec97e9734a742faf1cbc86eedc46ec486899ed8f60b8fdbf85b491dc
7
- data.tar.gz: f8b7225906230461f099835e91799117f6f6528a93e1311b01109b4210a0003e532201877377166d3cadf4ba841306e886ca41164aaeb7497b53340da530ff62
6
+ metadata.gz: f77444b5107f2a0d3ccb9166bb28297b6a8d643a0e4d4ac9310dd33699df7de1e51ab9ccd4ce4fc457267f43b497d5b17b2f5904b79007dac418f987900364ea
7
+ data.tar.gz: fc20ae15eba5a9d0faf7e953a9d28958928ecbed0b9a82c4d23643cac88ca60846e7f5cffa1fe11d38ad38c90ebb9582ef6abf0d3be9c1fa85b3f101e4281d2d
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Gem](https://img.shields.io/gem/dt/govuk-components?logo=rubygems)](https://rubygems.org/gems/govuk-components)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cbcbc140f300b920d833/test_coverage)](https://codeclimate.com/github/DFE-Digital/govuk-components/test_coverage)
8
8
  [![GitHub license](https://img.shields.io/github/license/DFE-Digital/govuk-components)](https://github.com/DFE-Digital/govuk-components/blob/main/LICENSE)
9
- [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.4.1-brightgreen)](https://design-system.service.gov.uk)
9
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.5.0-brightgreen)](https://design-system.service.gov.uk)
10
10
  [![Rails](https://img.shields.io/badge/Rails-6.1.7%20%E2%95%B1%207.0.3-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
11
  [![Ruby](https://img.shields.io/badge/Ruby-3.0.5%20%20%E2%95%B1%203.1.3%20%20%E2%95%B1%203.2.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
12
 
@@ -1,26 +1,29 @@
1
1
  class GovukComponent::AccordionComponent::SectionComponent < GovukComponent::Base
2
- attr_reader :heading_text, :summary_text, :expanded, :heading_level
2
+ attr_reader :heading_text, :summary_text, :expanded, :heading_level, :accordion_id
3
3
 
4
4
  renders_one :heading_html
5
5
  renders_one :summary_html
6
6
 
7
7
  alias_method :expanded?, :expanded
8
8
 
9
- def initialize(heading_text:, summary_text:, expanded:, heading_level:, classes: [], html_attributes: {})
9
+ def initialize(heading_text:, summary_text:, expanded:, heading_level:, accordion_id: nil, classes: [], html_attributes: {})
10
10
  @heading_text = heading_text
11
11
  @summary_text = summary_text
12
12
  @expanded = expanded
13
13
  @heading_level = heading_level
14
+ @accordion_id = accordion_id
14
15
 
15
16
  super(classes: classes, html_attributes: html_attributes)
16
17
  end
17
18
 
18
19
  def id(suffix: nil)
20
+ prefix = @accordion_id
21
+
19
22
  # generate a random number if we don't have heading_text to avoid attempting
20
23
  # to parameterize a potentially-huge chunk of HTML
21
- @prefix ||= heading_text&.parameterize || SecureRandom.hex(4)
24
+ @unique_identifier ||= heading_text&.parameterize || SecureRandom.hex(4)
22
25
 
23
- [@prefix, suffix].compact.join('-')
26
+ [prefix, @unique_identifier, suffix].compact.join('-')
24
27
  end
25
28
 
26
29
  def heading_content
@@ -7,14 +7,16 @@ class GovukComponent::AccordionComponent < GovukComponent::Base
7
7
  html_attributes: html_attributes,
8
8
  summary_text: summary_text,
9
9
  heading_text: heading_text,
10
+ accordion_id: accordion_id,
10
11
  &block
11
12
  )
12
13
  end
13
14
 
14
- attr_reader :id, :heading_level
15
+ attr_reader :accordion_id, :heading_level
15
16
 
16
17
  def initialize(heading_level: 2, classes: [], html_attributes: {})
17
18
  @heading_level = heading_tag(heading_level)
19
+ @accordion_id = html_attributes[:id]
18
20
 
19
21
  super(classes: classes, html_attributes: html_attributes)
20
22
  end
@@ -22,7 +24,7 @@ class GovukComponent::AccordionComponent < GovukComponent::Base
22
24
  private
23
25
 
24
26
  def default_attributes
25
- { class: %w(govuk-accordion), data: { module: 'govuk-accordion' } }
27
+ { class: %w(govuk-accordion), data: { module: 'govuk-accordion' } }.compact
26
28
  end
27
29
 
28
30
  def heading_tag(level)
@@ -125,11 +125,11 @@ private
125
125
  end
126
126
 
127
127
  def render?
128
- name.present? || content.present?
128
+ name.present? || content?
129
129
  end
130
130
 
131
131
  def call
132
- if content.present?
132
+ if content?
133
133
  tag.div(content, **html_attributes)
134
134
  else
135
135
  tag.span(name, **html_attributes)
@@ -27,7 +27,7 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
27
27
  end
28
28
 
29
29
  def render?
30
- headings.any? || text.present? || content.present?
30
+ headings.any? || text.present? || content?
31
31
  end
32
32
 
33
33
  class Heading < GovukComponent::Base
@@ -96,7 +96,7 @@ private
96
96
  text: @previous_text,
97
97
  }
98
98
 
99
- previous_page(**kwargs.compact)
99
+ with_previous_page(**kwargs.compact)
100
100
  end
101
101
 
102
102
  def build_next
@@ -107,11 +107,11 @@ private
107
107
  text: @next_text,
108
108
  }
109
109
 
110
- next_page(**kwargs.compact)
110
+ with_next_page(**kwargs.compact)
111
111
  end
112
112
 
113
113
  def build_items
114
- pagy.series.map { |i| item(number: i, href: pagy_url_for(pagy, i), from_pagy: true) }
114
+ pagy.series.map { |i| with_item(number: i, href: pagy_url_for(pagy, i), from_pagy: true) }
115
115
  end
116
116
 
117
117
  def default_adjacent_text(side)
@@ -20,7 +20,7 @@ class GovukComponent::SummaryListComponent::ActionComponent < GovukComponent::Ba
20
20
 
21
21
  def call
22
22
  link_to(href, **html_attributes) do
23
- safe_join([action_text, visually_hidden_span].compact, " ")
23
+ safe_join([action_text, visually_hidden_span].compact)
24
24
  end
25
25
  end
26
26
 
@@ -37,6 +37,6 @@ private
37
37
  end
38
38
 
39
39
  def visually_hidden_span
40
- tag.span(visually_hidden_text, class: "govuk-visually-hidden") if visually_hidden_text.present?
40
+ tag.span(%( #{visually_hidden_text}), class: "govuk-visually-hidden") if visually_hidden_text.present?
41
41
  end
42
42
  end
@@ -0,0 +1,16 @@
1
+ <%= tag.div(**html_attributes) do %>
2
+ <div class="govuk-summary-card__title-wrapper">
3
+ <%= tag.h2(title, class: "govuk-summary-card__title") %>
4
+
5
+ <% if actions.any? %>
6
+ <ul class="govuk-summary-card__actions">
7
+ <% actions.each do |action| %>
8
+ <%= tag.li(action, class: "govuk-summary-card__action") %>
9
+ <% end %>
10
+ </ul>
11
+ <% end %>
12
+ </div>
13
+ <div class="govuk-summary-card__content">
14
+ <%= summary_list || content %>
15
+ </div>
16
+ <% end %>
@@ -0,0 +1,19 @@
1
+ class GovukComponent::SummaryListComponent::CardComponent < GovukComponent::Base
2
+ attr_reader :title
3
+
4
+ renders_many :actions
5
+ renders_one :summary_list, "GovukComponent::SummaryListComponent"
6
+
7
+ def initialize(title:, actions: [], classes: [], html_attributes: {})
8
+ @title = title
9
+ actions.each { |a| with_action { a } } if actions.any?
10
+
11
+ super(classes: classes, html_attributes: html_attributes)
12
+ end
13
+
14
+ private
15
+
16
+ def default_attributes
17
+ { class: %w(govuk-summary-card) }
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  module GovukComponent
2
2
  class SummaryListComponent < GovukComponent::Base
3
- attr_reader :borders, :actions
3
+ attr_reader :borders, :actions, :card
4
4
 
5
5
  renders_many :rows, ->(classes: [], html_attributes: {}, &block) do
6
6
  GovukComponent::SummaryListComponent::RowComponent.new(
@@ -11,9 +11,10 @@ module GovukComponent
11
11
  )
12
12
  end
13
13
 
14
- def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, classes: [], html_attributes: {})
14
+ def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, card: nil, classes: [], html_attributes: {})
15
15
  @borders = borders
16
16
  @show_actions_column = actions
17
+ @card = card
17
18
 
18
19
  super(classes: classes, html_attributes: html_attributes)
19
20
 
@@ -22,8 +23,21 @@ module GovukComponent
22
23
  build(rows)
23
24
  end
24
25
 
26
+ def call
27
+ summary_list = tag.dl(**html_attributes) { safe_join(rows) }
28
+
29
+ (card.nil?) ? summary_list : card_with(summary_list)
30
+ end
31
+
25
32
  private
26
33
 
34
+ # we're not using `renders_one` here because we always want the card to render
35
+ # outside of the summary list. when manually building use
36
+ # govuk_summary_list_card { govuk_summary_list }
37
+ def card_with(summary_list)
38
+ render(GovukComponent::SummaryListComponent::CardComponent.new(**card)) { summary_list }
39
+ end
40
+
27
41
  def borders_class
28
42
  %(govuk-summary-list--no-border) unless borders
29
43
  end
@@ -38,10 +52,10 @@ module GovukComponent
38
52
  rows.each do |data|
39
53
  k, v, a = data.values_at(:key, :value, :actions)
40
54
 
41
- row(**data.slice(:classes, :html_attributes)) do |r|
42
- r.key(**k)
43
- r.value(**v)
44
- Array.wrap(a).each { |ad| r.action(**ad) }
55
+ with_row(**data.slice(:classes, :html_attributes)) do |r|
56
+ r.with_key(**k)
57
+ r.with_value(**v)
58
+ Array.wrap(a).each { |ad| r.with_action(**ad) }
45
59
  end
46
60
  end
47
61
  end
@@ -24,7 +24,7 @@ private
24
24
  def build_rows_from_row_data(data, first_cell_is_header)
25
25
  return if data.blank?
26
26
 
27
- data.each { |d| row(cell_data: d, first_cell_is_header: first_cell_is_header) }
27
+ data.each { |d| with_row(cell_data: d, first_cell_is_header: first_cell_is_header) }
28
28
  end
29
29
 
30
30
  def default_attributes
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::TableComponent::CellComponent < GovukComponent::Base
2
- attr_reader :text, :header, :numeric, :width, :scope, :parent
2
+ attr_reader :text, :header, :numeric, :width, :scope, :parent, :colspan, :rowspan
3
3
 
4
4
  alias_method :numeric?, :numeric
5
5
  alias_method :header?, :header
@@ -13,12 +13,14 @@ class GovukComponent::TableComponent::CellComponent < GovukComponent::Base
13
13
  "one-quarter" => "govuk-!-width-one-quarter",
14
14
  }.freeze
15
15
 
16
- def initialize(scope: nil, header: nil, numeric: false, text: nil, width: nil, parent: nil, classes: [], html_attributes: {})
16
+ def initialize(scope: nil, header: nil, numeric: false, text: nil, width: nil, parent: nil, rowspan: nil, colspan: nil, classes: [], html_attributes: {})
17
17
  @text = text
18
18
  @numeric = numeric
19
19
  @width = width
20
20
  @scope = scope
21
21
  @parent = parent
22
+ @colspan = colspan
23
+ @rowspan = rowspan
22
24
  @header = (header.nil?) ? in_thead? : header
23
25
 
24
26
  super(classes: classes, html_attributes: html_attributes)
@@ -39,11 +41,15 @@ private
39
41
  end
40
42
 
41
43
  def cell_element
42
- header ? 'th' : 'td'
44
+ if in_thead? || header?
45
+ 'th'
46
+ else
47
+ 'td'
48
+ end
43
49
  end
44
50
 
45
51
  def default_attributes
46
- { class: default_classes, scope: determine_scope }
52
+ { class: default_classes, scope: determine_scope, colspan: colspan, rowspan: rowspan }.compact
47
53
  end
48
54
 
49
55
  def determine_scope
@@ -56,28 +62,40 @@ private
56
62
  nil
57
63
  in { auto_table_scopes: true, parent: 'thead' }
58
64
  'col'
59
- in { auto_table_scopes: true, parent: 'tbody' }
65
+ in { auto_table_scopes: true, parent: 'tbody' } | { auto_table_scopes: true, parent: 'tfoot' }
60
66
  'row'
61
67
  else
62
- Rails.logger.warn("No scope pattern matched")
63
-
64
68
  nil
65
69
  end
66
70
  end
67
71
 
68
72
  def default_classes
69
- if header
70
- class_names("govuk-table__header", "govuk-table__header--numeric" => numeric?, width_class => width?)
71
- else
72
- class_names("govuk-table__cell", "govuk-table__cell--numeric" => numeric?, width_class => width?)
73
- end
73
+ class_names(
74
+ "govuk-table__#{class_suffix}",
75
+ "govuk-table__#{class_suffix}--numeric" => numeric?,
76
+ width => width?,
77
+ )
74
78
  end
75
79
 
76
- def width_class
77
- WIDTHS.fetch(width, nil)
80
+ def class_suffix
81
+ if in_thead? || (in_tbody? && header?)
82
+ "header"
83
+ elsif in_tfoot?
84
+ "footer"
85
+ else
86
+ "cell"
87
+ end
78
88
  end
79
89
 
80
90
  def in_thead?
81
91
  parent == "thead"
82
92
  end
93
+
94
+ def in_tfoot?
95
+ parent == "tfoot"
96
+ end
97
+
98
+ def in_tbody?
99
+ parent == "tbody"
100
+ end
83
101
  end
@@ -0,0 +1,45 @@
1
+ class GovukComponent::TableComponent::ColGroupComponent < GovukComponent::Base
2
+ renders_many :cols, "ColComponent"
3
+
4
+ def initialize(classes: [], cols: [], html_attributes: {})
5
+ super(classes: classes, html_attributes: html_attributes)
6
+
7
+ return if cols.blank?
8
+
9
+ cols.each { |c| with_col(span: c) }
10
+ end
11
+
12
+ def call
13
+ tag.colgroup(**html_attributes) { safe_join(cols) }
14
+ end
15
+
16
+ def render?
17
+ cols.any?
18
+ end
19
+
20
+ private
21
+
22
+ def default_attributes
23
+ {}
24
+ end
25
+
26
+ class ColComponent < GovukComponent::Base
27
+ attr_reader :span
28
+
29
+ def initialize(span: 1, classes: [], html_attributes: {})
30
+ @span = span.to_s
31
+
32
+ super(classes: classes, html_attributes: html_attributes)
33
+ end
34
+
35
+ def call
36
+ tag.col(span: span, **html_attributes)
37
+ end
38
+
39
+ private
40
+
41
+ def default_attributes
42
+ {}
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ class GovukComponent::TableComponent::FootComponent < GovukComponent::Base
2
+ renders_many :rows, ->(cell_data: nil, first_cell_is_header: false, classes: [], html_attributes: {}, &block) do
3
+ GovukComponent::TableComponent::RowComponent.from_foot(
4
+ cell_data: cell_data,
5
+ first_cell_is_header: first_cell_is_header,
6
+ classes: classes,
7
+ html_attributes: html_attributes,
8
+ &block
9
+ )
10
+ end
11
+
12
+ attr_reader :first_cell_is_header, :row_data
13
+
14
+ def initialize(rows: nil, first_cell_is_header: false, classes: [], html_attributes: {})
15
+ @rows = rows
16
+ @first_cell_is_header = first_cell_is_header
17
+
18
+ super(classes: classes, html_attributes: html_attributes)
19
+
20
+ return unless rows.presence
21
+
22
+ build_rows_from_row_data(rows)
23
+ end
24
+
25
+ def call
26
+ tag.tfoot(**html_attributes) { safe_join(rows) }
27
+ end
28
+
29
+ def render?
30
+ rows.any?
31
+ end
32
+
33
+ private
34
+
35
+ def build_rows_from_row_data(data)
36
+ return if data.blank?
37
+
38
+ with_row(cell_data: data, first_cell_is_header: first_cell_is_header)
39
+ end
40
+
41
+ def default_attributes
42
+ { class: %w(govuk-table__foot) }
43
+ end
44
+ end
@@ -25,7 +25,7 @@ private
25
25
  def build_rows_from_row_data(data)
26
26
  return if data.blank?
27
27
 
28
- data.each { |d| row(cell_data: d) }
28
+ data.each { |d| with_row(cell_data: d) }
29
29
  end
30
30
 
31
31
  def default_attributes
@@ -1,5 +1,5 @@
1
1
  class GovukComponent::TableComponent::RowComponent < GovukComponent::Base
2
- renders_many :cells, ->(scope: nil, header: nil, text: nil, numeric: false, width: nil, classes: [], html_attributes: {}, &block) do
2
+ renders_many :cells, ->(scope: nil, header: nil, text: nil, numeric: false, width: nil, rowspan: nil, colspan: nil, classes: [], html_attributes: {}, &block) do
3
3
  GovukComponent::TableComponent::CellComponent.new(
4
4
  scope: scope,
5
5
  header: header,
@@ -7,6 +7,8 @@ class GovukComponent::TableComponent::RowComponent < GovukComponent::Base
7
7
  numeric: numeric,
8
8
  width: width,
9
9
  parent: parent,
10
+ rowspan: rowspan,
11
+ colspan: colspan,
10
12
  classes: classes,
11
13
  html_attributes: html_attributes,
12
14
  &block
@@ -32,6 +34,10 @@ class GovukComponent::TableComponent::RowComponent < GovukComponent::Base
32
34
  new(*args, parent: 'tbody', **kwargs, &block)
33
35
  end
34
36
 
37
+ def self.from_foot(*args, **kwargs, &block)
38
+ new(*args, parent: 'tfoot', **kwargs, &block)
39
+ end
40
+
35
41
  def call
36
42
  tag.tr(**html_attributes) { safe_join(cells) }
37
43
  end
@@ -41,7 +47,14 @@ private
41
47
  def build_cells_from_cell_data(cell_data)
42
48
  return if cell_data.blank?
43
49
 
44
- cell_data.each.with_index { |data, i| cell(text: data, **cell_attributes(i)) }
50
+ cell_data.each_with_index do |data, i|
51
+ case data
52
+ when Hash
53
+ with_cell(**data, **cell_attributes(i))
54
+ when String
55
+ with_cell(text: data, **cell_attributes(i))
56
+ end
57
+ end
45
58
  end
46
59
 
47
60
  def cell_attributes(count)
@@ -1,12 +1,15 @@
1
1
  module GovukComponent
2
2
  class TableComponent < GovukComponent::Base
3
3
  renders_one :caption, "GovukComponent::TableComponent::CaptionComponent"
4
+ renders_many :cols, "GovukComponent::TableComponent::ColGroupComponent::ColComponent"
5
+ renders_many :colgroups, "GovukComponent::TableComponent::ColGroupComponent"
4
6
  renders_one :head, "GovukComponent::TableComponent::HeadComponent"
5
7
  renders_many :bodies, "GovukComponent::TableComponent::BodyComponent"
8
+ renders_one :foot, "GovukComponent::TableComponent::FootComponent"
6
9
 
7
10
  attr_accessor :id, :first_cell_is_header, :caption_text
8
11
 
9
- def initialize(id: nil, rows: nil, head: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {})
12
+ def initialize(id: nil, rows: nil, head: nil, foot: nil, caption: nil, first_cell_is_header: false, classes: [], html_attributes: {})
10
13
  @id = id
11
14
  @first_cell_is_header = first_cell_is_header
12
15
  @caption_text = caption
@@ -17,19 +20,20 @@ module GovukComponent
17
20
  return unless rows.presence
18
21
 
19
22
  # if no head is passed in,use the first row for headers
20
- build(*(head ? [head, rows] : [rows[0], rows[1..]]), caption_text)
23
+ build(*(head ? [head, rows] : [rows[0], rows[1..]]), foot, caption_text)
21
24
  end
22
25
 
23
26
  def call
24
- tag.table(**html_attributes) { safe_join([caption, head, bodies]) }
27
+ tag.table(**html_attributes) { safe_join([caption, colgroups, head, bodies, foot]) }
25
28
  end
26
29
 
27
30
  private
28
31
 
29
- def build(head_data, body_data, caption_text)
30
- caption(text: caption_text)
31
- head(rows: [head_data])
32
- body(rows: body_data, first_cell_is_header: first_cell_is_header)
32
+ def build(head_data, body_data, foot_data, caption_text)
33
+ with_caption(text: caption_text)
34
+ with_head(rows: [head_data])
35
+ with_body(rows: body_data, first_cell_is_header: first_cell_is_header)
36
+ with_foot(rows: foot_data, first_cell_is_header: first_cell_is_header)
33
37
  end
34
38
 
35
39
  def default_attributes
@@ -15,6 +15,7 @@ module GovukComponentsHelper
15
15
  govuk_section_break: 'GovukComponent::SectionBreakComponent',
16
16
  govuk_start_button: 'GovukComponent::StartButtonComponent',
17
17
  govuk_summary_list: 'GovukComponent::SummaryListComponent',
18
+ govuk_summary_card: 'GovukComponent::SummaryListComponent::CardComponent',
18
19
  govuk_table: 'GovukComponent::TableComponent',
19
20
  govuk_tabs: 'GovukComponent::TabComponent',
20
21
  govuk_tag: 'GovukComponent::TagComponent',
@@ -17,11 +17,6 @@ module GovukLinkHelper
17
17
  warning: "govuk-button--warning",
18
18
  }.freeze
19
19
 
20
- NEW_TAB_ATTRIBUTES = {
21
- target: "_blank",
22
- rel: "noreferrer noopener"
23
- }.freeze
24
-
25
20
  def govuk_link_classes(*styles, default_class: 'govuk-link')
26
21
  if (invalid_styles = (styles - LINK_STYLES.keys)) && invalid_styles.any?
27
22
  fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{LINK_STYLES.keys.to_sentence}")
@@ -38,14 +33,14 @@ module GovukLinkHelper
38
33
  [default_class] + BUTTON_STYLES.values_at(*styles).compact
39
34
  end
40
35
 
41
- def govuk_link_to(name = nil, options = nil, extra_options = {}, new_tab: false, &block)
36
+ def govuk_link_to(name = nil, options = nil, extra_options = {}, &block)
42
37
  extra_options = options if block_given?
43
- html_options = build_html_options(extra_options, new_tab: new_tab)
38
+ html_options = build_html_options(extra_options)
44
39
 
45
40
  if block_given?
46
41
  link_to(name, html_options, &block)
47
42
  else
48
- link_to(prepare_link_text(name, new_tab), options, html_options)
43
+ link_to(name, options, html_options)
49
44
  end
50
45
  end
51
46
 
@@ -71,15 +66,15 @@ module GovukLinkHelper
71
66
  end
72
67
  end
73
68
 
74
- def govuk_button_link_to(name = nil, options = nil, extra_options = {}, new_tab: false, &block)
69
+ def govuk_button_link_to(name = nil, options = nil, extra_options = {}, &block)
75
70
  extra_options = options if block_given?
76
71
  html_options = GovukComponent::StartButtonComponent::LINK_ATTRIBUTES
77
- .merge build_html_options(extra_options, style: :button, new_tab: new_tab)
72
+ .merge build_html_options(extra_options, style: :button)
78
73
 
79
74
  if block_given?
80
75
  link_to(name, html_options, &block)
81
76
  else
82
- link_to(prepare_link_text(name, new_tab), options, html_options)
77
+ link_to(name, options, html_options)
83
78
  end
84
79
  end
85
80
 
@@ -96,24 +91,19 @@ module GovukLinkHelper
96
91
 
97
92
  private
98
93
 
99
- def build_html_options(provided_options, style: :link, new_tab: false)
94
+ def build_html_options(provided_options, style: :link)
100
95
  element_styles = { link: LINK_STYLES, button: BUTTON_STYLES }.fetch(style, {})
101
96
 
102
97
  # we need to take a couple of extra steps here because we don't want the style
103
98
  # params (inverse, muted, etc) to end up as extra attributes on the link.
104
99
 
105
- remaining_options = new_tab_options(new_tab)
106
- .deep_merge_html_attributes(remove_styles_from_provided_options(element_styles, provided_options))
100
+ remaining_options = remove_styles_from_provided_options(element_styles, provided_options)
107
101
 
108
102
  style_classes = build_style_classes(style, extract_styles_from_provided_options(element_styles, provided_options))
109
103
 
110
104
  combine_attributes(remaining_options, class_name: style_classes)
111
105
  end
112
106
 
113
- def new_tab_options(new_tab)
114
- new_tab ? NEW_TAB_ATTRIBUTES : {}
115
- end
116
-
117
107
  def build_style_classes(style, provided_options)
118
108
  keys = *provided_options&.keys
119
109
 
@@ -143,16 +133,6 @@ private
143
133
 
144
134
  provided_options&.except(*styles.keys)
145
135
  end
146
-
147
- def prepare_link_text(text, new_tab)
148
- return text unless new_tab
149
-
150
- new_tab_text = new_tab.is_a?(String) ? new_tab : Govuk::Components.config.default_link_new_tab_text
151
-
152
- return text if new_tab_text.blank?
153
-
154
- %(#{text} #{new_tab_text})
155
- end
156
136
  end
157
137
 
158
138
  ActiveSupport.on_load(:action_view) { include GovukLinkHelper }
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '4.0.0a1'.freeze
3
+ VERSION = '4.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: 4.0.0a1
4
+ version: 4.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: 2023-01-23 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-attributes-utils
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '2'
53
+ version: 3.0.0rc6
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '2'
60
+ version: 3.0.0rc6
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: deep_merge
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -204,28 +204,28 @@ dependencies:
204
204
  requirements:
205
205
  - - "~>"
206
206
  - !ruby/object:Gem::Version
207
- version: 3.5.1
207
+ version: 3.6.0
208
208
  type: :development
209
209
  prerelease: false
210
210
  version_requirements: !ruby/object:Gem::Requirement
211
211
  requirements:
212
212
  - - "~>"
213
213
  - !ruby/object:Gem::Version
214
- version: 3.5.1
214
+ version: 3.6.0
215
215
  - !ruby/object:Gem::Dependency
216
216
  name: rouge
217
217
  requirement: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - "~>"
220
220
  - !ruby/object:Gem::Version
221
- version: 4.0.0
221
+ version: 4.1.0
222
222
  type: :development
223
223
  prerelease: false
224
224
  version_requirements: !ruby/object:Gem::Requirement
225
225
  requirements:
226
226
  - - "~>"
227
227
  - !ruby/object:Gem::Version
228
- version: 4.0.0
228
+ version: 4.1.0
229
229
  - !ruby/object:Gem::Dependency
230
230
  name: rubypants
231
231
  requirement: !ruby/object:Gem::Requirement
@@ -274,42 +274,42 @@ dependencies:
274
274
  requirements:
275
275
  - - "~>"
276
276
  - !ruby/object:Gem::Version
277
- version: 4.1.0
277
+ version: 5.1.0
278
278
  type: :development
279
279
  prerelease: false
280
280
  version_requirements: !ruby/object:Gem::Requirement
281
281
  requirements:
282
282
  - - "~>"
283
283
  - !ruby/object:Gem::Version
284
- version: 4.1.0
284
+ version: 5.1.0
285
285
  - !ruby/object:Gem::Dependency
286
286
  name: slim_lint
287
287
  requirement: !ruby/object:Gem::Requirement
288
288
  requirements:
289
289
  - - "~>"
290
290
  - !ruby/object:Gem::Version
291
- version: 0.22.0
291
+ version: 0.24.0
292
292
  type: :development
293
293
  prerelease: false
294
294
  version_requirements: !ruby/object:Gem::Requirement
295
295
  requirements:
296
296
  - - "~>"
297
297
  - !ruby/object:Gem::Version
298
- version: 0.22.0
298
+ version: 0.24.0
299
299
  - !ruby/object:Gem::Dependency
300
300
  name: webrick
301
301
  requirement: !ruby/object:Gem::Requirement
302
302
  requirements:
303
303
  - - "~>"
304
304
  - !ruby/object:Gem::Version
305
- version: 1.7.0
305
+ version: 1.8.1
306
306
  type: :development
307
307
  prerelease: false
308
308
  version_requirements: !ruby/object:Gem::Requirement
309
309
  requirements:
310
310
  - - "~>"
311
311
  - !ruby/object:Gem::Version
312
- version: 1.7.0
312
+ version: 1.8.1
313
313
  description: A collection of components intended to ease the building of GOV.UK Design
314
314
  System web applications
315
315
  email:
@@ -349,9 +349,10 @@ files:
349
349
  - app/components/govuk_component/phase_banner_component.rb
350
350
  - app/components/govuk_component/section_break_component.rb
351
351
  - app/components/govuk_component/start_button_component.rb
352
- - app/components/govuk_component/summary_list_component.html.erb
353
352
  - app/components/govuk_component/summary_list_component.rb
354
353
  - app/components/govuk_component/summary_list_component/action_component.rb
354
+ - app/components/govuk_component/summary_list_component/card_component.html.erb
355
+ - app/components/govuk_component/summary_list_component/card_component.rb
355
356
  - app/components/govuk_component/summary_list_component/key_component.rb
356
357
  - app/components/govuk_component/summary_list_component/row_component.rb
357
358
  - app/components/govuk_component/summary_list_component/value_component.rb
@@ -361,6 +362,8 @@ files:
361
362
  - app/components/govuk_component/table_component/body_component.rb
362
363
  - app/components/govuk_component/table_component/caption_component.rb
363
364
  - app/components/govuk_component/table_component/cell_component.rb
365
+ - app/components/govuk_component/table_component/col_group_component.rb
366
+ - app/components/govuk_component/table_component/foot_component.rb
364
367
  - app/components/govuk_component/table_component/head_component.rb
365
368
  - app/components/govuk_component/table_component/row_component.rb
366
369
  - app/components/govuk_component/tag_component.rb
@@ -1,5 +0,0 @@
1
- <%= tag.dl(**html_attributes) do %>
2
- <% rows.each do |row| %>
3
- <%= row %>
4
- <% end %>
5
- <% end %>