govuk-components 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bdf0839ecbe0f5046c63a0cca80caa808aa3b0d4f8d5f5280253523742d28d0
4
- data.tar.gz: d4d694316d383bdbfe93f0f1974d0ca14daedbe24e7d48371636b75384ddebaf
3
+ metadata.gz: 6f842d29dfabae4169ed1b2105df65c7f951e53001c3b8850f0f45c1f80f581c
4
+ data.tar.gz: '048b188612f81942b978fac451b4777f8076f6e459275f84b6eab70effa2f9df'
5
5
  SHA512:
6
- metadata.gz: b3aec4489d49df3becca14855f389a4479f82393a6aa231e220f7553202252a8c51a0dab7fd4dfa514e879db12b9c12beacf0db0be0694f412510a81e5c2d486
7
- data.tar.gz: 6429c8416c30dbd25c4afe381f0991f1b505e20faf74e99ad1fe32784345209da388d86ec980dda52c1d1aa3fd3b0f9a2e09d965cadf929e9fb2d6a65ec3c140
6
+ metadata.gz: 52fc5f481b7daf4472a3b25a98d588b4195071063b3c2283e7c6da75ec818ac4561bd41f1e33689d96bf4e98415c8bb7f3f836e4303075ca9af1a9020377ce97
7
+ data.tar.gz: 2c3ad6f877a3466a0407567c0eaa3c181f37ea3b657dd79633ec7b1fde020bf4d9b9aa9212943d190620e26ff80723726f0b50ffb6c6a7c60f7812dbd1c33edb
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 adding a new component update the examples page by cd-ing into the dummy app `cd spec/dummy` and running the rake task `bin/rake generate_examples_page`.
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,7 +3,7 @@
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)) %>
@@ -1,15 +1,20 @@
1
1
  class GovukComponent::Breadcrumbs < GovukComponent::Base
2
2
  attr_accessor :breadcrumbs
3
3
 
4
- def initialize(breadcrumbs:, classes: [], html_attributes: {})
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 = breadcrumbs
8
+ @hide_in_print = hide_in_print
9
+ @collapse_on_mobile = collapse_on_mobile
8
10
  end
9
11
 
10
12
  private
11
13
 
12
14
  def default_classes
13
- %w(govuk-breadcrumbs)
15
+ %w(govuk-breadcrumbs).tap do |classes|
16
+ classes << "govuk-!-display-none-print" if @hide_in_print
17
+ classes << "govuk-breadcrumbs--collapse-on-mobile" if @collapse_on_mobile
18
+ end
14
19
  end
15
20
  end
@@ -1,5 +1,6 @@
1
1
  class GovukComponent::CookieBanner < GovukComponent::Base
2
- with_content_areas :body, :actions
2
+ renders_one :body
3
+ renders_one :actions
3
4
 
4
5
  attr_accessor :title, :aria_label
5
6
 
@@ -5,6 +5,6 @@
5
5
  </span>
6
6
  </summary>
7
7
  <div class="govuk-details__text">
8
- <%= @description || content %>
8
+ <%= content.presence || @description %>
9
9
  </div>
10
10
  <% end %>
@@ -11,6 +11,15 @@
11
11
  <%= @logo %>
12
12
  </span>
13
13
  </span>
14
+ <% if @product_name.present? %>
15
+ <span class="govuk-header__product-name">
16
+ <%= @product_name %>
17
+ </span>
18
+ <% end %>
19
+
20
+ <% if product_description.present? %>
21
+ <%= product_description.content %>
22
+ <% end %>
14
23
  </a>
15
24
  </div>
16
25
  <div class="govuk-header__content">
@@ -21,16 +30,19 @@
21
30
  <% end %>
22
31
 
23
32
  <% if items.any? %>
33
+ <button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="<%= menu_button_label %>">Menu</button>
24
34
  <nav>
25
- <ul class="govuk-header__navigation " aria-label="Top Level Navigation">
35
+ <%= tag.ul(class: navigation_classes, id: "navigation", aria: { label: navigation_label }) do %>
26
36
  <% items.each do |item| %>
27
37
  <%= tag.li(class: item.classes.append(item.active_class), **item.html_attributes) do %>
28
- <a class="govuk-header__link" href="<%= item.href %>">
38
+ <% if item.link? %>
39
+ <%= link_to(item.title, item.href, class: "govuk-header__link") %>
40
+ <% else %>
29
41
  <%= item.title %>
30
- </a>
42
+ <% end %>
31
43
  <% end %>
32
44
  <% end %>
33
- </ul>
45
+ <% end %>
34
46
  </nav>
35
47
  <% end %>
36
48
  </div>
@@ -1,18 +1,25 @@
1
1
  class GovukComponent::Header < GovukComponent::Base
2
2
  include ViewComponent::Slotable
3
3
 
4
- attr_accessor :logo, :logo_href, :service_name, :service_name_href
4
+ attr_accessor :logo, :logo_href, :service_name, :service_name_href, :product_name, :menu_button_label, :navigation_label
5
5
 
6
6
  with_slot :item, collection: true, class_name: 'Item'
7
7
  wrap_slot :item
8
8
 
9
- def initialize(logo: 'GOV.UK', logo_href: '/', service_name: nil, service_name_href: '/', classes: [], html_attributes: {})
9
+ with_slot :product_description
10
+ wrap_slot :product_description
11
+
12
+ def initialize(logo: 'GOV.UK', logo_href: '/', service_name: nil, service_name_href: '/', product_name: nil, menu_button_label: 'Show or hide navigation menu', classes: [], navigation_classes: [], navigation_label: 'Navigation menu', html_attributes: {})
10
13
  super(classes: classes, html_attributes: html_attributes)
11
14
 
12
- @logo = logo
13
- @logo_href = logo_href
14
- @service_name = service_name
15
- @service_name_href = service_name_href
15
+ @logo = logo
16
+ @logo_href = logo_href
17
+ @service_name = service_name
18
+ @service_name_href = service_name_href
19
+ @product_name = product_name
20
+ @menu_button_label = menu_button_label
21
+ @navigation_classes = navigation_classes
22
+ @navigation_label = navigation_label
16
23
  end
17
24
 
18
25
  private
@@ -21,10 +28,16 @@ private
21
28
  %w(govuk-header)
22
29
  end
23
30
 
31
+ def navigation_classes
32
+ %w(govuk-header__navigation).tap { |nc|
33
+ nc.concat(@navigation_classes.is_a?(String) ? @navigation_classes.split : @navigation_classes)
34
+ }.uniq
35
+ end
36
+
24
37
  class Item < GovukComponent::Slot
25
38
  attr_accessor :title, :href, :active
26
39
 
27
- def initialize(title:, href:, active: false, classes: [], html_attributes: {})
40
+ def initialize(title:, href: nil, active: false, classes: [], html_attributes: {})
28
41
  super(classes: classes, html_attributes: html_attributes)
29
42
 
30
43
  self.title = title
@@ -40,6 +53,10 @@ private
40
53
  %w(govuk-header__navigation-item--active) if active?
41
54
  end
42
55
 
56
+ def link?
57
+ href.present?
58
+ end
59
+
43
60
  private
44
61
 
45
62
  def default_classes
@@ -1,14 +1,18 @@
1
1
  class GovukComponent::InsetText < GovukComponent::Base
2
2
  attr_accessor :text
3
3
 
4
- def initialize(text:, classes: [], html_attributes: {})
4
+ def initialize(text: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
7
  @text = text
8
8
  end
9
9
 
10
10
  def call
11
- tag.div(class: classes, **html_attributes) { @text }
11
+ tag.div(class: classes, **html_attributes) { content.presence || @text }
12
+ end
13
+
14
+ def render?
15
+ @text.present? || content.present?
12
16
  end
13
17
 
14
18
  private
@@ -1,9 +1,13 @@
1
1
  <%= tag.div(class: classes, **html_attributes) do %>
2
- <h1 class="govuk-panel__title">
3
- <%= @title %>
4
- </h1>
2
+ <% if display_title? %>
3
+ <h1 class="govuk-panel__title">
4
+ <%= @title %>
5
+ </h1>
6
+ <% end %>
5
7
 
6
- <div class="govuk-panel__body">
7
- <%= @body %>
8
- </div>
8
+ <% if display_body? %>
9
+ <div class="govuk-panel__body">
10
+ <%= content.presence || @body %>
11
+ </div>
12
+ <% end %>
9
13
  <% end %>
@@ -1,7 +1,7 @@
1
1
  class GovukComponent::Panel < GovukComponent::Base
2
2
  attr_accessor :title, :body
3
3
 
4
- def initialize(title:, body:, classes: [], html_attributes: {})
4
+ def initialize(title: nil, body: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
7
  @title = title
@@ -13,4 +13,16 @@ private
13
13
  def default_classes
14
14
  %w(govuk-panel govuk-panel--confirmation)
15
15
  end
16
+
17
+ def display_title?
18
+ @title.present?
19
+ end
20
+
21
+ def display_body?
22
+ [@body, content].any?(&:present?)
23
+ end
24
+
25
+ def render?
26
+ display_title? || display_body?
27
+ end
16
28
  end
@@ -1,10 +1,8 @@
1
1
  <%= tag.div(class: classes, **html_attributes) do %>
2
2
  <p class="govuk-phase-banner__content">
3
- <strong class="govuk-tag govuk-phase-banner__content__tag">
4
- <%= @phase %>
5
- </strong>
3
+ <%= render(phase_tag) %>
6
4
  <span class="govuk-phase-banner__text">
7
- <%= @text || content %>
5
+ <%= content.presence || @text %>
8
6
  </span>
9
7
  </p>
10
8
  <% end %>
@@ -1,11 +1,11 @@
1
1
  class GovukComponent::PhaseBanner < GovukComponent::Base
2
- attr_accessor :phase, :text
2
+ attr_accessor :phase_tag, :text
3
3
 
4
- def initialize(phase:, text: nil, classes: [], html_attributes: {})
4
+ def initialize(phase_tag: nil, text: nil, classes: [], html_attributes: {})
5
5
  super(classes: classes, html_attributes: html_attributes)
6
6
 
7
- @phase = phase
8
- @text = text
7
+ @phase_tag = GovukComponent::Tag.new(classes: "govuk-phase-banner__content__tag", **phase_tag)
8
+ @text = text
9
9
  end
10
10
 
11
11
  private
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '1.1.5'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
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-03-25 00:00:00.000000000 Z
11
+ date: 2021-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties