govuk-components 3.1.4 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -2
  3. data/app/components/govuk_component/back_link_component.rb +1 -1
  4. data/app/components/govuk_component/base.rb +2 -0
  5. data/app/components/govuk_component/breadcrumbs_component.rb +6 -1
  6. data/app/components/govuk_component/cookie_banner_component.rb +7 -1
  7. data/app/components/govuk_component/footer_component.rb +3 -11
  8. data/app/components/govuk_component/header_component.html.erb +1 -1
  9. data/app/components/govuk_component/header_component.rb +6 -6
  10. data/app/components/govuk_component/notification_banner_component.rb +11 -1
  11. data/app/components/govuk_component/pagination_component/adjacent_page.rb +2 -3
  12. data/app/components/govuk_component/pagination_component/next_page.rb +1 -6
  13. data/app/components/govuk_component/pagination_component/previous_page.rb +1 -6
  14. data/app/components/govuk_component/pagination_component.rb +19 -16
  15. data/app/components/govuk_component/phase_banner_component.rb +6 -1
  16. data/app/components/govuk_component/section_break_component.rb +6 -1
  17. data/app/components/govuk_component/start_button_component.rb +1 -1
  18. data/app/components/govuk_component/summary_list_component/action_component.rb +7 -1
  19. data/app/components/govuk_component/summary_list_component.rb +1 -1
  20. data/app/components/govuk_component/tag_component.rb +1 -1
  21. data/app/components/govuk_component/warning_text_component.rb +6 -7
  22. data/app/helpers/govuk_link_helper.rb +1 -5
  23. data/lib/govuk/components/engine.rb +99 -0
  24. data/lib/govuk/components/version.rb +1 -1
  25. metadata +6 -7
  26. data/MIT-LICENSE +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3840e40ffafa0fc239e251a1fd9f76c2bf6b290d0ea2f6df6a0dfd7300dd5f7
4
- data.tar.gz: e0bbfa5d779cf3a40edce2b7282beb355738643098f50bb6a24dcb5c182a3548
3
+ metadata.gz: 82c6c791cb04272f6d9c26584648e77df868106c405b03e8ab45de1d887e982c
4
+ data.tar.gz: 97a343854b2584929d0bbe0e184773463cfc208c6d100d6719650fe117839607
5
5
  SHA512:
6
- metadata.gz: bdf53c97e701ab06061022e6058e70a5bc8566cd5b6fb563c51c53c364d2d70281f2aea9883bafc8f7c510be4e3fbe478580cd3dd6496e00f774c7b9f5e4b044
7
- data.tar.gz: 7b85bbcdd1f5f05fe12a1bacdd6a56e488428174976f1b92db1eb9cfb17e9487f3c569e14532c91e6f5611e94afff18251984200c8406345dd463f296f1421e9
6
+ metadata.gz: fab4a1347e860c70cfa70314c634c550e776fce5a3b661877c0daaba84fa1da8678c56a58dbae572299ac6ddf279ee8277ae29509edc46933bb47c4dc94e7173
7
+ data.tar.gz: 678e902ca916bc9ad00944d555e8678b3897071f2b1f50e3eeb99585f5f412e3d91d22a7909c882b336ec98be4beadfd2ed488485fd472996c8b5552901782ab
data/README.md CHANGED
@@ -6,14 +6,23 @@
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.2.0-brightgreen)](https://design-system.service.gov.uk)
9
+ [![GOV.UK Design System Version](https://img.shields.io/badge/GOV.UK%20Design%20System-4.3.0-brightgreen)](https://design-system.service.gov.uk)
10
10
  [![Rails](https://img.shields.io/badge/Rails-6.1.5%20%E2%95%B1%207.0.3-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
- [![Ruby](https://img.shields.io/badge/Ruby-2.7.5%20%20%E2%95%B1%203.0.3%20%20%E2%95%B1%203.1.2-E16D6D)](https://www.ruby-lang.org/en/downloads/)
11
+ [![Ruby](https://img.shields.io/badge/Ruby-2.7.6%20%20%E2%95%B1%203.0.3%20%20%E2%95%B1%203.1.2-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
 
15
15
  It aims to implement the functionality from the original Nunjucks macros in a way that will feel more familiar to Rails developers. Blocks are preferred over strings of HTML, beneath the surface each component is just a Ruby object, everything is inheritable and overrideable.
16
16
 
17
+ ## Documentation
18
+
19
+ The gem comes with [a full guide](https://govuk-components.netlify.app/) that
20
+ covers most aspects of day-to-day use, along with code and output examples. The
21
+ examples in the guide (and the guide itself) are built using the components,
22
+ so it will always be up to date.
23
+
24
+ [![Netlify Status](https://api.netlify.com/api/v1/badges/d40a5a0a-b086-4c35-b046-97fbcbf9f219/deploy-status)](https://app.netlify.com/sites/govuk-components/deploys)
25
+
17
26
  ## What’s included?
18
27
 
19
28
  All of the non-form components from the GOV.UK Design System are implemented by this library as ViewComponents. Form components are implemented by the [GOV.UK Form Builder](https://govuk-form-builder.netlify.app/).
@@ -1,7 +1,7 @@
1
1
  class GovukComponent::BackLinkComponent < GovukComponent::Base
2
2
  attr_reader :text, :href
3
3
 
4
- def initialize(href:, text: 'Back', classes: [], html_attributes: {})
4
+ def initialize(href:, text: config.default_back_link_text, classes: [], html_attributes: {})
5
5
  @text = text
6
6
  @href = href
7
7
 
@@ -3,6 +3,8 @@ class GovukComponent::Base < ViewComponent::Base
3
3
 
4
4
  attr_reader :html_attributes
5
5
 
6
+ delegate :config, to: Govuk::Components
7
+
6
8
  def initialize(classes:, html_attributes:)
7
9
  if classes.nil?
8
10
  Rails.logger.warn("classes is nil, if no custom classes are needed omit the param")
@@ -1,7 +1,12 @@
1
1
  class GovukComponent::BreadcrumbsComponent < GovukComponent::Base
2
2
  attr_reader :breadcrumbs, :hide_in_print, :collapse_on_mobile
3
3
 
4
- def initialize(breadcrumbs:, hide_in_print: false, collapse_on_mobile: false, classes: [], html_attributes: {})
4
+ def initialize(breadcrumbs:,
5
+ hide_in_print: config.default_breadcrumbs_hide_in_print,
6
+ collapse_on_mobile: config.default_breadcrumbs_collapse_on_mobile,
7
+ classes: [],
8
+ html_attributes: {})
9
+
5
10
  @breadcrumbs = build_list(breadcrumbs)
6
11
  @hide_in_print = hide_in_print
7
12
  @collapse_on_mobile = collapse_on_mobile
@@ -4,7 +4,13 @@ module GovukComponent
4
4
 
5
5
  attr_accessor :aria_label, :hidden, :hide_in_print
6
6
 
7
- def initialize(aria_label: "Cookie banner", hidden: false, hide_in_print: true, classes: [], html_attributes: {})
7
+ def initialize(
8
+ aria_label: config.default_cookie_banner_aria_label,
9
+ hidden: false,
10
+ hide_in_print: config.default_cookie_banner_hide_in_print,
11
+ classes: [],
12
+ html_attributes: {}
13
+ )
8
14
  @aria_label = aria_label
9
15
  @hidden = hidden
10
16
  @hide_in_print = hide_in_print
@@ -11,13 +11,13 @@ class GovukComponent::FooterComponent < GovukComponent::Base
11
11
  classes: [],
12
12
  container_classes: [],
13
13
  container_html_attributes: {},
14
- copyright_text: default_copright_text,
15
- copyright_url: default_copyright_url,
14
+ copyright_text: config.default_footer_copyright_text,
15
+ copyright_url: config.default_footer_copyright_url,
16
16
  html_attributes: {},
17
17
  meta_items: {},
18
18
  meta_items_title: "Support links",
19
19
  meta_licence: nil,
20
- meta_text: nil,
20
+ meta_text: config.default_footer_component_meta_text,
21
21
  meta_classes: [],
22
22
  meta_html_attributes: {}
23
23
  )
@@ -84,12 +84,4 @@ private
84
84
  def build_copyright(text, url)
85
85
  link_to(text, url, class: %w(govuk-footer__link govuk-footer__copyright-logo))
86
86
  end
87
-
88
- def default_copright_text
89
- raw(%(© Crown copyright))
90
- end
91
-
92
- def default_copyright_url
93
- "https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/"
94
- end
95
87
  end
@@ -37,7 +37,7 @@
37
37
 
38
38
  <% if navigation_items.any? %>
39
39
  <%= tag.nav(**navigation_html_attributes) do %>
40
- <%= tag.button("Menu", type: "button", class: %w(govuk-header__menu-button govuk-js-header-toggle), aria: { controls: "navigation", label: menu_button_label }) %>
40
+ <%= tag.button("Menu", type: "button", class: %w(govuk-header__menu-button govuk-js-header-toggle), hidden: true, aria: { controls: "navigation", label: menu_button_label }) %>
41
41
  <ul id="navigation" class="govuk-header__navigation-list">
42
42
  <% navigation_items.each do |item| %>
43
43
  <%= item %>
@@ -16,15 +16,15 @@ class GovukComponent::HeaderComponent < GovukComponent::Base
16
16
 
17
17
  def initialize(classes: [],
18
18
  html_attributes: {},
19
- logotype: 'GOV.UK',
19
+ logotype: config.default_header_logotype,
20
20
  crown: true,
21
21
  crown_fallback_image_path: nil,
22
- homepage_url: '/',
23
- menu_button_label: 'Show or hide navigation menu',
22
+ homepage_url: config.default_header_homepage_url,
23
+ menu_button_label: config.default_header_menu_button_label,
24
24
  navigation_classes: [],
25
- navigation_label: 'Navigation menu',
26
- service_name: nil,
27
- service_url: '/',
25
+ navigation_label: config.default_header_navigation_label,
26
+ service_name: config.default_header_service_name,
27
+ service_url: config.default_header_service_url,
28
28
  container_classes: nil)
29
29
 
30
30
  @logotype = logotype
@@ -4,7 +4,17 @@ class GovukComponent::NotificationBannerComponent < GovukComponent::Base
4
4
  renders_one :title_html
5
5
  renders_many :headings, "Heading"
6
6
 
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
+ def initialize(
8
+ title_text: nil,
9
+ text: nil,
10
+ role: nil,
11
+ success: config.default_notification_title_success,
12
+ title_heading_level: config.default_notification_title_heading_level,
13
+ title_id: config.default_notification_banner_title_id,
14
+ disable_auto_focus: config.default_notification_disable_auto_focus,
15
+ classes: [],
16
+ html_attributes: {}
17
+ )
8
18
  @title_text = title_text
9
19
  @title_id = title_id
10
20
  @text = text
@@ -2,20 +2,19 @@ class GovukComponent::PaginationComponent::AdjacentPage < GovukComponent::Base
2
2
  attr_reader :href, :label_text, :text, :suffix, :block_mode, :visually_hidden_text
3
3
  alias_method :block_mode?, :block_mode
4
4
 
5
- def initialize(href:, suffix:, visually_hidden_text:, text:, block_mode: true, label_text: nil, classes: [], html_attributes: {})
5
+ def initialize(href:, suffix:, text:, block_mode: true, label_text: nil, classes: [], html_attributes: {})
6
6
  @href = href
7
7
  @label_text = label_text
8
8
  @text = text
9
9
  @block_mode = block_mode
10
10
  @suffix = suffix
11
- @visually_hidden_text = visually_hidden_text
12
11
 
13
12
  super(html_attributes: html_attributes, classes: classes)
14
13
  end
15
14
 
16
15
  def call
17
16
  tag.div(**html_attributes) do
18
- tag.a(href: href, class: %w(govuk-link govuk-pagination__link), rel: suffix, aria: { label: aria_label }) do
17
+ tag.a(href: href, class: %w(govuk-link govuk-pagination__link), rel: suffix) do
19
18
  safe_join([body, divider, label_content])
20
19
  end
21
20
  end
@@ -1,12 +1,11 @@
1
1
  class GovukComponent::PaginationComponent::NextPage < GovukComponent::PaginationComponent::AdjacentPage
2
- def initialize(href:, text:, label_text: nil, visually_hidden_text: nil, block_mode: true, classes: [], html_attributes: {})
2
+ def initialize(href:, text:, label_text: nil, block_mode: true, classes: [], html_attributes: {})
3
3
  super(
4
4
  suffix: "next",
5
5
  text: text,
6
6
  href: href,
7
7
  label_text: label_text,
8
8
  block_mode: block_mode,
9
- visually_hidden_text: visually_hidden_text,
10
9
  classes: classes,
11
10
  html_attributes: html_attributes
12
11
  )
@@ -20,10 +19,6 @@ class GovukComponent::PaginationComponent::NextPage < GovukComponent::Pagination
20
19
 
21
20
  private
22
21
 
23
- def aria_label
24
- @visually_hidden_text || "Next page"
25
- end
26
-
27
22
  def arrow
28
23
  tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--next", xmlns: "http://www.w3.org/2000/svg", height: "13", width: "15", focusable: "false", viewBox: "0 0 15 13", aria: { hidden: "true" }) do
29
24
  tag.path(d: "m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z")
@@ -1,12 +1,11 @@
1
1
  class GovukComponent::PaginationComponent::PreviousPage < GovukComponent::PaginationComponent::AdjacentPage
2
- def initialize(href:, text:, label_text: nil, visually_hidden_text: nil, block_mode: true, classes: [], html_attributes: {})
2
+ def initialize(href:, text:, label_text: nil, block_mode: true, classes: [], html_attributes: {})
3
3
  super(
4
4
  suffix: "prev",
5
5
  text: text,
6
6
  href: href,
7
7
  label_text: label_text,
8
8
  block_mode: block_mode,
9
- visually_hidden_text: visually_hidden_text,
10
9
  classes: classes,
11
10
  html_attributes: html_attributes
12
11
  )
@@ -14,10 +13,6 @@ class GovukComponent::PaginationComponent::PreviousPage < GovukComponent::Pagina
14
13
 
15
14
  private
16
15
 
17
- def aria_label
18
- @visually_hidden_text || "Previous page"
19
- end
20
-
21
16
  def arrow
22
17
  tag.svg(class: "govuk-pagination__icon govuk-pagination__icon--prev", xmlns: "http://www.w3.org/2000/svg", height: "13", width: "15", focusable: "false", viewBox: "0 0 15 13", aria: { hidden: "true" }) do
23
18
  tag.path(d: "m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z")
@@ -4,8 +4,6 @@ class GovukComponent::PaginationComponent < GovukComponent::Base
4
4
  attr_reader :pagy,
5
5
  :next_text,
6
6
  :previous_text,
7
- :visually_hidden_next_text,
8
- :visually_hidden_previous_text,
9
7
  :page_items,
10
8
  :previous_content,
11
9
  :next_content,
@@ -16,36 +14,38 @@ class GovukComponent::PaginationComponent < GovukComponent::Base
16
14
 
17
15
  renders_many :items, "GovukComponent::PaginationComponent::Item"
18
16
 
19
- renders_one :next_page, ->(href:, text: default_next_text, label_text: nil, visually_hidden_text: nil, classes: [], html_attributes: {}) do
17
+ renders_one :next_page, ->(href:, text: default_adjacent_text(:next), label_text: nil, classes: [], html_attributes: {}) do
20
18
  GovukComponent::PaginationComponent::NextPage.new(
21
19
  text: text,
22
20
  href: href,
23
21
  label_text: label_text,
24
22
  block_mode: block_mode?,
25
- visually_hidden_text: visually_hidden_text,
26
23
  classes: classes,
27
24
  html_attributes: html_attributes
28
25
  )
29
26
  end
30
27
 
31
- renders_one :previous_page, ->(href:, text: default_previous_text, label_text: nil, visually_hidden_text: nil, classes: [], html_attributes: {}) do
28
+ renders_one :previous_page, ->(href:, text: default_adjacent_text(:prev), label_text: nil, classes: [], html_attributes: {}) do
32
29
  GovukComponent::PaginationComponent::PreviousPage.new(
33
30
  text: text,
34
31
  href: href,
35
32
  label_text: label_text,
36
33
  block_mode: block_mode?,
37
- visually_hidden_text: visually_hidden_text,
38
34
  classes: classes,
39
35
  html_attributes: html_attributes
40
36
  )
41
37
  end
42
38
 
43
- def initialize(pagy: nil, next_text: nil, previous_text: nil, visually_hidden_next_text: nil, visually_hidden_previous_text: nil, block_mode: false, landmark_label: "results", classes: [], html_attributes: {})
39
+ def initialize(pagy: nil,
40
+ next_text: nil,
41
+ previous_text: nil,
42
+ block_mode: false,
43
+ landmark_label: config.default_pagination_landmark_label,
44
+ classes: [],
45
+ html_attributes: {})
44
46
  @pagy = pagy
45
47
  @next_text = next_text
46
48
  @previous_text = previous_text
47
- @visually_hidden_next_text = visually_hidden_next_text
48
- @visually_hidden_previous_text = visually_hidden_previous_text
49
49
  @block_mode = block_mode
50
50
  @landmark_label = landmark_label
51
51
 
@@ -94,7 +94,6 @@ private
94
94
  kwargs = {
95
95
  href: pagy_url_for(pagy, pagy.prev),
96
96
  text: @previous_text,
97
- visually_hidden_text: visually_hidden_previous_text,
98
97
  }
99
98
 
100
99
  previous_page(**kwargs.compact)
@@ -106,7 +105,6 @@ private
106
105
  kwargs = {
107
106
  href: pagy_url_for(pagy, pagy.next),
108
107
  text: @next_text,
109
- visually_hidden_text: visually_hidden_next_text,
110
108
  }
111
109
 
112
110
  next_page(**kwargs.compact)
@@ -116,11 +114,16 @@ private
116
114
  pagy.series.map { |i| item(number: i, href: pagy_url_for(pagy, i), from_pagy: true) }
117
115
  end
118
116
 
119
- def default_next_text
120
- safe_join(["Next", tag.span(class: "govuk-visually-hidden") { " page" }])
121
- end
117
+ def default_adjacent_text(side)
118
+ visible, hidden = *case side
119
+ when :next
120
+ config.default_pagination_next_text
121
+ when :prev
122
+ config.default_pagination_previous_text
123
+ end
124
+
125
+ return visible if hidden.blank?
122
126
 
123
- def default_previous_text
124
- safe_join(["Previous", tag.span(class: "govuk-visually-hidden") { " page" }])
127
+ (visible + tag.span(" #{hidden}", class: "govuk-visually-hidden")).html_safe
125
128
  end
126
129
  end
@@ -1,7 +1,12 @@
1
1
  class GovukComponent::PhaseBannerComponent < GovukComponent::Base
2
2
  attr_reader :text, :phase_tag
3
3
 
4
- def initialize(tag: nil, text: nil, classes: [], html_attributes: {})
4
+ def initialize(
5
+ tag: { text: config.default_phase_banner_tag },
6
+ text: config.default_phase_banner_text,
7
+ classes: [],
8
+ html_attributes: {}
9
+ )
5
10
  @phase_tag = tag
6
11
  @text = text
7
12
 
@@ -1,7 +1,12 @@
1
1
  class GovukComponent::SectionBreakComponent < GovukComponent::Base
2
2
  SIZES = %w(m l xl).freeze
3
3
 
4
- def initialize(visible: false, size: nil, classes: [], html_attributes: {})
4
+ def initialize(
5
+ visible: config.default_section_break_visible,
6
+ size: config.default_section_break_size,
7
+ classes: [],
8
+ html_attributes: {}
9
+ )
5
10
  @visible = visible
6
11
  @size = size
7
12
 
@@ -8,7 +8,7 @@ class GovukComponent::StartButtonComponent < GovukComponent::Base
8
8
 
9
9
  attr_reader :text, :href, :as_button
10
10
 
11
- def initialize(text:, href:, as_button: false, classes: [], html_attributes: {})
11
+ def initialize(text:, href:, as_button: config.default_start_button_as_button, classes: [], html_attributes: {})
12
12
  @text = text
13
13
  @href = href
14
14
  @as_button = as_button
@@ -1,7 +1,13 @@
1
1
  class GovukComponent::SummaryListComponent::ActionComponent < GovukComponent::Base
2
+ class VisuallyHiddenDefaultNilClass < NilClass; end
3
+
2
4
  attr_reader :href, :text, :visually_hidden_text, :attributes, :classes
3
5
 
4
- def initialize(href: nil, text: 'Change', visually_hidden_text: nil, classes: [], html_attributes: {})
6
+ def initialize(href: nil, text: 'Change', visually_hidden_text: VisuallyHiddenDefaultNilClass, classes: [], html_attributes: {})
7
+ if config.require_summary_list_action_visually_hidden_text && visually_hidden_text == VisuallyHiddenDefaultNilClass
8
+ fail(ArgumentError, "missing keyword: visually_hidden_text")
9
+ end
10
+
5
11
  super(classes: classes, html_attributes: html_attributes)
6
12
 
7
13
  @href = href
@@ -11,7 +11,7 @@ module GovukComponent
11
11
  )
12
12
  end
13
13
 
14
- def initialize(rows: nil, actions: true, borders: true, classes: [], html_attributes: {})
14
+ def initialize(rows: nil, actions: true, borders: config.default_summary_list_borders, classes: [], html_attributes: {})
15
15
  @borders = borders
16
16
  @show_actions_column = actions
17
17
 
@@ -3,7 +3,7 @@ class GovukComponent::TagComponent < GovukComponent::Base
3
3
 
4
4
  COLOURS = %w(grey green turquoise blue red purple pink orange yellow).freeze
5
5
 
6
- def initialize(text: nil, colour: nil, classes: [], html_attributes: {})
6
+ def initialize(text: nil, colour: config.default_tag_colour, classes: [], html_attributes: {})
7
7
  @text = text
8
8
  @colour = colour
9
9
 
@@ -1,10 +1,9 @@
1
1
  class GovukComponent::WarningTextComponent < GovukComponent::Base
2
- attr_reader :text, :icon_fallback_text
2
+ attr_reader :text, :icon, :icon_fallback_text
3
3
 
4
- ICON = '!'.freeze
5
-
6
- def initialize(text: nil, icon_fallback_text: 'Warning', classes: [], html_attributes: {})
4
+ def initialize(text: nil, icon_fallback_text: config.default_warning_text_icon_fallback_text, icon: config.default_warning_text_icon, classes: [], html_attributes: {})
7
5
  @text = text
6
+ @icon = icon
8
7
  @icon_fallback_text = icon_fallback_text
9
8
 
10
9
  super(classes: classes, html_attributes: html_attributes)
@@ -12,14 +11,14 @@ class GovukComponent::WarningTextComponent < GovukComponent::Base
12
11
 
13
12
  def call
14
13
  tag.div(**html_attributes) do
15
- safe_join([icon, warning_text])
14
+ safe_join([icon_element, warning_text])
16
15
  end
17
16
  end
18
17
 
19
18
  private
20
19
 
21
- def icon
22
- tag.span(ICON, class: 'govuk-warning-text__icon', aria: { hidden: true })
20
+ def icon_element
21
+ tag.span(icon, class: 'govuk-warning-text__icon', aria: { hidden: true })
23
22
  end
24
23
 
25
24
  def warning_text
@@ -56,11 +56,7 @@ module GovukLinkHelper
56
56
  html_options = build_html_options(extra_options, style: :button)
57
57
 
58
58
  if block_given?
59
- if Rails.version >= "7.0.0" && name.is_a?(Hash)
60
- button_to(name.merge(html_options), &block)
61
- else
62
- button_to(name, html_options, &block)
63
- end
59
+ button_to(options, html_options, &block)
64
60
  else
65
61
  button_to(name, options, html_options)
66
62
  end
@@ -1,7 +1,106 @@
1
1
  require "rails/engine"
2
+ require "active_support/configurable"
2
3
 
3
4
  module Govuk
4
5
  module Components
6
+ include ActiveSupport::Configurable
7
+
8
+ class << self
9
+ # Configure the form builder in the usual manner. All of the
10
+ # keys in {DEFAULTS} can be configured as per the example below
11
+ #
12
+ # @example
13
+ # Govuk::Components.configure do |conf|
14
+ # conf.do_some_things = 'yes'
15
+ # end
16
+ def configure
17
+ yield(config)
18
+ end
19
+
20
+ # Resets each of the configurable values to its default
21
+ #
22
+ # @note This method is only really intended for use to clean up
23
+ # during testing
24
+ def reset!
25
+ configure do |c|
26
+ DEFAULTS.each { |k, v| c.send("#{k}=", v) }
27
+ end
28
+ end
29
+ end
30
+
31
+ # @!group Defaults
32
+ #
33
+ # Default components configuration
34
+ #
35
+ # +:default_back_link_text+ Default text for the back link, defaults to +Back+
36
+ # +:default_breadcrumbs_collapse_on_mobile+ false
37
+ # +:default_breadcrumbs_hide_in_print+ false
38
+ # +:default_cookie_banner_aria_label+ "Cookie banner"
39
+ # +:default_cookie_banner_hide_in_print+ true
40
+ # +:default_header_navigation_label+ 'Navigation menu'
41
+ # +:default_header_menu_button_label+ 'Show or hide navigation menu'
42
+ # +:default_header_logotype+ 'GOV.UK'
43
+ # +:default_header_homepage_url+ '/'
44
+ # +:default_header_service_name+ nil
45
+ # +:default_header_service_url+ '/'
46
+ # +:default_footer_meta_text+ nil
47
+ # +:default_footer_copyright_text+ '© Crown copyright'
48
+ # +:default_footer_copyright_url+ "https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/"
49
+ # +:default_pagination_landmark_label+ "results"
50
+ # +:default_pagination_next_text+ Default 'next' text for pagination. An +Array+ where the first item is visible and the second visually hidden. Defaults to ["Next", "page"]
51
+ # +:default_pagination_previous_text+ Default 'previous' text for pagination. An +Array+ where the first item is visible and the second visually hidden. Defaults to ["Previous", "page"]
52
+ # +:default_phase_banner_tag+ nil
53
+ # +:default_phase_banner_text+ nil
54
+ # +:default_section_break_visible+ false
55
+ # +:default_section_break_size+ Size of the section break, possible values: +m+, +l+ and +xl+. Defaults to nil.
56
+ # +:default_tag_colour+ the default colour for tags, possible values: +grey+, +green+, +turquoise+, +blue+, +red+, +purple+, +pink+, +orange+, +yellow+. Defaults to +nil+
57
+ # +:default_start_button_as_button+ false
58
+ # +:default_summary_list_borders+ true
59
+ # +:default_notification_banner_title_id+ "govuk-notification-banner-title"
60
+ # +:default_notification_disable_auto_focus+ nil
61
+ # +:default_notification_title_heading_level+ 2
62
+ # +:default_notification_title_success+ false
63
+ # +:default_warning_text_icon_fallback_text+ "Warning"
64
+ # +:default_warning_text_icon+ "!"
65
+ #
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
+ DEFAULTS = {
68
+ default_back_link_text: 'Back',
69
+ default_breadcrumbs_collapse_on_mobile: false,
70
+ default_breadcrumbs_hide_in_print: false,
71
+ default_cookie_banner_aria_label: "Cookie banner",
72
+ default_cookie_banner_hide_in_print: true,
73
+ default_header_navigation_label: 'Navigation menu',
74
+ default_header_menu_button_label: 'Show or hide navigation menu',
75
+ default_header_logotype: 'GOV.UK',
76
+ default_header_homepage_url: '/',
77
+ default_header_service_name: nil,
78
+ default_header_service_url: '/',
79
+ default_footer_meta_text: nil,
80
+ default_footer_copyright_text: '© Crown copyright',
81
+ default_footer_copyright_url: "https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/",
82
+ default_pagination_landmark_label: "results",
83
+ default_pagination_next_text: %w(Next page),
84
+ default_pagination_previous_text: %w(Previous page),
85
+ default_phase_banner_tag: nil,
86
+ default_phase_banner_text: nil,
87
+ default_section_break_visible: false,
88
+ default_section_break_size: nil,
89
+ default_tag_colour: nil,
90
+ default_start_button_as_button: false,
91
+ default_summary_list_borders: true,
92
+ default_notification_banner_title_id: "govuk-notification-banner-title",
93
+ default_notification_disable_auto_focus: nil,
94
+ default_notification_title_heading_level: 2,
95
+ default_notification_title_success: false,
96
+ default_warning_text_icon_fallback_text: "Warning",
97
+ default_warning_text_icon: "!",
98
+
99
+ require_summary_list_action_visually_hidden_text: false,
100
+ }.freeze
101
+
102
+ DEFAULTS.each_key { |k| config_accessor(k) { DEFAULTS[k] } }
103
+
5
104
  class Engine < ::Rails::Engine
6
105
  isolate_namespace Govuk::Components
7
106
  end
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '3.1.4'.freeze
3
+ VERSION = '3.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: 3.1.4
4
+ version: 3.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: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: 2.56.2
95
+ version: 2.69.0
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 2.56.2
102
+ version: 2.69.0
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: deep_merge
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -260,14 +260,14 @@ dependencies:
260
260
  requirements:
261
261
  - - "~>"
262
262
  - !ruby/object:Gem::Version
263
- version: 3.29.0
263
+ version: 3.30.0
264
264
  type: :development
265
265
  prerelease: false
266
266
  version_requirements: !ruby/object:Gem::Requirement
267
267
  requirements:
268
268
  - - "~>"
269
269
  - !ruby/object:Gem::Version
270
- version: 3.29.0
270
+ version: 3.30.0
271
271
  - !ruby/object:Gem::Dependency
272
272
  name: rubypants
273
273
  requirement: !ruby/object:Gem::Requirement
@@ -360,7 +360,6 @@ executables: []
360
360
  extensions: []
361
361
  extra_rdoc_files: []
362
362
  files:
363
- - MIT-LICENSE
364
363
  - README.md
365
364
  - Rakefile
366
365
  - app/components/govuk_component.rb
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2020 Peter Yates
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.