govuk-components 4.0.0 → 4.1.1

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -22
  3. data/app/components/govuk_component/accordion_component/section_component.html.erb +5 -5
  4. data/app/components/govuk_component/accordion_component/section_component.rb +1 -1
  5. data/app/components/govuk_component/accordion_component.rb +1 -1
  6. data/app/components/govuk_component/back_link_component.rb +9 -3
  7. data/app/components/govuk_component/base.rb +4 -0
  8. data/app/components/govuk_component/breadcrumbs_component.html.erb +1 -1
  9. data/app/components/govuk_component/breadcrumbs_component.rb +9 -6
  10. data/app/components/govuk_component/cookie_banner_component/message_component.rb +7 -7
  11. data/app/components/govuk_component/cookie_banner_component.rb +1 -1
  12. data/app/components/govuk_component/details_component.rb +5 -5
  13. data/app/components/govuk_component/exit_this_page_component.rb +56 -0
  14. data/app/components/govuk_component/footer_component.html.erb +11 -11
  15. data/app/components/govuk_component/footer_component.rb +7 -7
  16. data/app/components/govuk_component/header_component.html.erb +10 -10
  17. data/app/components/govuk_component/header_component.rb +8 -8
  18. data/app/components/govuk_component/inset_text_component.rb +1 -1
  19. data/app/components/govuk_component/notification_banner_component.html.erb +3 -3
  20. data/app/components/govuk_component/notification_banner_component.rb +5 -5
  21. data/app/components/govuk_component/pagination_component/adjacent_page.rb +6 -6
  22. data/app/components/govuk_component/pagination_component/item.rb +4 -4
  23. data/app/components/govuk_component/pagination_component/next_page.rb +1 -1
  24. data/app/components/govuk_component/pagination_component/previous_page.rb +1 -1
  25. data/app/components/govuk_component/pagination_component.rb +4 -4
  26. data/app/components/govuk_component/panel_component.rb +3 -3
  27. data/app/components/govuk_component/phase_banner_component.html.erb +2 -2
  28. data/app/components/govuk_component/phase_banner_component.rb +2 -2
  29. data/app/components/govuk_component/section_break_component.rb +3 -3
  30. data/app/components/govuk_component/start_button_component.rb +8 -10
  31. data/app/components/govuk_component/summary_list_component/action_component.rb +1 -1
  32. data/app/components/govuk_component/summary_list_component/card_component.html.erb +5 -5
  33. data/app/components/govuk_component/summary_list_component/card_component.rb +1 -1
  34. data/app/components/govuk_component/summary_list_component/key_component.rb +1 -1
  35. data/app/components/govuk_component/summary_list_component/row_component.rb +5 -5
  36. data/app/components/govuk_component/summary_list_component/value_component.rb +1 -1
  37. data/app/components/govuk_component/summary_list_component.rb +2 -2
  38. data/app/components/govuk_component/tab_component.html.erb +2 -2
  39. data/app/components/govuk_component/tab_component.rb +5 -5
  40. data/app/components/govuk_component/table_component/body_component.rb +1 -1
  41. data/app/components/govuk_component/table_component/caption_component.rb +2 -2
  42. data/app/components/govuk_component/table_component/cell_component.rb +12 -10
  43. data/app/components/govuk_component/table_component/foot_component.rb +1 -1
  44. data/app/components/govuk_component/table_component/head_component.rb +1 -1
  45. data/app/components/govuk_component/table_component/row_component.rb +1 -1
  46. data/app/components/govuk_component/table_component.rb +1 -1
  47. data/app/components/govuk_component/tag_component.rb +2 -2
  48. data/app/components/govuk_component/warning_text_component.rb +4 -4
  49. data/app/helpers/govuk_back_to_top_link_helper.rb +7 -1
  50. data/app/helpers/govuk_components_helper.rb +1 -0
  51. data/app/helpers/govuk_exit_this_page_link_helper.rb +23 -0
  52. data/app/helpers/govuk_link_helper.rb +38 -26
  53. data/app/helpers/govuk_skip_link_helper.rb +2 -2
  54. data/app/helpers/title_with_error_prefix_helper.rb +7 -0
  55. data/lib/govuk/components/engine.rb +16 -2
  56. data/lib/govuk/components/version.rb +1 -1
  57. metadata +21 -12
@@ -3,34 +3,20 @@ require "html_attributes_utils"
3
3
  module GovukLinkHelper
4
4
  using HTMLAttributesUtils
5
5
 
6
- LINK_STYLES = {
7
- inverse: "govuk-link--inverse",
8
- muted: "govuk-link--muted",
9
- no_underline: "govuk-link--no-underline",
10
- no_visited_state: "govuk-link--no-visited-state",
11
- text_colour: "govuk-link--text-colour",
12
- }.freeze
13
-
14
- BUTTON_STYLES = {
15
- disabled: "govuk-button--disabled",
16
- secondary: "govuk-button--secondary",
17
- warning: "govuk-button--warning",
18
- }.freeze
19
-
20
- def govuk_link_classes(*styles, default_class: 'govuk-link')
21
- if (invalid_styles = (styles - LINK_STYLES.keys)) && invalid_styles.any?
22
- fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{LINK_STYLES.keys.to_sentence}")
6
+ def govuk_link_classes(*styles, default_class: "#{brand}-link")
7
+ if (invalid_styles = (styles - link_styles.keys)) && invalid_styles.any?
8
+ fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{link_styles.keys.to_sentence}")
23
9
  end
24
10
 
25
- [default_class] + LINK_STYLES.values_at(*styles).compact
11
+ [default_class] + link_styles.values_at(*styles).compact
26
12
  end
27
13
 
28
- def govuk_button_classes(*styles, default_class: 'govuk-button')
29
- if (invalid_styles = (styles - BUTTON_STYLES.keys)) && invalid_styles.any?
30
- fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{BUTTON_STYLES.keys.to_sentence}")
14
+ def govuk_button_classes(*styles, default_class: "#{brand}-button")
15
+ if (invalid_styles = (styles - button_styles.keys)) && invalid_styles.any?
16
+ fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{button_styles.keys.to_sentence}")
31
17
  end
32
18
 
33
- [default_class] + BUTTON_STYLES.values_at(*styles).compact
19
+ [default_class] + button_styles.values_at(*styles).compact
34
20
  end
35
21
 
36
22
  def govuk_link_to(name = nil, options = nil, extra_options = {}, &block)
@@ -68,8 +54,11 @@ module GovukLinkHelper
68
54
 
69
55
  def govuk_button_link_to(name = nil, options = nil, extra_options = {}, &block)
70
56
  extra_options = options if block_given?
71
- html_options = GovukComponent::StartButtonComponent::LINK_ATTRIBUTES
72
- .merge build_html_options(extra_options, style: :button)
57
+ html_options = {
58
+ data: { module: "#{brand}-button" },
59
+ draggable: 'false',
60
+ role: 'button',
61
+ }.merge build_html_options(extra_options, style: :button)
73
62
 
74
63
  if block_given?
75
64
  link_to(name, html_options, &block)
@@ -91,8 +80,31 @@ module GovukLinkHelper
91
80
 
92
81
  private
93
82
 
83
+ def brand
84
+ Govuk::Components.brand
85
+ end
86
+
87
+ def link_styles
88
+ {
89
+ inverse: "#{brand}-link--inverse",
90
+ muted: "#{brand}-link--muted",
91
+ no_underline: "#{brand}-link--no-underline",
92
+ no_visited_state: "#{brand}-link--no-visited-state",
93
+ text_colour: "#{brand}-link--text-colour",
94
+ }
95
+ end
96
+
97
+ def button_styles
98
+ {
99
+ disabled: "#{brand}-button--disabled",
100
+ secondary: "#{brand}-button--secondary",
101
+ warning: "#{brand}-button--warning",
102
+ inverse: "#{brand}-button--inverse",
103
+ }
104
+ end
105
+
94
106
  def build_html_options(provided_options, style: :link)
95
- element_styles = { link: LINK_STYLES, button: BUTTON_STYLES }.fetch(style, {})
107
+ element_styles = { link: link_styles, button: button_styles }.fetch(style, {})
96
108
 
97
109
  # we need to take a couple of extra steps here because we don't want the style
98
110
  # params (inverse, muted, etc) to end up as extra attributes on the link.
@@ -110,7 +122,7 @@ private
110
122
  case style
111
123
  when :link then govuk_link_classes(*keys)
112
124
  when :button then govuk_button_classes(*keys)
113
- when :breadcrumb then %w(govuk-breadcrumbs__link)
125
+ when :breadcrumb then "#{brand}-breadcrumbs__link"
114
126
  end
115
127
  end
116
128
 
@@ -1,8 +1,8 @@
1
1
  module GovukSkipLinkHelper
2
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')
3
+ link_classes = Array.wrap(classes).append("#{brand}-skip-link")
4
4
 
5
- html_attributes_with_data_module = { data: { module: "govuk-skip-link" } }.deep_merge(html_attributes)
5
+ html_attributes_with_data_module = { data: { module: "#{brand}-skip-link" } }.deep_merge(html_attributes)
6
6
 
7
7
  return link_to(href, class: link_classes, **html_attributes_with_data_module, &block) if block_given?
8
8
 
@@ -0,0 +1,7 @@
1
+ module TitleWithErrorPrefixHelper
2
+ def title_with_error_prefix(title, error:, error_prefix: Govuk::Components.config.default_error_prefix)
3
+ "#{error_prefix if error}#{title}"
4
+ end
5
+ end
6
+
7
+ ActiveSupport.on_load(:action_view) { include TitleWithErrorPrefixHelper }
@@ -32,11 +32,19 @@ module Govuk
32
32
  #
33
33
  # Default components configuration
34
34
  #
35
+ # +:brand+ sets the value used to prefix all classes, used to allow the components to be branded for alternative (similar) design systems
35
36
  # +:default_back_link_text+ Default text for the back link, defaults to +Back+
36
37
  # +:default_breadcrumbs_collapse_on_mobile+ false
37
38
  # +:default_breadcrumbs_hide_in_print+ false
38
39
  # +:default_cookie_banner_aria_label+ "Cookie banner"
39
40
  # +:default_cookie_banner_hide_in_print+ true
41
+ # +:default_error_prefix+ Text to use at the start of the page title tag when there is an error on the page. Default is 'Error: '
42
+ # +:default_exit_this_page_redirect_url+ The URL that the exit this page component links to by default. Defaults to https://www.bbc.co.uk/weather
43
+ # +:default_exit_this_page_text+ The default text that forms the link. Defaults to 'Exit this page'
44
+ # +:default_exit_this_page_activated_text+ Text announced by screen readers when Exit this Page has been activated via the keyboard shortcut. Default in govuk-frontend is 'Exiting page.' Defaults to nil so govuk-frontend value is used unless overridden.
45
+ # +:default_exit_this_page_timed_out_text+ Text announced by screen readers when the keyboard shortcut has timed out without successful activation. Default in govuk-frontend is 'Exit this page expired.' Defaults to nil so govuk-frontend value is used unless overridden.
46
+ # +:default_exit_this_page_press_two_more_times_text+ Text announced by screen readers when the user must press *Shift* two more times to activate the button. Default in govuk-frontend is 'Shift, press 2 more times to exit.' Defaults to nil so govuk-frontend value is used unless overridden.
47
+ # +:default_exit_this_page_press_one_more_time_text+ Text announced by screen readers when the user must press *Shift* one more time to activate the button. Default in govuk-frontend is 'Shift, press 1 more time to exit.' Defaults to nil so govuk-frontend value is used unless overridden.
40
48
  # +:default_header_navigation_label+ 'Navigation menu'
41
49
  # +:default_header_menu_button_label+ 'Show or hide navigation menu'
42
50
  # +:default_header_logotype+ 'GOV.UK'
@@ -66,11 +74,19 @@ module Govuk
66
74
  # +: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
75
  # +:enable_auto_table_scopes+ automatically adds a scope of 'col' to th elements in thead and 'row' to th elements in tbody.
68
76
  DEFAULTS = {
77
+ brand: 'govuk',
69
78
  default_back_link_text: 'Back',
70
79
  default_breadcrumbs_collapse_on_mobile: false,
71
80
  default_breadcrumbs_hide_in_print: false,
72
81
  default_cookie_banner_aria_label: "Cookie banner",
73
82
  default_cookie_banner_hide_in_print: true,
83
+ default_error_prefix: "Error: ",
84
+ default_exit_this_page_redirect_url: "https://www.bbc.co.uk/weather",
85
+ default_exit_this_page_text: "Exit this page",
86
+ default_exit_this_page_activated_text: nil,
87
+ default_exit_this_page_timed_out_text: nil,
88
+ default_exit_this_page_press_two_more_times_text: nil,
89
+ default_exit_this_page_press_one_more_time_text: nil,
74
90
  default_header_navigation_label: 'Navigation menu',
75
91
  default_header_menu_button_label: 'Show or hide navigation menu',
76
92
  default_header_logotype: 'GOV.UK',
@@ -96,9 +112,7 @@ module Govuk
96
112
  default_notification_title_success: false,
97
113
  default_warning_text_icon_fallback_text: "Warning",
98
114
  default_warning_text_icon: "!",
99
-
100
115
  default_link_new_tab_text: "(opens in new tab)",
101
-
102
116
  require_summary_list_action_visually_hidden_text: false,
103
117
  enable_auto_table_scopes: true,
104
118
  }.freeze
@@ -1,5 +1,5 @@
1
1
  module Govuk
2
2
  module Components
3
- VERSION = '4.0.0'.freeze
3
+ VERSION = '4.1.1'.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: 4.0.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DfE developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-26 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-attributes-utils
@@ -48,16 +48,22 @@ dependencies:
48
48
  name: view_component
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '3.3'
54
+ - - "<"
52
55
  - !ruby/object:Gem::Version
53
- version: 3.0.0
56
+ version: '3.6'
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
- - - "~>"
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '3.3'
64
+ - - "<"
59
65
  - !ruby/object:Gem::Version
60
- version: 3.0.0
66
+ version: '3.6'
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: deep_merge
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -120,14 +126,14 @@ dependencies:
120
126
  requirements:
121
127
  - - '='
122
128
  - !ruby/object:Gem::Version
123
- version: 4.9.0
129
+ version: 4.12.0
124
130
  type: :development
125
131
  prerelease: false
126
132
  version_requirements: !ruby/object:Gem::Requirement
127
133
  requirements:
128
134
  - - '='
129
135
  - !ruby/object:Gem::Version
130
- version: 4.9.0
136
+ version: 4.12.0
131
137
  - !ruby/object:Gem::Dependency
132
138
  name: sassc-rails
133
139
  requirement: !ruby/object:Gem::Requirement
@@ -310,8 +316,8 @@ dependencies:
310
316
  - - "~>"
311
317
  - !ruby/object:Gem::Version
312
318
  version: 1.8.1
313
- description: A collection of components intended to ease the building of GOV.UK Design
314
- System web applications
319
+ description: This library provides view components for the GOV.UK Design System. It
320
+ makes creating services more familiar for Ruby on Rails developers.
315
321
  email:
316
322
  - peter.yates@digital.education.gov.uk
317
323
  executables: []
@@ -332,6 +338,7 @@ files:
332
338
  - app/components/govuk_component/cookie_banner_component.rb
333
339
  - app/components/govuk_component/cookie_banner_component/message_component.rb
334
340
  - app/components/govuk_component/details_component.rb
341
+ - app/components/govuk_component/exit_this_page_component.rb
335
342
  - app/components/govuk_component/footer_component.html.erb
336
343
  - app/components/govuk_component/footer_component.rb
337
344
  - app/components/govuk_component/header_component.html.erb
@@ -372,15 +379,17 @@ files:
372
379
  - app/components/govuk_component/warning_text_component.rb
373
380
  - app/helpers/govuk_back_to_top_link_helper.rb
374
381
  - app/helpers/govuk_components_helper.rb
382
+ - app/helpers/govuk_exit_this_page_link_helper.rb
375
383
  - app/helpers/govuk_link_helper.rb
376
384
  - app/helpers/govuk_skip_link_helper.rb
385
+ - app/helpers/title_with_error_prefix_helper.rb
377
386
  - config/routes.rb
378
387
  - lib/govuk/components.rb
379
388
  - lib/govuk/components/engine.rb
380
389
  - lib/govuk/components/helpers/css_utilities.rb
381
390
  - lib/govuk/components/version.rb
382
391
  - lib/tasks/govuk/components_tasks.rake
383
- homepage: https://github.com/DFE-Digital/govuk-components
392
+ homepage: https://github.com/x-govuk/govuk-components
384
393
  licenses:
385
394
  - MIT
386
395
  metadata: {}
@@ -402,5 +411,5 @@ requirements: []
402
411
  rubygems_version: 3.2.33
403
412
  signing_key:
404
413
  specification_version: 4
405
- summary: Lightweight set of reusable GOV.UK Design System components
414
+ summary: GOV.UK Components for Ruby on Rails
406
415
  test_files: []