ccs-frontend_helpers 1.1.1 → 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: 39678d85e8ca928ae039bd25c162926a0a2e866831cd5006f7fa103d1d3ea960
4
- data.tar.gz: 8ec80df69bb1914c45084361b113fdf33806573ac47990e91655e8572b40291f
3
+ metadata.gz: 38560818156ac958cffb99cba75120dafce3be490c1536fdf83c92c532d66328
4
+ data.tar.gz: 2be3dc70f1282f56ce36ce5bb5092abf9a399bd29c8a582a24611caab9a6cbef
5
5
  SHA512:
6
- metadata.gz: d2f70aba7a5c5fa31a15687ce473c3388bda0866e4f103cb0bd47d443a61f9524625fa5db962354930070ac52578a1b47d566068813f4f086422adc9f77f8acf
7
- data.tar.gz: 1d5686a08d3e4f09a95467963328f5ded5b8ed58377d970e8478adf5588db06df9e5d00581d440f95b6dd1f6dfe9f88e8791fe47c78a71792acd5d939dbbe12c
6
+ metadata.gz: bcedbbe479c7981653a8aad6fe8944cb1f51b5e6aed4f1bee1f9ca5d9a54b42bdc897aaa3016096235d6e3a0ff9a63d810bf6a0de91433e7a743142ee8ab67e8
7
+ data.tar.gz: dbbf68e53152b494b4e252b09c3ab019349d6c840199f5253bc84db021aee2fe8fcde8c747014eb61db332cef5a4d87f5d951d9f1c88da998eed2e1939d6bacf
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.1
1
+ 3.3.4
data/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.0] - 2024-09-02
11
+
12
+ ### Added
13
+
14
+ - Update to CCS Frontend v1.1.3
15
+ - Update to GOV.UK Frontend v5.6.0
16
+ - The following GOV.UK helpers have been added:
17
+ - Service navigation
18
+
19
+ ## [1.1.1] - 2024-08-12
20
+
21
+ ### Added
22
+
23
+ - Update to CCS Frontend v1.1.2
24
+ - Update to GOV.UK Frontend v5.5.0
25
+
10
26
  ## [1.1.1] - 2024-06-28
11
27
 
12
28
  ### Added
data/Gemfile CHANGED
@@ -16,9 +16,9 @@ gem 'simplecov', '~> 0.21'
16
16
  gem 'nokogiri-diff', '~> 0.3.0'
17
17
 
18
18
  # Gems for linting/formatting the package
19
- gem 'rubocop', '~> 1.65'
19
+ gem 'rubocop', '~> 1.66'
20
20
  gem 'rubocop-capybara', '~> 2.20'
21
- gem 'rubocop-rails', '~> 2.25'
21
+ gem 'rubocop-rails', '~> 2.26'
22
22
  gem 'rubocop-rake', '~> 0.6'
23
23
  gem 'rubocop-rspec', '~> 3.0'
24
24
 
data/Gemfile.lock CHANGED
@@ -1,41 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ccs-frontend_helpers (1.1.1)
4
+ ccs-frontend_helpers (1.2.0)
5
5
  rails (>= 6.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (7.1.3.4)
11
- actionpack (= 7.1.3.4)
12
- activesupport (= 7.1.3.4)
10
+ actioncable (7.1.4)
11
+ actionpack (= 7.1.4)
12
+ activesupport (= 7.1.4)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
15
  zeitwerk (~> 2.6)
16
- actionmailbox (7.1.3.4)
17
- actionpack (= 7.1.3.4)
18
- activejob (= 7.1.3.4)
19
- activerecord (= 7.1.3.4)
20
- activestorage (= 7.1.3.4)
21
- activesupport (= 7.1.3.4)
16
+ actionmailbox (7.1.4)
17
+ actionpack (= 7.1.4)
18
+ activejob (= 7.1.4)
19
+ activerecord (= 7.1.4)
20
+ activestorage (= 7.1.4)
21
+ activesupport (= 7.1.4)
22
22
  mail (>= 2.7.1)
23
23
  net-imap
24
24
  net-pop
25
25
  net-smtp
26
- actionmailer (7.1.3.4)
27
- actionpack (= 7.1.3.4)
28
- actionview (= 7.1.3.4)
29
- activejob (= 7.1.3.4)
30
- activesupport (= 7.1.3.4)
26
+ actionmailer (7.1.4)
27
+ actionpack (= 7.1.4)
28
+ actionview (= 7.1.4)
29
+ activejob (= 7.1.4)
30
+ activesupport (= 7.1.4)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  net-imap
33
33
  net-pop
34
34
  net-smtp
35
35
  rails-dom-testing (~> 2.2)
36
- actionpack (7.1.3.4)
37
- actionview (= 7.1.3.4)
38
- activesupport (= 7.1.3.4)
36
+ actionpack (7.1.4)
37
+ actionview (= 7.1.4)
38
+ activesupport (= 7.1.4)
39
39
  nokogiri (>= 1.8.5)
40
40
  racc
41
41
  rack (>= 2.2.4)
@@ -43,35 +43,35 @@ GEM
43
43
  rack-test (>= 0.6.3)
44
44
  rails-dom-testing (~> 2.2)
45
45
  rails-html-sanitizer (~> 1.6)
46
- actiontext (7.1.3.4)
47
- actionpack (= 7.1.3.4)
48
- activerecord (= 7.1.3.4)
49
- activestorage (= 7.1.3.4)
50
- activesupport (= 7.1.3.4)
46
+ actiontext (7.1.4)
47
+ actionpack (= 7.1.4)
48
+ activerecord (= 7.1.4)
49
+ activestorage (= 7.1.4)
50
+ activesupport (= 7.1.4)
51
51
  globalid (>= 0.6.0)
52
52
  nokogiri (>= 1.8.5)
53
- actionview (7.1.3.4)
54
- activesupport (= 7.1.3.4)
53
+ actionview (7.1.4)
54
+ activesupport (= 7.1.4)
55
55
  builder (~> 3.1)
56
56
  erubi (~> 1.11)
57
57
  rails-dom-testing (~> 2.2)
58
58
  rails-html-sanitizer (~> 1.6)
59
- activejob (7.1.3.4)
60
- activesupport (= 7.1.3.4)
59
+ activejob (7.1.4)
60
+ activesupport (= 7.1.4)
61
61
  globalid (>= 0.3.6)
62
- activemodel (7.1.3.4)
63
- activesupport (= 7.1.3.4)
64
- activerecord (7.1.3.4)
65
- activemodel (= 7.1.3.4)
66
- activesupport (= 7.1.3.4)
62
+ activemodel (7.1.4)
63
+ activesupport (= 7.1.4)
64
+ activerecord (7.1.4)
65
+ activemodel (= 7.1.4)
66
+ activesupport (= 7.1.4)
67
67
  timeout (>= 0.4.0)
68
- activestorage (7.1.3.4)
69
- actionpack (= 7.1.3.4)
70
- activejob (= 7.1.3.4)
71
- activerecord (= 7.1.3.4)
72
- activesupport (= 7.1.3.4)
68
+ activestorage (7.1.4)
69
+ actionpack (= 7.1.4)
70
+ activejob (= 7.1.4)
71
+ activerecord (= 7.1.4)
72
+ activesupport (= 7.1.4)
73
73
  marcel (~> 1.0)
74
- activesupport (7.1.3.4)
74
+ activesupport (7.1.4)
75
75
  base64
76
76
  bigdecimal
77
77
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -96,20 +96,20 @@ GEM
96
96
  rack-test (>= 0.6.3)
97
97
  regexp_parser (>= 1.5, < 3.0)
98
98
  xpath (~> 3.2)
99
- concurrent-ruby (1.3.3)
99
+ concurrent-ruby (1.3.4)
100
100
  connection_pool (2.4.1)
101
101
  crass (1.0.6)
102
102
  date (3.3.4)
103
103
  diff-lcs (1.5.1)
104
104
  docile (1.4.0)
105
105
  drb (2.2.1)
106
- erubi (1.12.0)
106
+ erubi (1.13.0)
107
107
  globalid (1.2.1)
108
108
  activesupport (>= 6.1)
109
109
  i18n (1.14.5)
110
110
  concurrent-ruby (~> 1.0)
111
111
  io-console (0.7.2)
112
- irb (1.13.1)
112
+ irb (1.14.0)
113
113
  rdoc (>= 4.0.0)
114
114
  reline (>= 0.4.2)
115
115
  json (2.7.2)
@@ -125,9 +125,9 @@ GEM
125
125
  marcel (1.0.4)
126
126
  matrix (0.4.2)
127
127
  mini_mime (1.1.5)
128
- minitest (5.24.1)
128
+ minitest (5.25.1)
129
129
  mutex_m (0.2.0)
130
- net-imap (0.4.12)
130
+ net-imap (0.4.15)
131
131
  date
132
132
  net-protocol
133
133
  net-pop (0.1.2)
@@ -137,22 +137,22 @@ GEM
137
137
  net-smtp (0.5.0)
138
138
  net-protocol
139
139
  nio4r (2.7.3)
140
- nokogiri (1.16.5-x86_64-darwin)
140
+ nokogiri (1.16.7-x86_64-darwin)
141
141
  racc (~> 1.4)
142
- nokogiri (1.16.5-x86_64-linux)
142
+ nokogiri (1.16.7-x86_64-linux)
143
143
  racc (~> 1.4)
144
144
  nokogiri-diff (0.3.0)
145
145
  nokogiri (~> 1.5)
146
146
  tdiff (~> 0.4)
147
- parallel (1.25.1)
148
- parser (3.3.4.0)
147
+ parallel (1.26.3)
148
+ parser (3.3.4.2)
149
149
  ast (~> 2.4.1)
150
150
  racc
151
151
  psych (5.1.2)
152
152
  stringio
153
153
  public_suffix (5.0.4)
154
- racc (1.8.0)
155
- rack (3.1.4)
154
+ racc (1.8.1)
155
+ rack (3.1.7)
156
156
  rack-session (2.0.0)
157
157
  rack (>= 3.0.0)
158
158
  rack-test (2.1.0)
@@ -160,20 +160,20 @@ GEM
160
160
  rackup (2.1.0)
161
161
  rack (>= 3)
162
162
  webrick (~> 1.8)
163
- rails (7.1.3.4)
164
- actioncable (= 7.1.3.4)
165
- actionmailbox (= 7.1.3.4)
166
- actionmailer (= 7.1.3.4)
167
- actionpack (= 7.1.3.4)
168
- actiontext (= 7.1.3.4)
169
- actionview (= 7.1.3.4)
170
- activejob (= 7.1.3.4)
171
- activemodel (= 7.1.3.4)
172
- activerecord (= 7.1.3.4)
173
- activestorage (= 7.1.3.4)
174
- activesupport (= 7.1.3.4)
163
+ rails (7.1.4)
164
+ actioncable (= 7.1.4)
165
+ actionmailbox (= 7.1.4)
166
+ actionmailer (= 7.1.4)
167
+ actionpack (= 7.1.4)
168
+ actiontext (= 7.1.4)
169
+ actionview (= 7.1.4)
170
+ activejob (= 7.1.4)
171
+ activemodel (= 7.1.4)
172
+ activerecord (= 7.1.4)
173
+ activestorage (= 7.1.4)
174
+ activesupport (= 7.1.4)
175
175
  bundler (>= 1.15.0)
176
- railties (= 7.1.3.4)
176
+ railties (= 7.1.4)
177
177
  rails-dom-testing (2.2.0)
178
178
  activesupport (>= 5.0.0)
179
179
  minitest
@@ -181,9 +181,9 @@ GEM
181
181
  rails-html-sanitizer (1.6.0)
182
182
  loofah (~> 2.21)
183
183
  nokogiri (~> 1.14)
184
- railties (7.1.3.4)
185
- actionpack (= 7.1.3.4)
186
- activesupport (= 7.1.3.4)
184
+ railties (7.1.4)
185
+ actionpack (= 7.1.4)
186
+ activesupport (= 7.1.4)
187
187
  irb
188
188
  rackup (>= 1.0.0)
189
189
  rake (>= 12.2)
@@ -194,10 +194,8 @@ GEM
194
194
  rdoc (6.7.0)
195
195
  psych (>= 4.0.0)
196
196
  regexp_parser (2.9.2)
197
- reline (0.5.8)
197
+ reline (0.5.9)
198
198
  io-console (~> 0.5)
199
- rexml (3.3.1)
200
- strscan
201
199
  rspec (3.13.0)
202
200
  rspec-core (~> 3.13.0)
203
201
  rspec-expectations (~> 3.13.0)
@@ -211,29 +209,28 @@ GEM
211
209
  diff-lcs (>= 1.2.0, < 2.0)
212
210
  rspec-support (~> 3.13.0)
213
211
  rspec-support (3.13.1)
214
- rubocop (1.65.0)
212
+ rubocop (1.66.0)
215
213
  json (~> 2.3)
216
214
  language_server-protocol (>= 3.17.0)
217
215
  parallel (~> 1.10)
218
216
  parser (>= 3.3.0.2)
219
217
  rainbow (>= 2.2.2, < 4.0)
220
218
  regexp_parser (>= 2.4, < 3.0)
221
- rexml (>= 3.2.5, < 4.0)
222
- rubocop-ast (>= 1.31.1, < 2.0)
219
+ rubocop-ast (>= 1.32.1, < 2.0)
223
220
  ruby-progressbar (~> 1.7)
224
221
  unicode-display_width (>= 2.4.0, < 3.0)
225
- rubocop-ast (1.31.3)
222
+ rubocop-ast (1.32.1)
226
223
  parser (>= 3.3.1.0)
227
224
  rubocop-capybara (2.21.0)
228
225
  rubocop (~> 1.41)
229
- rubocop-rails (2.25.1)
226
+ rubocop-rails (2.26.0)
230
227
  activesupport (>= 4.2.0)
231
228
  rack (>= 1.1)
232
- rubocop (>= 1.33.0, < 2.0)
229
+ rubocop (>= 1.52.0, < 2.0)
233
230
  rubocop-ast (>= 1.31.1, < 2.0)
234
231
  rubocop-rake (0.6.0)
235
232
  rubocop (~> 1.0)
236
- rubocop-rspec (3.0.3)
233
+ rubocop-rspec (3.0.4)
237
234
  rubocop (~> 1.61)
238
235
  ruby-progressbar (1.13.0)
239
236
  simplecov (0.22.0)
@@ -242,10 +239,9 @@ GEM
242
239
  simplecov_json_formatter (~> 0.1)
243
240
  simplecov-html (0.12.3)
244
241
  simplecov_json_formatter (0.1.4)
245
- stringio (3.1.0)
246
- strscan (3.1.0)
242
+ stringio (3.1.1)
247
243
  tdiff (0.4.0)
248
- thor (1.3.1)
244
+ thor (1.3.2)
249
245
  timeout (0.4.1)
250
246
  tzinfo (2.0.6)
251
247
  concurrent-ruby (~> 1.0)
@@ -257,7 +253,7 @@ GEM
257
253
  xpath (3.2.0)
258
254
  nokogiri (~> 1.8)
259
255
  yard (0.9.36)
260
- zeitwerk (2.6.15)
256
+ zeitwerk (2.6.18)
261
257
 
262
258
  PLATFORMS
263
259
  x86_64-darwin-19
@@ -272,9 +268,9 @@ DEPENDENCIES
272
268
  nokogiri-diff (~> 0.3.0)
273
269
  rake (~> 13.2)
274
270
  rspec (~> 3.13)
275
- rubocop (~> 1.65)
271
+ rubocop (~> 1.66)
276
272
  rubocop-capybara (~> 2.20)
277
- rubocop-rails (~> 2.25)
273
+ rubocop-rails (~> 2.26)
278
274
  rubocop-rake (~> 0.6)
279
275
  rubocop-rspec (~> 3.0)
280
276
  simplecov (~> 0.21)
data/README.md CHANGED
@@ -14,6 +14,8 @@ The following table shows the version of CCS Frontend Helpers that you should us
14
14
 
15
15
  | CCS Frontend Helpers Version | Target GOV.UK Frontend Version | Target CCS Frontend Version |
16
16
  | ----------------------------- | ------------------------------ | --------------------------- |
17
+ | [1.2.0](https://github.com/Crown-Commercial-Service/ccs-frontend_helpers/releases/tag/v1.2.0) | [5.6.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.6.0) | [1.1.3](https://github.com/Crown-Commercial-Service/ccs-frontend-project/releases/tag/v1.1.3) |
18
+ | [1.1.2](https://github.com/Crown-Commercial-Service/ccs-frontend_helpers/releases/tag/v1.1.2) | [5.5.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.5.0) | [1.1.2](https://github.com/Crown-Commercial-Service/ccs-frontend-project/releases/tag/v1.1.2) |
17
19
  | [1.1.1](https://github.com/Crown-Commercial-Service/ccs-frontend_helpers/releases/tag/v1.1.1) | [5.4.1](https://github.com/alphagov/govuk-frontend/releases/tag/v5.4.1) | [1.1.1](https://github.com/Crown-Commercial-Service/ccs-frontend-project/releases/tag/v1.1.1) |
18
20
  | [1.1.0](https://github.com/Crown-Commercial-Service/ccs-frontend_helpers/releases/tag/v1.1.0) | [5.4.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.4.0) | [1.1.0](https://github.com/Crown-Commercial-Service/ccs-frontend-project/releases/tag/v1.1.0) |
19
21
  | [1.0.0](https://github.com/Crown-Commercial-Service/ccs-frontend_helpers/releases/tag/v1.0.0) | [5.4.0](https://github.com/alphagov/govuk-frontend/releases/tag/v5.4.0) | [1.0.0](https://github.com/Crown-Commercial-Service/ccs-frontend-project/releases/tag/v1.0.0) |
@@ -0,0 +1,74 @@
1
+ require_relative '../../base'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class ServiceNavigation < Base
7
+ # = GOV.UK Service navigation link
8
+ #
9
+ # The individual service navigation link item
10
+ #
11
+ # @!attribute [r] text
12
+ # @return [String] Text for the service navigation link
13
+ # @!attribute [r] href
14
+ # @return [String] The href for the service navigation link
15
+
16
+ class Link < Base
17
+ private
18
+
19
+ attr_reader :text, :href
20
+
21
+ public
22
+
23
+ # @param text [String] the text for the service navigation link
24
+ # @param href [String] the href for the service navigation link
25
+ # @param options [Hash] options that will be used in customising the HTML
26
+ #
27
+ # @option options [Boolean] :active flag to mark the navigation item as active or not
28
+ # @option options [Hash] :attributes any additional attributes that will added as part of the HTML
29
+
30
+ def initialize(text:, href: nil, **options)
31
+ super(**options)
32
+
33
+ @options[:attributes][:aria] = { current: options[:current] ? 'page' : 'true' } if options[:active] || options[:current]
34
+
35
+ @text = text
36
+ @href = href
37
+ end
38
+
39
+ # Generates the HTML for the GOV.UK Service navigation link
40
+ #
41
+ # @return [ActiveSupport::SafeBuffer]
42
+
43
+ def render
44
+ tag.li(class: "govuk-service-navigation__item #{'govuk-service-navigation__item--active' if options[:active] || options[:current]}".rstrip) do
45
+ if href
46
+ options[:attributes][:class] = 'govuk-service-navigation__link'
47
+
48
+ link_to(inner_content, href, **options[:attributes])
49
+ else
50
+ options[:attributes][:class] = 'govuk-service-navigation__text'
51
+
52
+ tag.span(inner_content, **options[:attributes])
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ # Generates the HTML for the inner content of the GOV.UK Service navigation link component
60
+ #
61
+ # @return [ActiveSupport::SafeBuffer]
62
+
63
+ def inner_content
64
+ if options[:active] || options[:current]
65
+ tag.strong(text, class: 'govuk-service-navigation__active-fallback')
66
+ else
67
+ text
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,81 @@
1
+ require_relative 'link'
2
+
3
+ module CCS
4
+ module Components
5
+ module GovUK
6
+ class ServiceNavigation < Base
7
+ # = GOV.UK Service navigation navigation
8
+ #
9
+ # The service navigation navigation section
10
+ #
11
+ # @!attribute [r] navigation
12
+ # @return Array<Hash> A hash with navigation options
13
+ # @!attribute [r] navigation_label
14
+ # @return [String] The aria label for the navigation
15
+ # @!attribute [r] navigation_classes
16
+ # @return [String] The classes for the navigation
17
+ # @!attribute [r] navigation_id
18
+ # @return [String] The id for the navigation
19
+ # @!attribute [r] menu_button
20
+ # @return [Hash] The options for the menu button
21
+
22
+ class Navigation
23
+ include ActionView::Context
24
+ include ActionView::Helpers
25
+
26
+ private
27
+
28
+ attr_reader :navigation, :menu_button
29
+
30
+ public
31
+
32
+ # rubocop:disable Metrics/CyclomaticComplexity
33
+
34
+ # @param navigation [Hash] options for the navigation
35
+ # @param context [ActionView::Base] the view context
36
+ # @param menu_button [Hash] options for the menu button
37
+ #
38
+ # @option navigation [Array] :items an array of links for the navigation section.
39
+ # See {Components::GovUK::ServiceNavigation::Link#initialize Link#initialize} for details of the items in the array.
40
+ # @option navigation [String] :classes additional CSS classes for the navigation HTML
41
+ # @option navigation [String] :label text for the aria-label attribute of the navigation. Defaults to the menu button text
42
+ #
43
+ # @option menu_button [String] :text text for the button that opens the mobile navigation menu.
44
+ # By default, this is set to +Menu+.
45
+ # @option menu_button [String] :label text for the aria-label attribute of the button that opens the mobile navigation.
46
+ # Defaults to +Show or hide menu+.
47
+
48
+ def initialize(navigation:, context:, menu_button: nil)
49
+ menu_button ||= {}
50
+ menu_button[:text] ||= 'Menu'
51
+
52
+ @navigation = { id: navigation[:id] || 'navigation' }
53
+
54
+ menu_button[:aria] = { controls: @navigation[:id] }
55
+ menu_button[:aria][:label] = menu_button[:label] if menu_button[:label] && menu_button[:label] != menu_button[:text]
56
+
57
+ @menu_button = menu_button
58
+ @navigation[:links] = navigation[:items].map { |navigation_link| Link.new(context: context, **navigation_link) }
59
+ @navigation[:label] = navigation[:label] || menu_button[:text]
60
+ @navigation[:class] = "govuk-service-navigation__wrapper #{navigation[:classes]}".rstrip
61
+ end
62
+
63
+ # rubocop:enable Metrics/CyclomaticComplexity
64
+
65
+ # Generates the HTML for the GOV.UK Service Navigation navigation
66
+ #
67
+ # @return [ActiveSupport::SafeBuffer]
68
+
69
+ def render
70
+ tag.nav(aria: { label: navigation[:label] }, class: navigation[:class]) do
71
+ concat(button_tag(menu_button[:text], type: :button, class: 'govuk-service-navigation__toggle govuk-js-service-navigation-toggle', aria: menu_button[:aria], hidden: true))
72
+ concat(tag.ul(id: navigation[:id], class: 'govuk-service-navigation__list') do
73
+ navigation[:links].each { |navigation_link| concat(navigation_link.render) }
74
+ end)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,91 @@
1
+ require_relative '../base'
2
+ require_relative 'service_navigation/navigation'
3
+
4
+ module CCS
5
+ module Components
6
+ module GovUK
7
+ # = GOV.UK Service Navigation
8
+ #
9
+ # This is used to generate the service navigation component from the
10
+ # {https://design-system.service.gov.uk/components/service-navigatio GDS - Components - Service navigation}
11
+ #
12
+ # @!attribute [r] text
13
+ # @return [String] Text for the service navigation
14
+ # @!attribute [r] href
15
+ # @return [String] The href for the service navigation
16
+
17
+ class ServiceNavigation < Base
18
+ private
19
+
20
+ attr_reader :navigation, :service
21
+
22
+ public
23
+
24
+ # @param navigation [Hash] options for the navigation section of the service navigation.
25
+ # See {Components::GovUK::ServiceNavigation::Navigation#initialize Navigation#initialize} for details of the options.
26
+ # @param menu_button [Hash] options for the menu button in the service navigation.
27
+ # See {Components::GovUK::ServiceNavigation::Navigation#initialize Navigation#initialize} for details of the options.
28
+ # @param service [Hash] options for the service name
29
+ # @param options [Hash] options that will be used in customising the HTML
30
+ #
31
+ # @option service [String] :name the name of the service, included in the service navigation
32
+ # @option service [String] :href URL for the service name anchor
33
+ #
34
+ # @option options [String] :classes additional CSS classes for the service navigation HTML
35
+ # @option options [Hash] :attributes additional attributes that will added as part of the service navigation HTML
36
+
37
+ def initialize(navigation: nil, menu_button: nil, service: nil, **options)
38
+ super(**options)
39
+
40
+ (@options[:attributes][:aria] ||= {})[:label] ||= 'Service information' if service
41
+
42
+ @navigation = Navigation.new(navigation: navigation, menu_button: menu_button, context: @context) if navigation && navigation[:items].present?
43
+ @service = service
44
+ end
45
+
46
+ # Generates the HTML for the GOV.UK Service navigation component
47
+ #
48
+ # @return [ActiveSupport::SafeBuffer]
49
+
50
+ def render
51
+ if service
52
+ tag.section(inner_content, **options[:attributes])
53
+ else
54
+ tag.div(inner_content, **options[:attributes])
55
+ end
56
+ end
57
+
58
+ # The default attributes for the service navigation
59
+
60
+ DEFAULT_ATTRIBUTES = { class: 'govuk-service-navigation', data: { module: 'govuk-service-navigation' } }.freeze
61
+
62
+ private
63
+
64
+ # Generates the HTML for the inner content of the GOV.UK Service navigation component
65
+ #
66
+ # @return [ActiveSupport::SafeBuffer]
67
+
68
+ def inner_content
69
+ tag.div(class: 'govuk-width-container') do
70
+ tag.div(class: 'govuk-service-navigation__container') do
71
+ concat(tag.span(service_navigation_service_name, class: 'govuk-service-navigation__service-name')) if service
72
+ concat(navigation.render) if navigation
73
+ end
74
+ end
75
+ end
76
+
77
+ # Generates the service name section
78
+ #
79
+ # @return [ActiveSupport::SafeBuffer]
80
+
81
+ def service_navigation_service_name
82
+ if service[:href]
83
+ link_to(service[:name], service[:href], class: 'govuk-service-navigation__link')
84
+ else
85
+ tag.span(service[:name], class: 'govuk-service-navigation__text')
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -30,7 +30,7 @@ module CCS
30
30
  def initialize(task_list_items:, id_prefix: nil, **options)
31
31
  super(**options)
32
32
 
33
- @task_list_items = task_list_items.map.with_index(1) { |task_list_item, index| Item.new(context: @context, index: index, id_prefix: id_prefix || 'task-list', **task_list_item) }
33
+ @task_list_items = task_list_items.map.with_index(1) { |task_list_item, index| Item.new(context: @context, index: index, id_prefix: id_prefix || 'task-list', **task_list_item) if task_list_item.present? }
34
34
  end
35
35
 
36
36
  # Generates the HTML for the GOV.UK task list component
@@ -39,7 +39,7 @@ module CCS
39
39
 
40
40
  def render
41
41
  tag.ul(**options[:attributes]) do
42
- task_list_items.each { |task_list_item| concat(task_list_item.render) }
42
+ task_list_items.each { |task_list_item| concat(task_list_item.render) if task_list_item }
43
43
  end
44
44
  end
45
45
 
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../components/govuk/service_navigation'
4
+
5
+ module CCS
6
+ module FrontendHelpers
7
+ module GovUKFrontend
8
+ # = GOV.UK Service Navigation
9
+ #
10
+ # This helper is used for generating the service navigation component from the
11
+ # {https://design-system.service.gov.uk/components/service-navigation GDS - Components - Service navigations}
12
+
13
+ module ServiceNavigation
14
+ # Generates the HTML for the GOV.UK Service navigation component
15
+ #
16
+ # @param (see CCS::Components::GovUK::ServiceNavigation#initialize)
17
+ #
18
+ # @option (see CCS::Components::GovUK::ServiceNavigation#initialize)
19
+ #
20
+ # @return (see CCS::Components::GovUK::ServiceNavigation#render)
21
+
22
+ def govuk_service_navigation(**options)
23
+ Components::GovUK::ServiceNavigation.new(context: self, **options).render
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -28,6 +28,7 @@ require_relative 'govuk_frontend/password_input'
28
28
  require_relative 'govuk_frontend/phase_banner'
29
29
  require_relative 'govuk_frontend/radios'
30
30
  require_relative 'govuk_frontend/select'
31
+ require_relative 'govuk_frontend/service_navigation'
31
32
  require_relative 'govuk_frontend/skip_link'
32
33
  require_relative 'govuk_frontend/step_by_step_navigation'
33
34
  require_relative 'govuk_frontend/summary_list'
@@ -72,6 +73,7 @@ module CCS
72
73
  include PhaseBanner
73
74
  include Radios
74
75
  include Select
76
+ include ServiceNavigation
75
77
  include SkipLink
76
78
  include StepByStepNavigation
77
79
  include SummaryList
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CCS
4
4
  module FrontendHelpers
5
- VERSION = '1.1.1'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
data/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "author": "CCS",
6
6
  "license": "MIT",
7
7
  "devDependencies": {
8
- "govuk-frontend": "^5.4.1",
9
- "ccs-frontend": "^1.1.1"
8
+ "govuk-frontend": "^5.6.0",
9
+ "ccs-frontend": "^1.1.3"
10
10
  }
11
11
  }
data/yarn.lock CHANGED
@@ -2,12 +2,12 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
- ccs-frontend@^1.1.1:
6
- version "1.1.1"
7
- resolved "https://registry.yarnpkg.com/ccs-frontend/-/ccs-frontend-1.1.1.tgz#ec279e2c252ae70d546c1b78770ee8d02b576fd2"
8
- integrity sha512-k6I7qGMNTgGRkofX45g73UXPz7Ai3R+hOcoIfjFdWqWPNa2zsScsfJtSbRaqYBD2T2LHso9ql3PuXIUywcBNfw==
5
+ ccs-frontend@^1.1.3:
6
+ version "1.1.3"
7
+ resolved "https://registry.yarnpkg.com/ccs-frontend/-/ccs-frontend-1.1.3.tgz#d42befcf40517a32161716e963c298add2f01141"
8
+ integrity sha512-jZKKnZVI1JEpHY/3F8Hgry0zlXwlMSBtBc/JBBenXy/T67lmVAf5IadcVCnrZkQ5gLxbY8rfq3nUWZsoF90p5w==
9
9
 
10
- govuk-frontend@^5.4.1:
11
- version "5.4.1"
12
- resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-5.4.1.tgz#cae59d1fd441f7830445810c1d281eac06a835d1"
13
- integrity sha512-Gmd8LV++TRh9OF6tA+9KQTpwvlsLcri7qRjViz9ji4YuwZvX+c9TD7tyE+dnJcqsQsJfhr9Fp38m3Hu3H7EIcQ==
10
+ govuk-frontend@^5.6.0:
11
+ version "5.6.0"
12
+ resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-5.6.0.tgz#8c0975f0d825ec7192bcfe64e3e97ef3dfa7dea1"
13
+ integrity sha512-yNA4bL7i7mNrg36wPNZ3RctHo9mjl82Phs8MWs1lwovxJuQ4ogEo/XWn2uB1HxkXNqgMlW4wnd0iiKgRMfxYfw==
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccs-frontend_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crown Commercial Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,6 +119,9 @@ files:
119
119
  - lib/ccs/components/govuk/pagination/item/tag.rb
120
120
  - lib/ccs/components/govuk/panel.rb
121
121
  - lib/ccs/components/govuk/phase_banner.rb
122
+ - lib/ccs/components/govuk/service_navigation.rb
123
+ - lib/ccs/components/govuk/service_navigation/link.rb
124
+ - lib/ccs/components/govuk/service_navigation/navigation.rb
122
125
  - lib/ccs/components/govuk/skip_link.rb
123
126
  - lib/ccs/components/govuk/step_by_step_navigation.rb
124
127
  - lib/ccs/components/govuk/step_by_step_navigation/section.rb
@@ -186,6 +189,7 @@ files:
186
189
  - lib/ccs/frontend_helpers/govuk_frontend/phase_banner.rb
187
190
  - lib/ccs/frontend_helpers/govuk_frontend/radios.rb
188
191
  - lib/ccs/frontend_helpers/govuk_frontend/select.rb
192
+ - lib/ccs/frontend_helpers/govuk_frontend/service_navigation.rb
189
193
  - lib/ccs/frontend_helpers/govuk_frontend/skip_link.rb
190
194
  - lib/ccs/frontend_helpers/govuk_frontend/step_by_step_navigation.rb
191
195
  - lib/ccs/frontend_helpers/govuk_frontend/summary_list.rb
@@ -222,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
226
  - !ruby/object:Gem::Version
223
227
  version: '0'
224
228
  requirements: []
225
- rubygems_version: 3.5.9
229
+ rubygems_version: 3.5.11
226
230
  signing_key:
227
231
  specification_version: 4
228
232
  summary: Gem containing view helpers for CCS Ruby on Rails projects