govuk-components 1.1.9 → 2.0.0b4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/app/components/govuk_component/{accordion.html.erb → accordion_component.html.erb} +2 -2
- data/app/components/govuk_component/{accordion.rb → accordion_component.rb} +13 -14
- data/app/components/govuk_component/{back_link.rb → back_link_component.rb} +6 -2
- data/app/components/govuk_component/base.rb +9 -7
- data/app/components/govuk_component/{breadcrumbs.html.erb → breadcrumbs_component.html.erb} +3 -6
- data/app/components/govuk_component/{breadcrumbs.rb → breadcrumbs_component.rb} +4 -4
- data/app/components/govuk_component/{cookie_banner.html.erb → cookie_banner_component.html.erb} +2 -6
- data/app/components/govuk_component/{cookie_banner.rb → cookie_banner_component.rb} +1 -1
- data/app/components/govuk_component/details_component.rb +40 -0
- data/app/components/govuk_component/{footer.html.erb → footer_component.html.erb} +3 -5
- data/app/components/govuk_component/{footer.rb → footer_component.rb} +4 -9
- data/app/components/govuk_component/header_component.html.erb +49 -0
- data/app/components/govuk_component/header_component.rb +112 -0
- data/app/components/govuk_component/{inset_text.rb → inset_text_component.rb} +4 -4
- data/app/components/govuk_component/notification_banner_component.html.erb +14 -0
- data/app/components/govuk_component/{notification_banner.rb → notification_banner_component.rb} +30 -16
- data/app/components/govuk_component/panel_component.rb +46 -0
- data/app/components/govuk_component/phase_banner_component.html.erb +6 -0
- data/app/components/govuk_component/phase_banner_component.rb +20 -0
- data/app/components/govuk_component/start_button_component.rb +47 -0
- data/app/components/govuk_component/summary_list_component.html.erb +11 -0
- data/app/components/govuk_component/summary_list_component.rb +64 -0
- data/app/components/govuk_component/tab_component.html.erb +11 -0
- data/app/components/govuk_component/{tabs.rb → tab_component.rb} +23 -12
- data/app/components/govuk_component/tag_component.rb +48 -0
- data/app/components/govuk_component/warning_text_component.rb +38 -0
- data/app/helpers/govuk_components_helper.rb +16 -16
- data/app/helpers/govuk_link_helper.rb +39 -4
- data/lib/govuk/components.rb +1 -0
- data/lib/govuk/components/helpers/css_utilities.rb +22 -0
- data/lib/govuk/components/version.rb +1 -1
- metadata +48 -53
- data/app/components/govuk_component/back_link.html.erb +0 -1
- data/app/components/govuk_component/details.html.erb +0 -10
- data/app/components/govuk_component/details.rb +0 -16
- data/app/components/govuk_component/header.html.erb +0 -52
- data/app/components/govuk_component/header.rb +0 -65
- data/app/components/govuk_component/notification_banner.html.erb +0 -23
- data/app/components/govuk_component/panel.html.erb +0 -13
- data/app/components/govuk_component/panel.rb +0 -28
- data/app/components/govuk_component/phase_banner.html.erb +0 -8
- data/app/components/govuk_component/phase_banner.rb +0 -16
- data/app/components/govuk_component/slot.rb +0 -9
- data/app/components/govuk_component/start_now_button.html.erb +0 -6
- data/app/components/govuk_component/start_now_button.rb +0 -16
- data/app/components/govuk_component/summary_list.html.erb +0 -19
- data/app/components/govuk_component/summary_list.rb +0 -34
- data/app/components/govuk_component/tabs.html.erb +0 -19
- data/app/components/govuk_component/tag.rb +0 -30
- data/app/components/govuk_component/warning.html.erb +0 -7
- data/app/components/govuk_component/warning.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adc43cd112d0d674ac3780c1b8d82b73085994b4d94d4637b555309c35339f3f
|
4
|
+
data.tar.gz: c48babb1d6c848ce088a4677021dfdf6b85e99381de187856db129f3256026c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d079f362768501769be70a9ab9e18664b995f32a36693b1b7f6be230c4394d61a006255703f467fd7d80b190976690f1268ca303914e1c6155bc9e2f56ab4b
|
7
|
+
data.tar.gz: ffee587ebba53cdde8399c898a34cf0def0d7d43327153300972afd6a0e6c4e08fdf64bfb3bda90b178152ab0f71f50daca9532f33542dc5654d80a259ca99c6
|
data/README.md
CHANGED
@@ -99,7 +99,11 @@ To setup the dummy app:
|
|
99
99
|
`bin/rails db:migrate`
|
100
100
|
`bin/rails s`
|
101
101
|
|
102
|
-
After
|
102
|
+
After changing a component or adding a new one:
|
103
|
+
|
104
|
+
* add or update the corresponding specs, and check they pass by running `bundle exec rspec`.
|
105
|
+
|
106
|
+
* update the examples page by cd-ing into the dummy app `cd spec/dummy` and running the rake task `bin/rake generate_examples_page`.
|
103
107
|
|
104
108
|
## License
|
105
109
|
|
@@ -3,13 +3,13 @@
|
|
3
3
|
<%= tag.div(id: section.id(suffix: 'section'), class: section.classes, **section.html_attributes) do %>
|
4
4
|
<div class="govuk-accordion__section-header">
|
5
5
|
<h2 class="govuk-accordion__section-heading">
|
6
|
-
<%= tag.span(section.title, id: section.id, class: "govuk-accordion__section-button", aria: { expanded: section.expanded
|
6
|
+
<%= tag.span(section.title, id: section.id, class: "govuk-accordion__section-button", aria: { expanded: section.expanded?, controls: section.id(suffix: 'content') }) %>
|
7
7
|
</h2>
|
8
8
|
<% if section.summary.present? %>
|
9
9
|
<%= tag.div(section.summary, id: section.id(suffix: 'summary'), class: %w(govuk-accordion__section-summary govuk-body)) %>
|
10
10
|
<% end %>
|
11
11
|
</div>
|
12
|
-
<%=
|
12
|
+
<%= section %>
|
13
13
|
<% end %>
|
14
14
|
<% end %>
|
15
15
|
<% end %>
|
@@ -1,10 +1,7 @@
|
|
1
|
-
class GovukComponent::
|
2
|
-
|
1
|
+
class GovukComponent::AccordionComponent < GovukComponent::Base
|
2
|
+
renders_many :sections, "Section"
|
3
3
|
|
4
|
-
|
5
|
-
wrap_slot :section
|
6
|
-
|
7
|
-
attr_accessor :id
|
4
|
+
attr_reader :id
|
8
5
|
|
9
6
|
def initialize(id: nil, classes: [], html_attributes: {})
|
10
7
|
super(classes: classes, html_attributes: html_attributes)
|
@@ -18,31 +15,33 @@ private
|
|
18
15
|
%w(govuk-accordion)
|
19
16
|
end
|
20
17
|
|
21
|
-
class Section < GovukComponent::
|
22
|
-
|
18
|
+
class Section < GovukComponent::Base
|
19
|
+
attr_reader :title, :summary, :expanded
|
23
20
|
|
24
21
|
alias_method :expanded?, :expanded
|
25
22
|
|
26
23
|
def initialize(title:, summary: nil, expanded: false, classes: [], html_attributes: {})
|
27
24
|
super(classes: classes, html_attributes: html_attributes)
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
@title = title
|
27
|
+
@summary = summary
|
28
|
+
@expanded = expanded
|
32
29
|
end
|
33
30
|
|
34
31
|
def id(suffix: nil)
|
35
32
|
[title.parameterize, suffix].compact.join('-')
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
39
|
-
|
35
|
+
def call
|
36
|
+
tag.div(content, id: id(suffix: 'content'), class: %w(govuk-accordion__section-content), aria: { labelledby: id })
|
40
37
|
end
|
41
38
|
|
42
39
|
private
|
43
40
|
|
44
41
|
def default_classes
|
45
|
-
%w(govuk-accordion__section)
|
42
|
+
%w(govuk-accordion__section).tap do |classes|
|
43
|
+
classes.append("govuk-accordion__section--expanded") if expanded?
|
44
|
+
end
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class GovukComponent::
|
2
|
-
|
1
|
+
class GovukComponent::BackLinkComponent < GovukComponent::Base
|
2
|
+
attr_reader :text, :href, :options
|
3
3
|
|
4
4
|
def initialize(text:, href:, classes: nil, html_attributes: {})
|
5
5
|
super(classes: classes, html_attributes: html_attributes)
|
@@ -8,6 +8,10 @@ class GovukComponent::BackLink < GovukComponent::Base
|
|
8
8
|
@href = href
|
9
9
|
end
|
10
10
|
|
11
|
+
def call
|
12
|
+
link_to(text, href, class: classes, **html_attributes)
|
13
|
+
end
|
14
|
+
|
11
15
|
private
|
12
16
|
|
13
17
|
def default_classes
|
@@ -1,17 +1,19 @@
|
|
1
1
|
class GovukComponent::Base < ViewComponent::Base
|
2
|
+
include Govuk::Components::Helpers::CssUtilities
|
3
|
+
|
2
4
|
include GovukComponent::Traits::CustomClasses
|
3
5
|
include GovukComponent::Traits::CustomHtmlAttributes
|
4
6
|
|
5
|
-
|
7
|
+
attr_reader :html_attributes
|
8
|
+
|
9
|
+
def initialize(classes:, html_attributes:)
|
6
10
|
@classes = parse_classes(classes)
|
7
11
|
@html_attributes = html_attributes
|
12
|
+
|
13
|
+
super
|
8
14
|
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
def self.wrap_slot(name)
|
13
|
-
define_method(%(add_#{name})) do |*args, **kwargs, &block|
|
14
|
-
slot(name, *args, **kwargs, &block)
|
15
|
-
end
|
16
|
+
def default_classes
|
17
|
+
[]
|
16
18
|
end
|
17
19
|
end
|
@@ -1,17 +1,14 @@
|
|
1
1
|
<%= tag.div(class: classes, **html_attributes) do %>
|
2
2
|
<ol class="govuk-breadcrumbs__list">
|
3
|
-
|
3
|
+
<% @breadcrumbs.each do |text, link| %>
|
4
4
|
|
5
|
-
|
5
|
+
<% if link.present? %>
|
6
6
|
<li class="govuk-breadcrumbs__list-item">
|
7
7
|
<%= link_to(text, link, class: "govuk-breadcrumbs__link") %>
|
8
8
|
</li>
|
9
9
|
<% else %>
|
10
|
-
|
11
|
-
<%= text %>
|
12
|
-
</li>
|
10
|
+
<%= tag.li(text, class: "govuk-breadcrumbs__list-item", aria: { current: "page" }) %>
|
13
11
|
<% end %>
|
14
|
-
|
15
12
|
<% end %>
|
16
13
|
</ol>
|
17
14
|
<% end %>
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class GovukComponent::
|
2
|
-
|
1
|
+
class GovukComponent::BreadcrumbsComponent < GovukComponent::Base
|
2
|
+
attr_reader :breadcrumbs, :hide_in_print, :collapse_on_mobile
|
3
3
|
|
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)
|
@@ -13,8 +13,8 @@ private
|
|
13
13
|
|
14
14
|
def default_classes
|
15
15
|
%w(govuk-breadcrumbs).tap do |classes|
|
16
|
-
classes << "govuk-!-display-none-print" if
|
17
|
-
classes << "govuk-breadcrumbs--collapse-on-mobile" if
|
16
|
+
classes << "govuk-!-display-none-print" if hide_in_print
|
17
|
+
classes << "govuk-breadcrumbs--collapse-on-mobile" if collapse_on_mobile
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/app/components/govuk_component/{cookie_banner.html.erb → cookie_banner_component.html.erb}
RENAMED
@@ -3,14 +3,10 @@
|
|
3
3
|
<div class="govuk-grid-row">
|
4
4
|
<div class="govuk-grid-column-two-thirds">
|
5
5
|
<% if title.present? %>
|
6
|
-
|
7
|
-
<%= title %>
|
8
|
-
</h2>
|
6
|
+
<%= tag.h2(title, class: %w(govuk-cookie-banner__heading govuk-heading-m)) %>
|
9
7
|
<% end %>
|
10
8
|
|
11
|
-
|
12
|
-
<%= body %>
|
13
|
-
</div>
|
9
|
+
<%= tag.div(body, class: "govuk-cookie-banner__content") %>
|
14
10
|
</div>
|
15
11
|
</div>
|
16
12
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class GovukComponent::DetailsComponent < GovukComponent::Base
|
2
|
+
attr_reader :summary_text, :text
|
3
|
+
|
4
|
+
renders_one :summary_html
|
5
|
+
|
6
|
+
def initialize(summary_text:, text: nil, classes: [], html_attributes: {})
|
7
|
+
super(classes: classes, html_attributes: html_attributes)
|
8
|
+
|
9
|
+
@summary_text = summary_text
|
10
|
+
@text = text
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
tag.details(class: classes, data: { module: "govuk-details" }, **html_attributes) do
|
15
|
+
safe_join([summary, description])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def summary
|
22
|
+
tag.summary(class: "govuk-details__summary") do
|
23
|
+
tag.span(summary_content, class: "govuk-details__summary-text")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def summary_content
|
28
|
+
summary_html || summary_text
|
29
|
+
end
|
30
|
+
|
31
|
+
def description
|
32
|
+
tag.div(class: "govuk-details__text") do
|
33
|
+
content.presence || text
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_classes
|
38
|
+
%w(govuk-details)
|
39
|
+
end
|
40
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<div class="govuk-width-container ">
|
3
3
|
<div class="govuk-footer__meta">
|
4
4
|
<% if meta.present? %>
|
5
|
-
<%= meta
|
5
|
+
<%= meta %>
|
6
6
|
<% else %>
|
7
7
|
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
|
8
8
|
<% if meta_items.any? %>
|
@@ -28,13 +28,11 @@
|
|
28
28
|
<% end %>
|
29
29
|
|
30
30
|
<% if meta_content.present? %>
|
31
|
-
<%= meta_content
|
31
|
+
<%= meta_content %>
|
32
32
|
<% end %>
|
33
33
|
</div>
|
34
34
|
<div class="govuk-footer__meta">
|
35
|
-
|
36
|
-
<%= copyright %>
|
37
|
-
</div>
|
35
|
+
<%= tag.div(copyright, class: "govuk-footer__meta-item") %>
|
38
36
|
</div>
|
39
37
|
<% end %>
|
40
38
|
</div>
|
@@ -1,13 +1,8 @@
|
|
1
|
-
class GovukComponent::
|
2
|
-
|
1
|
+
class GovukComponent::FooterComponent < GovukComponent::Base
|
2
|
+
renders_one :meta_content
|
3
|
+
renders_one :meta
|
3
4
|
|
4
|
-
|
5
|
-
wrap_slot :meta_content
|
6
|
-
|
7
|
-
with_slot :meta
|
8
|
-
wrap_slot :meta
|
9
|
-
|
10
|
-
attr_accessor :meta_items, :meta_items_title, :meta_licence, :copyright
|
5
|
+
attr_reader :meta_items, :meta_items_title, :meta_licence, :copyright
|
11
6
|
|
12
7
|
def initialize(meta_items: {}, meta_items_title: "Support links", meta_licence: nil, classes: [], html_attributes: {}, copyright_text: default_copright_text, copyright_url: default_copyright_url)
|
13
8
|
super(classes: classes, html_attributes: html_attributes)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<%= tag.header(class: classes, role: 'banner', data: { module: 'govuk-header' }, **html_attributes) do %>
|
2
|
+
<%= tag.div(class: container_classes) do %>
|
3
|
+
<div class="govuk-header__logo">
|
4
|
+
<%= link_to(homepage_url, class: %w(govuk-header__link govuk-header__link--homepage)) do %>
|
5
|
+
<span class="govuk-header__logotype">
|
6
|
+
<% if custom_logo.present? %>
|
7
|
+
<%= custom_logo %>
|
8
|
+
<% else %>
|
9
|
+
<% if crown %>
|
10
|
+
<svg aria-hidden="true" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 132 97" height="30" width="36">
|
11
|
+
<path fill="currentColor" fill-rule="evenodd" d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-3.6 1.5-7.8-.2-9.2-3.8-1.5-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.3 3.5-.4 7.6-3.9 9.1zM89.3 35.8c-3.6 1.5-7.8-.2-9.2-3.8-1.4-3.6.2-7.7 3.9-9.1 3.6-1.5 7.7.3 9.2 3.8 1.4 3.6-.3 7.7-3.9 9.1zM69.7 17.7l8.9 4.7V9.3l-8.9 2.8c-.2-.3-.5-.6-.9-.9L72.4 0H59.6l3.5 11.2c-.3.3-.6.5-.9.9l-8.8-2.8v13.1l8.8-4.7c.3.3.6.7.9.9l-5 15.4v.1c-.2.8-.4 1.6-.4 2.4 0 4.1 3.1 7.5 7 8.1h.2c.3 0 .7.1 1 .1.4 0 .7 0 1-.1h.2c4-.6 7.1-4.1 7.1-8.1 0-.8-.1-1.7-.4-2.4V34l-5.1-15.4c.4-.2.7-.6 1-.9zM66 92.8c16.9 0 32.8 1.1 47.1 3.2 4-16.9 8.9-26.7 14-33.5l-9.6-3.4c1 4.9 1.1 7.2 0 10.2-1.5-1.4-3-4.3-4.2-8.7L108.6 76c2.8-2 5-3.2 7.5-3.3-4.4 9.4-10 11.9-13.6 11.2-4.3-.8-6.3-4.6-5.6-7.9 1-4.7 5.7-5.9 8-.5 4.3-8.7-3-11.4-7.6-8.8 7.1-7.2 7.9-13.5 2.1-21.1-8 6.1-8.1 12.3-4.5 20.8-4.7-5.4-12.1-2.5-9.5 6.2 3.4-5.2 7.9-2 7.2 3.1-.6 4.3-6.4 7.8-13.5 7.2-10.3-.9-10.9-8-11.2-13.8 2.5-.5 7.1 1.8 11 7.3L80.2 60c-4.1 4.4-8 5.3-12.3 5.4 1.4-4.4 8-11.6 8-11.6H55.5s6.4 7.2 7.9 11.6c-4.2-.1-8-1-12.3-5.4l1.4 16.4c3.9-5.5 8.5-7.7 10.9-7.3-.3 5.8-.9 12.8-11.1 13.8-7.2.6-12.9-2.9-13.5-7.2-.7-5 3.8-8.3 7.1-3.1 2.7-8.7-4.6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"></path>
|
12
|
+
<image src="/assets/images/govuk-logotype-crown.png" xlink:href="" class="govuk-header__logotype-crown-fallback-image" width="36" height="32"></image>
|
13
|
+
</svg>
|
14
|
+
<% end %>
|
15
|
+
<%= tag.span(logotype, class: "govuk-header__logotype-text") %>
|
16
|
+
<% end %>
|
17
|
+
</span>
|
18
|
+
<% if product_name.present? %>
|
19
|
+
<%= product_name %>
|
20
|
+
<% end %>
|
21
|
+
<% end %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<% if service_name.present? || items.present? %>
|
25
|
+
<div class="govuk-header__content">
|
26
|
+
<% if service_name.present? %>
|
27
|
+
<%= link_to(service_name, service_url, class: %w(govuk-header__link govuk-header__link--service-name)) %>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<% if items.any? %>
|
31
|
+
<%= tag.button("Menu", type: "button", class: %w(govuk-header__menu-button govuk-js-header-toggle), aria: { controls: "navigation", label: menu_button_label }) %>
|
32
|
+
<nav>
|
33
|
+
<%= tag.ul(class: navigation_classes, id: "navigation", aria: { label: navigation_label }) do %>
|
34
|
+
<% items.each do |item| %>
|
35
|
+
<%= tag.li(class: item.classes.append(item.active_class), **item.html_attributes) do %>
|
36
|
+
<% if item.link? %>
|
37
|
+
<%= link_to(item.text, item.href, class: "govuk-header__link") %>
|
38
|
+
<% else %>
|
39
|
+
<%= item.text %>
|
40
|
+
<% end %>
|
41
|
+
<% end %>
|
42
|
+
<% end %>
|
43
|
+
<% end %>
|
44
|
+
</nav>
|
45
|
+
<% end %>
|
46
|
+
</div>
|
47
|
+
<% end %>
|
48
|
+
<% end %>
|
49
|
+
<% end %>
|
@@ -0,0 +1,112 @@
|
|
1
|
+
class GovukComponent::HeaderComponent < GovukComponent::Base
|
2
|
+
renders_many :items, "Item"
|
3
|
+
renders_one :custom_logo
|
4
|
+
renders_one :product_name, "ProductName"
|
5
|
+
|
6
|
+
attr_reader :logotype,
|
7
|
+
:crown,
|
8
|
+
:homepage_url,
|
9
|
+
:service_name,
|
10
|
+
:service_url,
|
11
|
+
:menu_button_label,
|
12
|
+
:navigation_label,
|
13
|
+
:custom_navigation_classes,
|
14
|
+
:custom_container_classes
|
15
|
+
|
16
|
+
def initialize(classes: [],
|
17
|
+
html_attributes: {},
|
18
|
+
logotype: 'GOV.UK',
|
19
|
+
crown: true,
|
20
|
+
homepage_url: '/',
|
21
|
+
menu_button_label: 'Show or hide navigation menu',
|
22
|
+
navigation_classes: [],
|
23
|
+
navigation_label: 'Navigation menu',
|
24
|
+
service_name: nil,
|
25
|
+
service_url: '/',
|
26
|
+
container_classes: nil)
|
27
|
+
|
28
|
+
super(classes: classes, html_attributes: html_attributes)
|
29
|
+
|
30
|
+
@logotype = logotype
|
31
|
+
@crown = crown
|
32
|
+
@homepage_url = homepage_url
|
33
|
+
@service_name = service_name
|
34
|
+
@service_url = service_url
|
35
|
+
@menu_button_label = menu_button_label
|
36
|
+
@custom_navigation_classes = navigation_classes
|
37
|
+
@navigation_label = navigation_label
|
38
|
+
@custom_container_classes = container_classes
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def default_classes
|
44
|
+
%w(govuk-header)
|
45
|
+
end
|
46
|
+
|
47
|
+
def navigation_classes
|
48
|
+
combine_classes(%w(govuk-header__navigation), custom_navigation_classes)
|
49
|
+
end
|
50
|
+
|
51
|
+
def container_classes
|
52
|
+
combine_classes(%w(govuk-header__container govuk-width-container), custom_container_classes)
|
53
|
+
end
|
54
|
+
|
55
|
+
class Item < GovukComponent::Base
|
56
|
+
attr_reader :text, :href, :active
|
57
|
+
|
58
|
+
def initialize(text:, href: nil, active: false, classes: [], html_attributes: {})
|
59
|
+
super(classes: classes, html_attributes: html_attributes)
|
60
|
+
|
61
|
+
@text = text
|
62
|
+
@href = href
|
63
|
+
@active = active
|
64
|
+
end
|
65
|
+
|
66
|
+
def active?
|
67
|
+
active
|
68
|
+
end
|
69
|
+
|
70
|
+
def active_class
|
71
|
+
%w(govuk-header__navigation-item--active) if active?
|
72
|
+
end
|
73
|
+
|
74
|
+
def link?
|
75
|
+
href.present?
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def default_classes
|
81
|
+
%w(govuk-header__navigation-item)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class ProductName < GovukComponent::Base
|
86
|
+
attr_reader :name
|
87
|
+
|
88
|
+
def initialize(name: nil, html_attributes: {}, classes: [])
|
89
|
+
super(classes: classes, html_attributes: html_attributes)
|
90
|
+
|
91
|
+
@name = name
|
92
|
+
end
|
93
|
+
|
94
|
+
def render?
|
95
|
+
name.present? || content.present?
|
96
|
+
end
|
97
|
+
|
98
|
+
def call
|
99
|
+
if content.present?
|
100
|
+
tag.div(content, class: classes)
|
101
|
+
else
|
102
|
+
tag.span(name, class: classes)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def default_classes
|
109
|
+
%w(govuk-header__product-name)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|