govuk-components 3.3.0 → 4.0.0a2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/components/govuk_component/pagination_component.rb +3 -3
- data/app/components/govuk_component/summary_list_component/card_component.html.erb +16 -0
- data/app/components/govuk_component/summary_list_component/card_component.rb +19 -0
- data/app/components/govuk_component/summary_list_component.rb +20 -6
- data/app/components/govuk_component/table_component/body_component.rb +14 -2
- data/app/components/govuk_component/table_component/cell_component.rb +54 -10
- data/app/components/govuk_component/table_component/col_group_component.rb +45 -0
- data/app/components/govuk_component/table_component/foot_component.rb +44 -0
- data/app/components/govuk_component/table_component/head_component.rb +13 -2
- data/app/components/govuk_component/table_component/row_component.rb +53 -6
- data/app/components/govuk_component/table_component.rb +14 -6
- data/app/helpers/govuk_components_helper.rb +1 -0
- data/app/helpers/govuk_link_helper.rb +24 -9
- data/lib/govuk/components/engine.rb +4 -0
- data/lib/govuk/components/version.rb +1 -1
- metadata +28 -29
- data/app/components/govuk_component/summary_list_component.html.erb +0 -5
- data/app/components/govuk_component/table_component/body_component.html.erb +0 -5
- data/app/components/govuk_component/table_component/head_component.html.erb +0 -5
- data/app/components/govuk_component/table_component/row_component.html.erb +0 -5
- data/app/components/govuk_component/table_component.html.erb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a89715e3ac54c26a25f8711ffcc1bcbae3c7cd697e6dc4993d6581c52fe4885
|
4
|
+
data.tar.gz: 8c781f15f6e02d50b5c463732770340502a7c3e300b63f633c6ca09b084effab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c89afcba1f59b8b7d02142b891904667a9b6aaeb84db7f1d4c6c373d516b7ee302aa23e6431d21e3144f1ea6bbdc7d78703bc6d3dfe88e5c00c2f987ce8368c
|
7
|
+
data.tar.gz: 1dc348dde934a1806118c18c75d20b4cee98b03ba2032a1a86a4a0519461662acab039b8a8f65fd41ef3406faf634da95e72db9a2e33456af191375f87477b19
|
data/README.md
CHANGED
@@ -6,9 +6,9 @@
|
|
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.
|
10
|
-
[![Rails](https://img.shields.io/badge/Rails-6.1.
|
11
|
-
[![Ruby](https://img.shields.io/badge/Ruby-
|
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
|
+
[![Rails](https://img.shields.io/badge/Rails-6.1.7%20%E2%95%B1%207.0.3-E16D6D)](https://weblog.rubyonrails.org/releases/)
|
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
|
|
13
13
|
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.
|
14
14
|
|
@@ -96,7 +96,7 @@ private
|
|
96
96
|
text: @previous_text,
|
97
97
|
}
|
98
98
|
|
99
|
-
|
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
|
-
|
110
|
+
with_next_page(**kwargs.compact)
|
111
111
|
end
|
112
112
|
|
113
113
|
def build_items
|
114
|
-
pagy.series.map { |i|
|
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)
|
@@ -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
|
-
|
42
|
-
r.
|
43
|
-
r.
|
44
|
-
Array.wrap(a).each { |ad| r.
|
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
|
@@ -1,5 +1,13 @@
|
|
1
1
|
class GovukComponent::TableComponent::BodyComponent < GovukComponent::Base
|
2
|
-
renders_many :rows,
|
2
|
+
renders_many :rows, ->(cell_data: nil, first_cell_is_header: false, classes: [], html_attributes: {}, &block) do
|
3
|
+
GovukComponent::TableComponent::RowComponent.from_body(
|
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
|
3
11
|
|
4
12
|
def initialize(rows: nil, first_cell_is_header: false, classes: [], html_attributes: {})
|
5
13
|
super(classes: classes, html_attributes: html_attributes)
|
@@ -7,12 +15,16 @@ class GovukComponent::TableComponent::BodyComponent < GovukComponent::Base
|
|
7
15
|
build_rows_from_row_data(rows, first_cell_is_header)
|
8
16
|
end
|
9
17
|
|
18
|
+
def call
|
19
|
+
tag.tbody(**html_attributes) { safe_join(rows) }
|
20
|
+
end
|
21
|
+
|
10
22
|
private
|
11
23
|
|
12
24
|
def build_rows_from_row_data(data, first_cell_is_header)
|
13
25
|
return if data.blank?
|
14
26
|
|
15
|
-
data.each { |d|
|
27
|
+
data.each { |d| with_row(cell_data: d, first_cell_is_header: first_cell_is_header) }
|
16
28
|
end
|
17
29
|
|
18
30
|
def default_attributes
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class GovukComponent::TableComponent::CellComponent < GovukComponent::Base
|
2
|
-
attr_reader :text, :header, :numeric, :width
|
2
|
+
attr_reader :text, :header, :numeric, :width, :scope, :parent, :colspan, :rowspan
|
3
3
|
|
4
4
|
alias_method :numeric?, :numeric
|
5
|
+
alias_method :header?, :header
|
5
6
|
|
6
7
|
WIDTHS = {
|
7
8
|
"full" => "govuk-!-width-full",
|
@@ -12,11 +13,15 @@ class GovukComponent::TableComponent::CellComponent < GovukComponent::Base
|
|
12
13
|
"one-quarter" => "govuk-!-width-one-quarter",
|
13
14
|
}.freeze
|
14
15
|
|
15
|
-
def initialize(
|
16
|
-
@header = header
|
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
|
+
@scope = scope
|
21
|
+
@parent = parent
|
22
|
+
@colspan = colspan
|
23
|
+
@rowspan = rowspan
|
24
|
+
@header = (header.nil?) ? in_thead? : header
|
20
25
|
|
21
26
|
super(classes: classes, html_attributes: html_attributes)
|
22
27
|
end
|
@@ -36,22 +41,61 @@ private
|
|
36
41
|
end
|
37
42
|
|
38
43
|
def cell_element
|
39
|
-
|
44
|
+
if in_thead? || header?
|
45
|
+
'th'
|
46
|
+
else
|
47
|
+
'td'
|
48
|
+
end
|
40
49
|
end
|
41
50
|
|
42
51
|
def default_attributes
|
43
|
-
{ class: default_classes }
|
52
|
+
{ class: default_classes, scope: determine_scope, colspan: colspan, rowspan: rowspan }.compact
|
53
|
+
end
|
54
|
+
|
55
|
+
def determine_scope
|
56
|
+
conditions = { scope: scope, parent: parent, header: header, auto_table_scopes: config.enable_auto_table_scopes }
|
57
|
+
|
58
|
+
case conditions
|
59
|
+
in { scope: String }
|
60
|
+
scope
|
61
|
+
in { scope: false } | { header: false } | { auto_table_scopes: false }
|
62
|
+
nil
|
63
|
+
in { auto_table_scopes: true, parent: 'thead' }
|
64
|
+
'col'
|
65
|
+
in { auto_table_scopes: true, parent: 'tbody' } | { auto_table_scopes: true, parent: 'tfoot' }
|
66
|
+
'row'
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
44
70
|
end
|
45
71
|
|
46
72
|
def default_classes
|
47
|
-
|
48
|
-
|
73
|
+
class_names(
|
74
|
+
"govuk-table__#{class_suffix}",
|
75
|
+
"govuk-table__#{class_suffix}--numeric" => numeric?,
|
76
|
+
width => width?,
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def class_suffix
|
81
|
+
if in_thead? || (in_tbody? && header?)
|
82
|
+
"header"
|
83
|
+
elsif in_tfoot?
|
84
|
+
"footer"
|
49
85
|
else
|
50
|
-
|
86
|
+
"cell"
|
51
87
|
end
|
52
88
|
end
|
53
89
|
|
54
|
-
def
|
55
|
-
|
90
|
+
def in_thead?
|
91
|
+
parent == "thead"
|
92
|
+
end
|
93
|
+
|
94
|
+
def in_tfoot?
|
95
|
+
parent == "tfoot"
|
96
|
+
end
|
97
|
+
|
98
|
+
def in_tbody?
|
99
|
+
parent == "tbody"
|
56
100
|
end
|
57
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
|
@@ -1,5 +1,12 @@
|
|
1
1
|
class GovukComponent::TableComponent::HeadComponent < GovukComponent::Base
|
2
|
-
renders_many :rows,
|
2
|
+
renders_many :rows, ->(cell_data: nil, classes: [], html_attributes: {}, &block) do
|
3
|
+
GovukComponent::TableComponent::RowComponent.from_head(
|
4
|
+
cell_data: cell_data,
|
5
|
+
classes: classes,
|
6
|
+
html_attributes: html_attributes,
|
7
|
+
&block
|
8
|
+
)
|
9
|
+
end
|
3
10
|
|
4
11
|
attr_reader :row_data
|
5
12
|
|
@@ -9,12 +16,16 @@ class GovukComponent::TableComponent::HeadComponent < GovukComponent::Base
|
|
9
16
|
build_rows_from_row_data(rows)
|
10
17
|
end
|
11
18
|
|
19
|
+
def call
|
20
|
+
tag.thead(**html_attributes) { safe_join(rows) }
|
21
|
+
end
|
22
|
+
|
12
23
|
private
|
13
24
|
|
14
25
|
def build_rows_from_row_data(data)
|
15
26
|
return if data.blank?
|
16
27
|
|
17
|
-
data.each { |d|
|
28
|
+
data.each { |d| with_row(cell_data: d) }
|
18
29
|
end
|
19
30
|
|
20
31
|
def default_attributes
|
@@ -1,30 +1,77 @@
|
|
1
1
|
class GovukComponent::TableComponent::RowComponent < GovukComponent::Base
|
2
|
-
renders_many :cells,
|
2
|
+
renders_many :cells, ->(scope: nil, header: nil, text: nil, numeric: false, width: nil, rowspan: nil, colspan: nil, classes: [], html_attributes: {}, &block) do
|
3
|
+
GovukComponent::TableComponent::CellComponent.new(
|
4
|
+
scope: scope,
|
5
|
+
header: header,
|
6
|
+
text: text,
|
7
|
+
numeric: numeric,
|
8
|
+
width: width,
|
9
|
+
parent: parent,
|
10
|
+
rowspan: rowspan,
|
11
|
+
colspan: colspan,
|
12
|
+
classes: classes,
|
13
|
+
html_attributes: html_attributes,
|
14
|
+
&block
|
15
|
+
)
|
16
|
+
end
|
3
17
|
|
4
|
-
attr_reader :
|
18
|
+
attr_reader :first_cell_is_header, :parent
|
5
19
|
|
6
|
-
def initialize(cell_data: nil, first_cell_is_header: false,
|
7
|
-
@header = header
|
20
|
+
def initialize(cell_data: nil, first_cell_is_header: false, parent: nil, classes: [], html_attributes: {})
|
8
21
|
@first_cell_is_header = first_cell_is_header
|
22
|
+
@parent = parent
|
9
23
|
|
10
24
|
super(classes: classes, html_attributes: html_attributes)
|
11
25
|
|
12
26
|
build_cells_from_cell_data(cell_data)
|
13
27
|
end
|
14
28
|
|
29
|
+
def self.from_head(*args, **kwargs, &block)
|
30
|
+
new(*args, parent: 'thead', **kwargs, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.from_body(*args, **kwargs, &block)
|
34
|
+
new(*args, parent: 'tbody', **kwargs, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.from_foot(*args, **kwargs, &block)
|
38
|
+
new(*args, parent: 'tfoot', **kwargs, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def call
|
42
|
+
tag.tr(**html_attributes) { safe_join(cells) }
|
43
|
+
end
|
44
|
+
|
15
45
|
private
|
16
46
|
|
17
47
|
def build_cells_from_cell_data(cell_data)
|
18
48
|
return if cell_data.blank?
|
19
49
|
|
20
|
-
cell_data.
|
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
|
58
|
+
end
|
59
|
+
|
60
|
+
def cell_attributes(count)
|
61
|
+
cell_is_header?(count).then do |cell_is_header|
|
62
|
+
{ header: cell_is_header }
|
63
|
+
end
|
21
64
|
end
|
22
65
|
|
23
66
|
def cell_is_header?(count)
|
24
|
-
|
67
|
+
in_thead? || (first_cell_is_header && count.zero?)
|
25
68
|
end
|
26
69
|
|
27
70
|
def default_attributes
|
28
71
|
{ class: %w(govuk-table__row) }
|
29
72
|
end
|
73
|
+
|
74
|
+
def in_thead?
|
75
|
+
parent == "thead"
|
76
|
+
end
|
30
77
|
end
|
@@ -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,15 +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)
|
24
|
+
end
|
25
|
+
|
26
|
+
def call
|
27
|
+
tag.table(**html_attributes) { safe_join([caption, colgroups, head, bodies, foot]) }
|
21
28
|
end
|
22
29
|
|
23
30
|
private
|
24
31
|
|
25
|
-
def build(head_data, body_data, caption_text)
|
26
|
-
|
27
|
-
|
28
|
-
|
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)
|
29
37
|
end
|
30
38
|
|
31
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',
|
@@ -1,4 +1,8 @@
|
|
1
|
+
require "html_attributes_utils"
|
2
|
+
|
1
3
|
module GovukLinkHelper
|
4
|
+
using HTMLAttributesUtils
|
5
|
+
|
2
6
|
LINK_STYLES = {
|
3
7
|
inverse: "govuk-link--inverse",
|
4
8
|
muted: "govuk-link--muted",
|
@@ -88,17 +92,16 @@ module GovukLinkHelper
|
|
88
92
|
private
|
89
93
|
|
90
94
|
def build_html_options(provided_options, style: :link)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
95
|
+
element_styles = { link: LINK_STYLES, button: BUTTON_STYLES }.fetch(style, {})
|
96
|
+
|
97
|
+
# we need to take a couple of extra steps here because we don't want the style
|
98
|
+
# params (inverse, muted, etc) to end up as extra attributes on the link.
|
96
99
|
|
97
|
-
remaining_options = provided_options
|
100
|
+
remaining_options = remove_styles_from_provided_options(element_styles, provided_options)
|
98
101
|
|
99
|
-
|
102
|
+
style_classes = build_style_classes(style, extract_styles_from_provided_options(element_styles, provided_options))
|
100
103
|
|
101
|
-
|
104
|
+
combine_attributes(remaining_options, class_name: style_classes)
|
102
105
|
end
|
103
106
|
|
104
107
|
def build_style_classes(style, provided_options)
|
@@ -111,13 +114,25 @@ private
|
|
111
114
|
end
|
112
115
|
end
|
113
116
|
|
114
|
-
def
|
117
|
+
def combine_attributes(attributes, class_name:)
|
115
118
|
attributes ||= {}
|
116
119
|
|
117
120
|
attributes.with_indifferent_access.tap do |attrs|
|
118
121
|
attrs[:class] = Array.wrap(attrs[:class]).prepend(class_name).flatten.join(" ")
|
119
122
|
end
|
120
123
|
end
|
124
|
+
|
125
|
+
def extract_styles_from_provided_options(styles, provided_options)
|
126
|
+
return {} if provided_options.blank?
|
127
|
+
|
128
|
+
provided_options.slice(*styles.keys)
|
129
|
+
end
|
130
|
+
|
131
|
+
def remove_styles_from_provided_options(styles, provided_options)
|
132
|
+
return {} if provided_options.blank?
|
133
|
+
|
134
|
+
provided_options&.except(*styles.keys)
|
135
|
+
end
|
121
136
|
end
|
122
137
|
|
123
138
|
ActiveSupport.on_load(:action_view) { include GovukLinkHelper }
|
@@ -64,6 +64,7 @@ module Govuk
|
|
64
64
|
# +:default_warning_text_icon+ "!"
|
65
65
|
#
|
66
66
|
# +:require_summary_list_action_visually_hidden_text+ when true forces visually hidden text to be set for every action. It can still be explicitly skipped by passing in +nil+. Defaults to +false+
|
67
|
+
# +:enable_auto_table_scopes+ automatically adds a scope of 'col' to th elements in thead and 'row' to th elements in tbody.
|
67
68
|
DEFAULTS = {
|
68
69
|
default_back_link_text: 'Back',
|
69
70
|
default_breadcrumbs_collapse_on_mobile: false,
|
@@ -96,7 +97,10 @@ module Govuk
|
|
96
97
|
default_warning_text_icon_fallback_text: "Warning",
|
97
98
|
default_warning_text_icon: "!",
|
98
99
|
|
100
|
+
default_link_new_tab_text: "(opens in new tab)",
|
101
|
+
|
99
102
|
require_summary_list_action_visually_hidden_text: false,
|
103
|
+
enable_auto_table_scopes: true,
|
100
104
|
}.freeze
|
101
105
|
|
102
106
|
DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
|
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
|
+
version: 4.0.0a2
|
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:
|
11
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html-attributes-utils
|
@@ -16,48 +16,48 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.0
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 1.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.0.0
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 1.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pagy
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: '6.0'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: '6.0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: view_component
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 3.0.0rc1
|
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:
|
60
|
+
version: 3.0.0rc1
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: deep_merge
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,14 +120,14 @@ dependencies:
|
|
120
120
|
requirements:
|
121
121
|
- - '='
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: 4.
|
123
|
+
version: 4.9.0
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - '='
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: 4.
|
130
|
+
version: 4.9.0
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: sassc-rails
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,14 +204,14 @@ dependencies:
|
|
204
204
|
requirements:
|
205
205
|
- - "~>"
|
206
206
|
- !ruby/object:Gem::Version
|
207
|
-
version: 3.
|
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.
|
214
|
+
version: 3.6.0
|
215
215
|
- !ruby/object:Gem::Dependency
|
216
216
|
name: rouge
|
217
217
|
requirement: !ruby/object:Gem::Requirement
|
@@ -288,28 +288,28 @@ dependencies:
|
|
288
288
|
requirements:
|
289
289
|
- - "~>"
|
290
290
|
- !ruby/object:Gem::Version
|
291
|
-
version: 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.
|
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.
|
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.
|
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,23 +349,22 @@ 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
|
358
359
|
- app/components/govuk_component/tab_component.html.erb
|
359
360
|
- app/components/govuk_component/tab_component.rb
|
360
|
-
- app/components/govuk_component/table_component.html.erb
|
361
361
|
- app/components/govuk_component/table_component.rb
|
362
|
-
- app/components/govuk_component/table_component/body_component.html.erb
|
363
362
|
- app/components/govuk_component/table_component/body_component.rb
|
364
363
|
- app/components/govuk_component/table_component/caption_component.rb
|
365
364
|
- app/components/govuk_component/table_component/cell_component.rb
|
366
|
-
- app/components/govuk_component/table_component/
|
365
|
+
- app/components/govuk_component/table_component/col_group_component.rb
|
366
|
+
- app/components/govuk_component/table_component/foot_component.rb
|
367
367
|
- app/components/govuk_component/table_component/head_component.rb
|
368
|
-
- app/components/govuk_component/table_component/row_component.html.erb
|
369
368
|
- app/components/govuk_component/table_component/row_component.rb
|
370
369
|
- app/components/govuk_component/tag_component.rb
|
371
370
|
- app/components/govuk_component/traits.rb
|
@@ -385,7 +384,7 @@ homepage: https://github.com/DFE-Digital/govuk-components
|
|
385
384
|
licenses:
|
386
385
|
- MIT
|
387
386
|
metadata: {}
|
388
|
-
post_install_message:
|
387
|
+
post_install_message:
|
389
388
|
rdoc_options: []
|
390
389
|
require_paths:
|
391
390
|
- lib
|
@@ -396,12 +395,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
396
395
|
version: '0'
|
397
396
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
398
397
|
requirements:
|
399
|
-
- - "
|
398
|
+
- - ">"
|
400
399
|
- !ruby/object:Gem::Version
|
401
|
-
version:
|
400
|
+
version: 1.3.1
|
402
401
|
requirements: []
|
403
|
-
rubygems_version: 3.
|
404
|
-
signing_key:
|
402
|
+
rubygems_version: 3.2.33
|
403
|
+
signing_key:
|
405
404
|
specification_version: 4
|
406
405
|
summary: Lightweight set of reusable GOV.UK Design System components
|
407
406
|
test_files: []
|