govuk-components 2.0.0b5 → 2.0.0rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/govuk_component/accordion_component.html.erb +1 -11
- data/app/components/govuk_component/accordion_component.rb +18 -31
- data/app/components/govuk_component/accordion_component/section_component.html.erb +11 -0
- data/app/components/govuk_component/accordion_component/section_component.rb +41 -0
- data/app/components/govuk_component/back_link_component.rb +7 -3
- data/app/components/govuk_component/breadcrumbs_component.html.erb +2 -9
- data/app/components/govuk_component/breadcrumbs_component.rb +24 -1
- data/app/components/govuk_component/cookie_banner_component.rb +10 -5
- data/app/components/govuk_component/cookie_banner_component/message_component.rb +60 -0
- data/app/components/govuk_component/details_component.rb +5 -3
- data/app/components/govuk_component/footer_component.html.erb +4 -4
- data/app/components/govuk_component/footer_component.rb +45 -7
- data/app/components/govuk_component/header_component.html.erb +3 -3
- data/app/components/govuk_component/header_component.rb +2 -2
- data/app/components/govuk_component/inset_text_component.rb +9 -4
- data/app/components/govuk_component/notification_banner_component.html.erb +3 -3
- data/app/components/govuk_component/notification_banner_component.rb +29 -18
- data/app/components/govuk_component/panel_component.rb +25 -15
- data/app/components/govuk_component/phase_banner_component.rb +2 -2
- data/app/components/govuk_component/summary_list_component.html.erb +1 -7
- data/app/components/govuk_component/summary_list_component.rb +1 -36
- data/app/components/govuk_component/summary_list_component/action_component.rb +34 -0
- data/app/components/govuk_component/summary_list_component/key_component.rb +23 -0
- data/app/components/govuk_component/summary_list_component/row_component.rb +45 -0
- data/app/components/govuk_component/summary_list_component/value_component.rb +23 -0
- data/app/components/govuk_component/tab_component.html.erb +1 -1
- data/app/components/govuk_component/tab_component.rb +10 -8
- data/app/components/govuk_component/tag_component.rb +8 -14
- data/app/components/govuk_component/warning_text_component.rb +4 -4
- data/app/helpers/govuk_link_helper.rb +94 -34
- data/app/helpers/govuk_skip_link_helper.rb +7 -2
- data/lib/govuk/components/version.rb +1 -1
- metadata +11 -5
- data/app/components/govuk_component/cookie_banner_component.html.erb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9edec9359b5c0de9625e624d8287300e31870ff711796dc930fb344543ed926a
|
4
|
+
data.tar.gz: 29acdd36e71f45b69af12d291466e360bfc4bbc77db3ac48f57469d66912e3dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 146d5279be3e72e4164a0bbf81fa91c1262cfa88c61b28ef0be7dd1e7ccadb486ee998c1e33e6268868834019aa2c4dda0ace1adab701a34c77996db91ab3f0e
|
7
|
+
data.tar.gz: ab5f09b50cf6d80b776c0d2aff7824f85ad788b95c2d3f3b7e19bd998884ccb2cbe4ceb98e2eeff25619b6c5f251f156c8dc31cd2b41fd7d8b50b2ab872449c4
|
@@ -1,15 +1,5 @@
|
|
1
1
|
<%= tag.div(id: @id, class: classes, data: { module: 'govuk-accordion' }, **html_attributes) do %>
|
2
2
|
<% sections.each do |section| %>
|
3
|
-
<%=
|
4
|
-
<div class="govuk-accordion__section-header">
|
5
|
-
<h2 class="govuk-accordion__section-heading">
|
6
|
-
<%= tag.span(section.title, id: section.id, class: "govuk-accordion__section-button", aria: { expanded: section.expanded?, controls: section.id(suffix: 'content') }) %>
|
7
|
-
</h2>
|
8
|
-
<% if section.summary.present? %>
|
9
|
-
<%= tag.div(section.summary, id: section.id(suffix: 'summary'), class: %w(govuk-accordion__section-summary govuk-body)) %>
|
10
|
-
<% end %>
|
11
|
-
</div>
|
12
|
-
<%= section %>
|
13
|
-
<% end %>
|
3
|
+
<%= section %>
|
14
4
|
<% end %>
|
15
5
|
<% end %>
|
@@ -1,12 +1,23 @@
|
|
1
1
|
class GovukComponent::AccordionComponent < GovukComponent::Base
|
2
|
-
renders_many :sections,
|
2
|
+
renders_many :sections, ->(heading_text: nil, summary_text: nil, expanded: false, classes: [], html_attributes: {}, &block) do
|
3
|
+
GovukComponent::AccordionComponent::SectionComponent.new(
|
4
|
+
classes: classes,
|
5
|
+
expanded: expanded,
|
6
|
+
heading_level: heading_level, # set once at parent level, passed to all children
|
7
|
+
html_attributes: html_attributes,
|
8
|
+
summary_text: summary_text,
|
9
|
+
heading_text: heading_text,
|
10
|
+
&block
|
11
|
+
)
|
12
|
+
end
|
3
13
|
|
4
|
-
attr_reader :id
|
14
|
+
attr_reader :id, :heading_level
|
5
15
|
|
6
|
-
def initialize(id: nil, classes: [], html_attributes: {})
|
16
|
+
def initialize(id: nil, heading_level: 2, classes: [], html_attributes: {})
|
7
17
|
super(classes: classes, html_attributes: html_attributes)
|
8
18
|
|
9
|
-
@id
|
19
|
+
@id = id
|
20
|
+
@heading_level = heading_tag(heading_level)
|
10
21
|
end
|
11
22
|
|
12
23
|
private
|
@@ -15,33 +26,9 @@ private
|
|
15
26
|
%w(govuk-accordion)
|
16
27
|
end
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
alias_method :expanded?, :expanded
|
22
|
-
|
23
|
-
def initialize(title:, summary: nil, expanded: false, classes: [], html_attributes: {})
|
24
|
-
super(classes: classes, html_attributes: html_attributes)
|
25
|
-
|
26
|
-
@title = title
|
27
|
-
@summary = summary
|
28
|
-
@expanded = expanded
|
29
|
-
end
|
30
|
-
|
31
|
-
def id(suffix: nil)
|
32
|
-
[title.parameterize, suffix].compact.join('-')
|
33
|
-
end
|
34
|
-
|
35
|
-
def call
|
36
|
-
tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id })
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
29
|
+
def heading_tag(level)
|
30
|
+
fail(ArgumentError, "heading_level must be 1-6") unless level.in?(1..6)
|
40
31
|
|
41
|
-
|
42
|
-
%w(govuk-accordion__section).tap do |classes|
|
43
|
-
classes.append("govuk-accordion__section--expanded") if expanded?
|
44
|
-
end
|
45
|
-
end
|
32
|
+
%(h#{level})
|
46
33
|
end
|
47
34
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= tag.div(id: id(suffix: 'section'), class: classes, **html_attributes) do %>
|
2
|
+
<div class="govuk-accordion__section-header">
|
3
|
+
<%= content_tag(heading_level, class: "govuk-accordion__section-heading") do %>
|
4
|
+
<%= tag.span(heading_content, id: id, class: "govuk-accordion__section-button", aria: { expanded: expanded?, controls: id(suffix: 'content') }) %>
|
5
|
+
<% end %>
|
6
|
+
<% if summary_content.present? %>
|
7
|
+
<%= tag.div(summary_content, id: id(suffix: 'summary'), class: %w(govuk-accordion__section-summary govuk-body)) %>
|
8
|
+
<% end %>
|
9
|
+
</div>
|
10
|
+
<%= tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id }) %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class GovukComponent::AccordionComponent::SectionComponent < GovukComponent::Base
|
2
|
+
attr_reader :heading_text, :summary_text, :expanded, :heading_level
|
3
|
+
|
4
|
+
renders_one :heading_html
|
5
|
+
renders_one :summary_html
|
6
|
+
|
7
|
+
alias_method :expanded?, :expanded
|
8
|
+
|
9
|
+
def initialize(heading_text:, summary_text:, expanded:, heading_level:, classes: [], html_attributes: {})
|
10
|
+
super(classes: classes, html_attributes: html_attributes)
|
11
|
+
|
12
|
+
@heading_text = heading_text
|
13
|
+
@summary_text = summary_text
|
14
|
+
@expanded = expanded
|
15
|
+
@heading_level = heading_level
|
16
|
+
end
|
17
|
+
|
18
|
+
def id(suffix: nil)
|
19
|
+
# generate a random number if we don't have heading_text to avoid attempting
|
20
|
+
# to parameterize a potentially-huge chunk of HTML
|
21
|
+
@prefix ||= heading_text&.parameterize || SecureRandom.hex(4)
|
22
|
+
|
23
|
+
[@prefix, suffix].compact.join('-')
|
24
|
+
end
|
25
|
+
|
26
|
+
def heading_content
|
27
|
+
heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html")
|
28
|
+
end
|
29
|
+
|
30
|
+
def summary_content
|
31
|
+
summary_html || summary_text
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def default_classes
|
37
|
+
%w(govuk-accordion__section).tap do |classes|
|
38
|
+
classes.append("govuk-accordion__section--expanded") if expanded?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class GovukComponent::BackLinkComponent < GovukComponent::Base
|
2
|
-
attr_reader :text, :href
|
2
|
+
attr_reader :text, :href
|
3
3
|
|
4
|
-
def initialize(
|
4
|
+
def initialize(href:, text: nil, classes: nil, html_attributes: {})
|
5
5
|
super(classes: classes, html_attributes: html_attributes)
|
6
6
|
|
7
7
|
@text = text
|
@@ -9,11 +9,15 @@ class GovukComponent::BackLinkComponent < GovukComponent::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call
|
12
|
-
link_to(
|
12
|
+
link_to(link_content, href, class: classes, **html_attributes)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
+
def link_content
|
18
|
+
text || content || fail(ArgumentError, "no text or content")
|
19
|
+
end
|
20
|
+
|
17
21
|
def default_classes
|
18
22
|
%w(govuk-back-link)
|
19
23
|
end
|
@@ -1,14 +1,7 @@
|
|
1
1
|
<%= tag.div(class: classes, **html_attributes) do %>
|
2
2
|
<ol class="govuk-breadcrumbs__list">
|
3
|
-
<% @breadcrumbs.each do |
|
4
|
-
|
5
|
-
<% if link.present? %>
|
6
|
-
<li class="govuk-breadcrumbs__list-item">
|
7
|
-
<%= link_to(text, link, class: "govuk-breadcrumbs__link") %>
|
8
|
-
</li>
|
9
|
-
<% else %>
|
10
|
-
<%= tag.li(text, class: "govuk-breadcrumbs__list-item", aria: { current: "page" }) %>
|
11
|
-
<% end %>
|
3
|
+
<% @breadcrumbs.each do |link| %>
|
4
|
+
<%= link %>
|
12
5
|
<% end %>
|
13
6
|
</ol>
|
14
7
|
<% end %>
|
@@ -4,7 +4,7 @@ class GovukComponent::BreadcrumbsComponent < GovukComponent::Base
|
|
4
4
|
def initialize(breadcrumbs:, hide_in_print: false, collapse_on_mobile: false, classes: [], html_attributes: {})
|
5
5
|
super(classes: classes, html_attributes: html_attributes)
|
6
6
|
|
7
|
-
@breadcrumbs = breadcrumbs
|
7
|
+
@breadcrumbs = build_list(breadcrumbs)
|
8
8
|
@hide_in_print = hide_in_print
|
9
9
|
@collapse_on_mobile = collapse_on_mobile
|
10
10
|
end
|
@@ -17,4 +17,27 @@ private
|
|
17
17
|
classes << "govuk-breadcrumbs--collapse-on-mobile" if collapse_on_mobile
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def build_list(breadcrumbs)
|
22
|
+
case breadcrumbs
|
23
|
+
when Array
|
24
|
+
breadcrumbs.map { |item| build_list_item(item) }
|
25
|
+
when Hash
|
26
|
+
breadcrumbs.map { |text, link| build_list_item(text, link) }
|
27
|
+
else
|
28
|
+
fail(ArgumentError, "breadcrumb must be an array or hash")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_list_item(text, link = nil)
|
33
|
+
if link.present?
|
34
|
+
list_item { link_to(text, link, class: "govuk-breadcrumbs__link") }
|
35
|
+
else
|
36
|
+
list_item(aria: { current: "page" }) { text }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_item(html_attributes = {}, &block)
|
41
|
+
tag.li(class: "govuk-breadcrumbs__list-item", **html_attributes, &block)
|
42
|
+
end
|
20
43
|
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
class GovukComponent::CookieBannerComponent < GovukComponent::Base
|
2
|
-
|
3
|
-
renders_one :actions
|
2
|
+
renders_many :messages, GovukComponent::CookieBannerComponent::MessageComponent
|
4
3
|
|
5
|
-
attr_accessor :
|
4
|
+
attr_accessor :aria_label, :hidden
|
6
5
|
|
7
|
-
def initialize(
|
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,60 @@
|
|
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
|
+
safe_join([
|
20
|
+
tag.div(class: "govuk-grid-column-two-thirds") { safe_join([heading_element, message_element]) },
|
21
|
+
actions_element
|
22
|
+
])
|
23
|
+
end
|
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
|
+
tag.h2(heading_content, class: %w(govuk-cookie-banner__heading govuk-heading-m))
|
35
|
+
end
|
36
|
+
|
37
|
+
def heading_content
|
38
|
+
heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html")
|
39
|
+
end
|
40
|
+
|
41
|
+
def message_element
|
42
|
+
tag.div(message_content, class: "govuk-cookie-banner__content")
|
43
|
+
end
|
44
|
+
|
45
|
+
def message_content
|
46
|
+
content || wrap_in_p(text) || fail(ArgumentError, "no text or content")
|
47
|
+
end
|
48
|
+
|
49
|
+
def wrap_in_p(message_text)
|
50
|
+
return if message_text.blank?
|
51
|
+
|
52
|
+
tag.p(message_text)
|
53
|
+
end
|
54
|
+
|
55
|
+
def actions_element
|
56
|
+
return if actions.none?
|
57
|
+
|
58
|
+
tag.div(class: "govuk-button-group") { safe_join(actions) }
|
59
|
+
end
|
60
|
+
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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%= tag.footer(class: classes, role: 'contentinfo', **html_attributes) do %>
|
2
|
-
|
3
|
-
|
2
|
+
<%= tag.div(class: container_classes, **container_html_attributes) do %>
|
3
|
+
<%= tag.div(class: meta_classes, **meta_html_attributes) do %>
|
4
4
|
<% if meta.present? %>
|
5
5
|
<%= meta %>
|
6
6
|
<% else %>
|
@@ -35,6 +35,6 @@
|
|
35
35
|
<%= tag.div(copyright, class: "govuk-footer__meta-item") %>
|
36
36
|
</div>
|
37
37
|
<% end %>
|
38
|
-
|
39
|
-
|
38
|
+
<% end %>
|
39
|
+
<% end %>
|
40
40
|
<% end %>
|
@@ -1,16 +1,34 @@
|
|
1
1
|
class GovukComponent::FooterComponent < GovukComponent::Base
|
2
|
-
renders_one :
|
2
|
+
renders_one :meta_html
|
3
3
|
renders_one :meta
|
4
4
|
|
5
|
-
attr_reader :meta_items, :meta_items_title, :meta_licence, :copyright
|
5
|
+
attr_reader :meta_items, :meta_text, :meta_items_title, :meta_licence, :copyright, :custom_container_classes
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(
|
8
|
+
classes: [],
|
9
|
+
container_classes: [],
|
10
|
+
container_html_attributes: {},
|
11
|
+
copyright_text: default_copright_text,
|
12
|
+
copyright_url: default_copyright_url,
|
13
|
+
html_attributes: {},
|
14
|
+
meta_items: {},
|
15
|
+
meta_items_title: "Support links",
|
16
|
+
meta_licence: nil,
|
17
|
+
meta_text: nil,
|
18
|
+
meta_classes: [],
|
19
|
+
meta_html_attributes: {}
|
20
|
+
)
|
8
21
|
super(classes: classes, html_attributes: html_attributes)
|
9
22
|
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
23
|
+
@meta_text = meta_text
|
24
|
+
@meta_items = build_meta_links(meta_items)
|
25
|
+
@meta_items_title = meta_items_title
|
26
|
+
@meta_licence = meta_licence
|
27
|
+
@custom_meta_classes = meta_classes
|
28
|
+
@custom_meta_html_attributes = meta_html_attributes
|
29
|
+
@copyright = build_copyright(copyright_text, copyright_url)
|
30
|
+
@custom_container_classes = container_classes
|
31
|
+
@custom_container_html_attributes = container_html_attributes
|
14
32
|
end
|
15
33
|
|
16
34
|
private
|
@@ -19,6 +37,26 @@ private
|
|
19
37
|
%w(govuk-footer)
|
20
38
|
end
|
21
39
|
|
40
|
+
def container_classes
|
41
|
+
combine_classes(%w(govuk-width-container), custom_container_classes)
|
42
|
+
end
|
43
|
+
|
44
|
+
def meta_content
|
45
|
+
meta_html || meta_text
|
46
|
+
end
|
47
|
+
|
48
|
+
def meta_classes
|
49
|
+
%w(govuk-footer__meta).append(@custom_meta_classes)
|
50
|
+
end
|
51
|
+
|
52
|
+
def meta_html_attributes
|
53
|
+
@custom_meta_html_attributes
|
54
|
+
end
|
55
|
+
|
56
|
+
def container_html_attributes
|
57
|
+
@custom_container_html_attributes
|
58
|
+
end
|
59
|
+
|
22
60
|
def build_meta_links(links)
|
23
61
|
return [] if links.blank?
|
24
62
|
|
@@ -21,17 +21,17 @@
|
|
21
21
|
<% end %>
|
22
22
|
</div>
|
23
23
|
|
24
|
-
<% if service_name.present? ||
|
24
|
+
<% if service_name.present? || navigation_items.present? %>
|
25
25
|
<div class="govuk-header__content">
|
26
26
|
<% if service_name.present? %>
|
27
27
|
<%= link_to(service_name, service_url, class: %w(govuk-header__link govuk-header__link--service-name)) %>
|
28
28
|
<% end %>
|
29
29
|
|
30
|
-
<% if
|
30
|
+
<% if navigation_items.any? %>
|
31
31
|
<%= tag.button("Menu", type: "button", class: %w(govuk-header__menu-button govuk-js-header-toggle), aria: { controls: "navigation", label: menu_button_label }) %>
|
32
32
|
<nav>
|
33
33
|
<%= tag.ul(class: navigation_classes, id: "navigation", aria: { label: navigation_label }) do %>
|
34
|
-
<%
|
34
|
+
<% navigation_items.each do |item| %>
|
35
35
|
<%= tag.li(class: item.classes.append(item.active_class), **item.html_attributes) do %>
|
36
36
|
<% if item.link? %>
|
37
37
|
<%= link_to(item.text, item.href, class: "govuk-header__link") %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class GovukComponent::HeaderComponent < GovukComponent::Base
|
2
|
-
renders_many :
|
2
|
+
renders_many :navigation_items, "NavigationItem"
|
3
3
|
renders_one :custom_logo
|
4
4
|
renders_one :product_name, "ProductName"
|
5
5
|
|
@@ -52,7 +52,7 @@ private
|
|
52
52
|
combine_classes(%w(govuk-header__container govuk-width-container), custom_container_classes)
|
53
53
|
end
|
54
54
|
|
55
|
-
class
|
55
|
+
class NavigationItem < GovukComponent::Base
|
56
56
|
attr_reader :text, :href, :active
|
57
57
|
|
58
58
|
def initialize(text:, href: nil, active: false, classes: [], html_attributes: {})
|
@@ -1,22 +1,27 @@
|
|
1
1
|
class GovukComponent::InsetTextComponent < GovukComponent::Base
|
2
|
-
attr_reader :text
|
2
|
+
attr_reader :text, :id
|
3
3
|
|
4
|
-
def initialize(text: nil, classes: [], html_attributes: {})
|
4
|
+
def initialize(text: nil, id: nil, classes: [], html_attributes: {})
|
5
5
|
super(classes: classes, html_attributes: html_attributes)
|
6
6
|
|
7
7
|
@text = text
|
8
|
+
@id = id
|
8
9
|
end
|
9
10
|
|
10
11
|
def call
|
11
|
-
tag.div(class: classes, **html_attributes) {
|
12
|
+
tag.div(class: classes, id: id, **html_attributes) { inset_text_content }
|
12
13
|
end
|
13
14
|
|
14
15
|
def render?
|
15
|
-
|
16
|
+
inset_text_content.present?
|
16
17
|
end
|
17
18
|
|
18
19
|
private
|
19
20
|
|
21
|
+
def inset_text_content
|
22
|
+
content.presence || text
|
23
|
+
end
|
24
|
+
|
20
25
|
def default_classes
|
21
26
|
%w(govuk-inset-text)
|
22
27
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
<%= tag.div(class: classes, role:
|
1
|
+
<%= tag.div(class: classes, role: role, aria: { labelledby: title_id }, data: data_params, **html_attributes) do %>
|
2
2
|
<div class="govuk-notification-banner__header">
|
3
3
|
<%= content_tag(title_tag, class: "govuk-notification-banner__title", id: title_id) do %>
|
4
|
-
<%=
|
4
|
+
<%= title_content %>
|
5
5
|
<% end %>
|
6
6
|
</div>
|
7
7
|
<div class="govuk-notification-banner__content">
|
@@ -9,6 +9,6 @@
|
|
9
9
|
<%= heading %>
|
10
10
|
<% end %>
|
11
11
|
|
12
|
-
<%= content %>
|
12
|
+
<%= content || text %>
|
13
13
|
</div>
|
14
14
|
<% end %>
|
@@ -1,34 +1,23 @@
|
|
1
1
|
class GovukComponent::NotificationBannerComponent < GovukComponent::Base
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :title_text, :title_id, :text, :success, :title_heading_level, :disable_auto_focus, :role
|
3
3
|
|
4
|
+
renders_one :title_html
|
4
5
|
renders_many :headings, "Heading"
|
5
6
|
|
6
|
-
def initialize(
|
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: {})
|
7
8
|
super(classes: classes, html_attributes: html_attributes)
|
8
9
|
|
9
|
-
@
|
10
|
+
@title_text = title_text
|
10
11
|
@title_id = title_id
|
12
|
+
@text = text
|
11
13
|
@success = success
|
14
|
+
@role = role || default_role
|
12
15
|
@title_heading_level = title_heading_level
|
13
16
|
@disable_auto_focus = disable_auto_focus
|
14
17
|
end
|
15
18
|
|
16
19
|
def render?
|
17
|
-
headings.any? || content.present?
|
18
|
-
end
|
19
|
-
|
20
|
-
def classes
|
21
|
-
super.append(success_class).compact
|
22
|
-
end
|
23
|
-
|
24
|
-
def success_class
|
25
|
-
%(govuk-notification-banner--success) if success
|
26
|
-
end
|
27
|
-
|
28
|
-
def title_tag
|
29
|
-
fail "title_heading_level must be a number between 1 and 6" unless title_heading_level.is_a?(Integer) && title_heading_level.in?(1..6)
|
30
|
-
|
31
|
-
"h#{title_heading_level}"
|
20
|
+
headings.any? || text.present? || content.present?
|
32
21
|
end
|
33
22
|
|
34
23
|
class Heading < GovukComponent::Base
|
@@ -70,4 +59,26 @@ private
|
|
70
59
|
def data_params
|
71
60
|
{ "module" => "govuk-notification-banner", "disable-auto-focus" => disable_auto_focus }.compact
|
72
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
|
73
84
|
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
class GovukComponent::PanelComponent < GovukComponent::Base
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :id, :title_text, :text, :heading_level
|
3
3
|
|
4
|
-
|
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
|
-
@
|
8
|
-
@
|
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
|
24
|
-
|
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
|
28
|
-
|
35
|
+
def title
|
36
|
+
title_html || title_text
|
29
37
|
end
|
30
38
|
|
31
39
|
def panel_title
|
32
|
-
|
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
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
54
|
+
title.present? || panel_content.present?
|
45
55
|
end
|
46
56
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class GovukComponent::PhaseBannerComponent < GovukComponent::Base
|
2
2
|
attr_reader :text, :phase_tag
|
3
3
|
|
4
|
-
def initialize(
|
4
|
+
def initialize(tag: nil, text: nil, classes: [], html_attributes: {})
|
5
5
|
super(classes: classes, html_attributes: html_attributes)
|
6
6
|
|
7
|
-
@phase_tag =
|
7
|
+
@phase_tag = tag
|
8
8
|
@text = text
|
9
9
|
end
|
10
10
|
|
@@ -1,11 +1,5 @@
|
|
1
1
|
<%= tag.dl(class: classes, **html_attributes) do %>
|
2
2
|
<% rows.each do |row| %>
|
3
|
-
<%=
|
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,
|
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,39 +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
|
-
tag.dd(class: "govuk-summary-list__actions") do
|
50
|
-
if href.present?
|
51
|
-
govuk_link_to(href, class: action_classes, **action_attributes) do
|
52
|
-
safe_join([text, tag.span(visually_hidden_text, class: "govuk-visually-hidden")])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def default_classes
|
61
|
-
%w(govuk-summary-list__row)
|
62
|
-
end
|
63
|
-
end
|
64
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, :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 :
|
20
|
+
attr_reader :label, :text
|
20
21
|
|
21
|
-
def initialize(
|
22
|
+
def initialize(label:, text: nil, classes: [], html_attributes: {})
|
22
23
|
super(classes: classes, html_attributes: html_attributes)
|
23
24
|
|
24
|
-
@
|
25
|
+
@label = label
|
26
|
+
@text = text
|
25
27
|
end
|
26
28
|
|
27
29
|
def id(prefix: nil)
|
28
|
-
[prefix,
|
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(
|
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,19 +1,9 @@
|
|
1
1
|
class GovukComponent::TagComponent < GovukComponent::Base
|
2
2
|
attr_reader :text, :colour
|
3
3
|
|
4
|
-
COLOURS = %w(
|
5
|
-
|
6
|
-
|
7
|
-
turquoise
|
8
|
-
blue
|
9
|
-
red
|
10
|
-
purple
|
11
|
-
pink
|
12
|
-
orange
|
13
|
-
yellow
|
14
|
-
).freeze
|
15
|
-
|
16
|
-
def initialize(text:, colour: nil, classes: [], html_attributes: {})
|
4
|
+
COLOURS = %w(grey green turquoise blue red purple pink orange yellow).freeze
|
5
|
+
|
6
|
+
def initialize(text: nil, colour: nil, classes: [], html_attributes: {})
|
17
7
|
super(classes: classes, html_attributes: html_attributes)
|
18
8
|
|
19
9
|
@text = text
|
@@ -21,11 +11,15 @@ class GovukComponent::TagComponent < GovukComponent::Base
|
|
21
11
|
end
|
22
12
|
|
23
13
|
def call
|
24
|
-
tag.strong(
|
14
|
+
tag.strong(tag_content, class: classes.append(colour_class), **html_attributes)
|
25
15
|
end
|
26
16
|
|
27
17
|
private
|
28
18
|
|
19
|
+
def tag_content
|
20
|
+
@text || content || fail(ArgumentError, "no text or content")
|
21
|
+
end
|
22
|
+
|
29
23
|
def default_classes
|
30
24
|
%w(govuk-tag)
|
31
25
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class GovukComponent::WarningTextComponent < GovukComponent::Base
|
2
|
-
attr_reader :text, :
|
2
|
+
attr_reader :text, :icon_fallback_text
|
3
3
|
|
4
4
|
ICON = '!'.freeze
|
5
5
|
|
6
|
-
def initialize(text:,
|
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
|
-
@
|
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(
|
32
|
+
tag.span(icon_fallback_text, class: 'govuk-warning-text__assistive')
|
33
33
|
end
|
34
34
|
|
35
35
|
def default_classes
|
@@ -1,61 +1,121 @@
|
|
1
1
|
module GovukLinkHelper
|
2
|
-
|
3
|
-
|
2
|
+
LINK_STYLES = {
|
3
|
+
inverse: "govuk-link--inverse",
|
4
|
+
muted: "govuk-link--muted",
|
5
|
+
no_underline: "govuk-link--no-underline",
|
6
|
+
no_visited_state: "govuk-link--no-visited-state",
|
7
|
+
text_colour: "govuk-link--text-colour",
|
8
|
+
}.freeze
|
4
9
|
|
5
|
-
|
6
|
-
|
10
|
+
BUTTON_STYLES = {
|
11
|
+
disabled: "govuk-button--disabled",
|
12
|
+
secondary: "govuk-button--secondary",
|
13
|
+
warning: "govuk-button--warning",
|
14
|
+
}.freeze
|
7
15
|
|
8
|
-
def
|
9
|
-
|
16
|
+
def govuk_link_classes(*styles, default_class: 'govuk-link')
|
17
|
+
if (invalid_styles = (styles - LINK_STYLES.keys)) && invalid_styles.any?
|
18
|
+
fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{LINK_STYLES.keys.to_sentence}")
|
19
|
+
end
|
10
20
|
|
11
|
-
|
21
|
+
[default_class] + LINK_STYLES.values_at(*styles).compact
|
12
22
|
end
|
13
23
|
|
14
|
-
def
|
15
|
-
|
24
|
+
def govuk_button_classes(*styles, default_class: 'govuk-button')
|
25
|
+
if (invalid_styles = (styles - BUTTON_STYLES.keys)) && invalid_styles.any?
|
26
|
+
fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{BUTTON_STYLES.keys.to_sentence}")
|
27
|
+
end
|
28
|
+
|
29
|
+
[default_class] + BUTTON_STYLES.values_at(*styles).compact
|
16
30
|
end
|
17
31
|
|
18
|
-
|
32
|
+
def govuk_link_to(name = nil, options = nil, extra_options = {}, &block)
|
33
|
+
extra_options = options if block_given?
|
34
|
+
html_options = build_html_options(extra_options)
|
19
35
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
text_colour_class(text_colour),
|
26
|
-
inverse_class(inverse),
|
27
|
-
no_underline_class(no_underline),
|
28
|
-
]
|
36
|
+
if block_given?
|
37
|
+
link_to(name, html_options, &block)
|
38
|
+
else
|
39
|
+
link_to(name, options, html_options)
|
40
|
+
end
|
29
41
|
end
|
30
42
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
43
|
+
def govuk_mail_to(email_address, name = nil, extra_options = {}, &block)
|
44
|
+
extra_options = name if block_given?
|
45
|
+
html_options = build_html_options(extra_options)
|
46
|
+
|
47
|
+
if block_given?
|
48
|
+
mail_to(email_address, html_options, &block)
|
49
|
+
else
|
50
|
+
mail_to(email_address, name, html_options)
|
34
51
|
end
|
35
52
|
end
|
36
53
|
|
37
|
-
def
|
38
|
-
|
54
|
+
def govuk_button_to(name = nil, options = nil, extra_options = {}, &block)
|
55
|
+
extra_options = options if block_given?
|
56
|
+
html_options = build_html_options(extra_options, style: :button)
|
57
|
+
|
58
|
+
if block_given?
|
59
|
+
button_to(name, html_options, &block)
|
60
|
+
else
|
61
|
+
button_to(name, options, html_options)
|
62
|
+
end
|
39
63
|
end
|
40
64
|
|
41
|
-
def
|
42
|
-
|
65
|
+
def govuk_button_link_to(name = nil, options = nil, extra_options = {}, &block)
|
66
|
+
extra_options = options if block_given?
|
67
|
+
html_options = build_html_options(extra_options, style: :button)
|
68
|
+
|
69
|
+
if block_given?
|
70
|
+
link_to(name, html_options, &block)
|
71
|
+
else
|
72
|
+
link_to(name, options, html_options)
|
73
|
+
end
|
43
74
|
end
|
44
75
|
|
45
|
-
def
|
46
|
-
|
76
|
+
def govuk_breadcrumb_link_to(name = nil, options = nil, extra_options = {}, &block)
|
77
|
+
extra_options = options if block_given?
|
78
|
+
html_options = build_html_options(extra_options, style: :breadcrumb)
|
79
|
+
|
80
|
+
if block_given?
|
81
|
+
link_to(name, html_options, &block)
|
82
|
+
else
|
83
|
+
link_to(name, options, html_options)
|
84
|
+
end
|
47
85
|
end
|
48
86
|
|
49
|
-
|
50
|
-
|
87
|
+
private
|
88
|
+
|
89
|
+
def build_html_options(provided_options, style: :link)
|
90
|
+
styles = case style
|
91
|
+
when :link then LINK_STYLES
|
92
|
+
when :button then BUTTON_STYLES
|
93
|
+
else {}
|
94
|
+
end
|
95
|
+
|
96
|
+
remaining_options = provided_options&.slice!(*styles.keys)
|
97
|
+
|
98
|
+
return {} unless (style_classes = build_style_classes(style, provided_options))
|
99
|
+
|
100
|
+
inject_class(remaining_options, class_name: style_classes)
|
51
101
|
end
|
52
102
|
|
53
|
-
def
|
54
|
-
|
103
|
+
def build_style_classes(style, provided_options)
|
104
|
+
keys = *provided_options&.keys
|
105
|
+
|
106
|
+
case style
|
107
|
+
when :link then govuk_link_classes(*keys)
|
108
|
+
when :button then govuk_button_classes(*keys)
|
109
|
+
when :breadcrumb then %w(govuk-breadcrumbs__link)
|
110
|
+
end
|
55
111
|
end
|
56
112
|
|
57
|
-
def
|
58
|
-
|
113
|
+
def inject_class(attributes, class_name:)
|
114
|
+
attributes ||= {}
|
115
|
+
|
116
|
+
attributes.with_indifferent_access.tap do |attrs|
|
117
|
+
attrs[:class] = Array.wrap(attrs[:class]).prepend(class_name).flatten
|
118
|
+
end
|
59
119
|
end
|
60
120
|
end
|
61
121
|
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module GovukSkipLinkHelper
|
2
|
-
def govuk_skip_link(text: 'Skip to main content', href: '#main-content')
|
3
|
-
|
2
|
+
def govuk_skip_link(text: 'Skip to main content', href: '#main-content', classes: [], **html_attributes, &block)
|
3
|
+
link_classes = Array.wrap(classes).append('govuk-skip-link')
|
4
|
+
|
5
|
+
return link_to(href, class: link_classes, **html_attributes, &block) if block_given?
|
6
|
+
|
7
|
+
link_to(text, href, class: link_classes, **html_attributes)
|
4
8
|
end
|
5
9
|
end
|
10
|
+
|
6
11
|
ActiveSupport.on_load(:action_view) { include GovukSkipLinkHelper }
|
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.
|
4
|
+
version: 2.0.0rc2
|
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-
|
11
|
+
date: 2021-08-04 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.
|
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.
|
54
|
+
version: 2.36.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry-byebug
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,12 +163,14 @@ files:
|
|
163
163
|
- Rakefile
|
164
164
|
- app/components/govuk_component/accordion_component.html.erb
|
165
165
|
- app/components/govuk_component/accordion_component.rb
|
166
|
+
- app/components/govuk_component/accordion_component/section_component.html.erb
|
167
|
+
- app/components/govuk_component/accordion_component/section_component.rb
|
166
168
|
- app/components/govuk_component/back_link_component.rb
|
167
169
|
- app/components/govuk_component/base.rb
|
168
170
|
- app/components/govuk_component/breadcrumbs_component.html.erb
|
169
171
|
- app/components/govuk_component/breadcrumbs_component.rb
|
170
|
-
- app/components/govuk_component/cookie_banner_component.html.erb
|
171
172
|
- app/components/govuk_component/cookie_banner_component.rb
|
173
|
+
- app/components/govuk_component/cookie_banner_component/message_component.rb
|
172
174
|
- app/components/govuk_component/details_component.rb
|
173
175
|
- app/components/govuk_component/footer_component.html.erb
|
174
176
|
- app/components/govuk_component/footer_component.rb
|
@@ -183,6 +185,10 @@ files:
|
|
183
185
|
- app/components/govuk_component/start_button_component.rb
|
184
186
|
- app/components/govuk_component/summary_list_component.html.erb
|
185
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
|
186
192
|
- app/components/govuk_component/tab_component.html.erb
|
187
193
|
- app/components/govuk_component/tab_component.rb
|
188
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 %>
|