govuk_design_system_formbuilder 6.0.0 → 6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5cdce7fa87b070e4c8335c43ee6a23e8ad7ca61933f1ad0a3a80339c3e1959a
4
- data.tar.gz: b3446d561dc3a96c23d6140ad0f966edd39517891eac18e1a3c41d894c8b48c5
3
+ metadata.gz: 2cf25eca1fc9e5160b36b37bd946844b4662453bb3d7ad41761b669b3ee8bebe
4
+ data.tar.gz: 7173d16c0574e1f4e2477c08ffe2a0bdc5325047d323dd21427d8fc2bdf42b31
5
5
  SHA512:
6
- metadata.gz: d74467eeac3d4b1001452df29de4d3a6e92159346f820b7d70b06ea74a34e175748891abebdc0867245fbaafffae30bef8d36c8637104f46ce11d82ac832790d
7
- data.tar.gz: c4752085f758ddf51b544c9a6b59425fdcccfc5ea316560ccafedb18a40f002bd3f228da78d8df379e3cc588266ad3fa871f84aa56b3f9c4123e31f73c2e8cba
6
+ metadata.gz: 2b34a3a4c6792f6bcfd13c0415f07b9e144e64d97350d9c6cb700feffbc1b90242f05f765ae292523a87ccf212528687c42285442f2b4eab8d9c46ec8a9aa594
7
+ data.tar.gz: ad04540f4c3788b828e154c67b733fdb63fbd46a708e3f83b94400d57ae5016095ab9203c4603c22a4c49f9d01b054590679142fc3e90ee5f852c92bc30960ec
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem version](https://badge.fury.io/rb/govuk_design_system_formbuilder.svg)](https://badge.fury.io/rb/govuk_design_system_formbuilder)
5
5
  [![Gem](https://img.shields.io/gem/dt/govuk_design_system_formbuilder?logo=rubygems)](https://rubygems.org/gems/govuk_design_system_formbuilder)
6
6
  ![GitHub license](https://img.shields.io/github/license/x-govuk/govuk-form-builder)
7
- [![GOV.UK Design System version](https://img.shields.io/badge/GOV.UK%20Design%20System-6.0.0-brightgreen)](https://design-system.service.gov.uk)
7
+ [![GOV.UK Design System version](https://img.shields.io/badge/GOV.UK%20Design%20System-6.2.0-brightgreen)](https://design-system.service.gov.uk)
8
8
  [![Rails](https://img.shields.io/badge/Rails-7.2.3%20%E2%95%B1%208.0.1%20%E2%95%B1%208.1.2-E16D6D)](https://weblog.rubyonrails.org/releases/)
9
9
  [![Ruby](https://img.shields.io/badge/Ruby-3.2.10%20%20%E2%95%B1%203.4.8%20%20%E2%95%B1%204.0.1-E16D6D)](https://www.ruby-lang.org/en/downloads/)
10
10
 
@@ -385,6 +385,11 @@ module GOVUKDesignSystemFormBuilder
385
385
  # @option form_group kwargs [Hash] additional attributes added to the form group
386
386
  # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +textarea+ element
387
387
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
388
+ # @param characters_under_limit_other_text [String] Text that informs the user they have X word/characters remaining. Default is "%{count} characters to go". If javascript is not provided, this option will be ignored.
389
+ # @param characters_under_limit_one_text [String] Text that informs the user they have 1 word/character remaining. Default is "%{count} character to go". If javascript is not provided, this option will be ignored.
390
+ # @param characters_at_limit_text [String] The text that informs the user they've reached the character limit. Default is "No characters left". If javascript is not provided, this option will be ignored.
391
+ # @param characters_over_limit_other_text [String] Text that informs the user they have added X words/characters too many. Default is "%{count} characters to go". If javascript is not provided, this option will be ignored.
392
+ # @param characters_over_limit_one_text [String] Text that informs the user they have added 1 word/character too many. Default is "%{count} character to go". If javascript is not provided, this option will be ignored.
388
393
  # @return [ActiveSupport::SafeBuffer] HTML output
389
394
  # @see https://design-system.service.gov.uk/components/textarea/ GOV.UK text area component
390
395
  # @see https://design-system.service.gov.uk/components/character-count GOV.UK character count component
@@ -409,8 +414,46 @@ module GOVUKDesignSystemFormBuilder
409
414
  # = f.govuk_text_area :instructions,
410
415
  # label: -> { tag.h3("How do you set it up?") }
411
416
  #
412
- def govuk_text_area(attribute_name, hint: {}, label: {}, caption: {}, max_words: nil, max_chars: nil, rows: 5, threshold: nil, form_group: {}, **kwargs, &block)
413
- Elements::TextArea.new(self, object_name, attribute_name, hint:, label:, caption:, max_words:, max_chars:, rows:, threshold:, form_group:, **kwargs, &block).html
417
+ def govuk_text_area(
418
+ attribute_name,
419
+ hint: {},
420
+ label: {},
421
+ caption: {},
422
+ max_words: nil,
423
+ max_chars: nil,
424
+ rows: 5,
425
+ threshold: nil,
426
+ form_group: {},
427
+ description_other_text: nil,
428
+ under_limit_other_text: nil,
429
+ under_limit_one_text: nil,
430
+ at_limit_text: nil,
431
+ over_limit_one_text: nil,
432
+ over_limit_other_text: nil,
433
+ **kwargs,
434
+ &block
435
+ )
436
+ Elements::TextArea.new(
437
+ self,
438
+ object_name,
439
+ attribute_name,
440
+ hint:,
441
+ label:,
442
+ caption:,
443
+ max_words:,
444
+ max_chars:,
445
+ rows:,
446
+ threshold:,
447
+ form_group:,
448
+ description_other_text:,
449
+ under_limit_other_text:,
450
+ under_limit_one_text:,
451
+ at_limit_text:,
452
+ over_limit_one_text:,
453
+ over_limit_other_text:,
454
+ **kwargs,
455
+ &block
456
+ ).html
414
457
  end
415
458
 
416
459
  # Generates a +select+ element containing +option+ for each member in the provided collection
@@ -1119,6 +1162,12 @@ module GOVUKDesignSystemFormBuilder
1119
1162
  # @param javascript [Boolean] Configures whether to add HTML for the javascript-enhanced version of the component
1120
1163
  # @param before_input [String,Proc] the content injected before the input. No content will be added if left +nil+
1121
1164
  # @param after_input [String,Proc] the content injected after the input. No content will be added if left +nil+
1165
+ # @param choose_files_button_text [String] The text of the button that opens the file picker. Default is "Choose file". If javascript is not provided, this option will be ignored.
1166
+ # @param drop_instruction_text [String] The text informing users they can drop files. Default is "or drop file". If javascript is not provided, this option will be ignored.
1167
+ # @param multiple_files_chosen_text [Hash] The text displayed when multiple files have been chosen by the user. The component will replace the %{count} placeholder with the number of files selected. This uses the govuk-frontend pluralisation rules. If javascript is not provided, this option will be ignored.
1168
+ # @param no_file_chosen_text [String] The text displayed when no file has been chosen by the user. Default is "No file chosen". If javascript is not provided, this option will be ignored.
1169
+ # @param entered_drop_zone_text [String] The text announced by assistive technology when user drags files and enters the drop zone. Default is "Entered drop zone". If javascript is not provided, this option will be ignored.
1170
+ # @param left_drop_zone_text [String] The text announced by assistive technology when user drags files and leaves the drop zone without dropping. Default is "Left drop zone". If javascript is not provided, this option will be ignored.
1122
1171
  # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
1123
1172
  #
1124
1173
  # @example A photo upload field with file type specifier and injected content
@@ -1137,8 +1186,44 @@ module GOVUKDesignSystemFormBuilder
1137
1186
  # @note Remember to set +multipart: true+ when creating a form with file
1138
1187
  # uploads, {https://guides.rubyonrails.org/form_helpers.html#uploading-files see
1139
1188
  # the Rails documentation} for more information
1140
- def govuk_file_field(attribute_name, label: {}, caption: {}, hint: {}, form_group: {}, javascript: false, before_input: nil, after_input: nil, **kwargs, &block)
1141
- Elements::File.new(self, object_name, attribute_name, label:, caption:, hint:, form_group:, javascript:, before_input:, after_input:, **kwargs, &block).html
1189
+ def govuk_file_field(
1190
+ attribute_name,
1191
+ label: {},
1192
+ caption: {},
1193
+ hint: {},
1194
+ form_group: {},
1195
+ javascript: false,
1196
+ before_input: nil,
1197
+ after_input: nil,
1198
+ choose_files_button_text: nil,
1199
+ drop_instruction_text: nil,
1200
+ multiple_files_chosen_text: nil,
1201
+ no_file_chosen_text: nil,
1202
+ entered_drop_zone_text: nil,
1203
+ left_drop_zone_text: nil,
1204
+ **kwargs,
1205
+ &block
1206
+ )
1207
+ Elements::File.new(
1208
+ self,
1209
+ object_name,
1210
+ attribute_name,
1211
+ label:,
1212
+ caption:,
1213
+ hint:,
1214
+ form_group:,
1215
+ javascript:,
1216
+ before_input:,
1217
+ after_input:,
1218
+ choose_files_button_text:,
1219
+ drop_instruction_text:,
1220
+ multiple_files_chosen_text:,
1221
+ no_file_chosen_text:,
1222
+ entered_drop_zone_text:,
1223
+ left_drop_zone_text:,
1224
+ **kwargs,
1225
+ &block
1226
+ ).html
1142
1227
  end
1143
1228
  end
1144
1229
  end
@@ -36,7 +36,7 @@ module GOVUKDesignSystemFormBuilder
36
36
  {
37
37
  legend: @legend,
38
38
  caption: @caption,
39
- described_by: [error_id, hint_id, supplemental_id]
39
+ described_by: [error_id, hint_id]
40
40
  }
41
41
  end
42
42
 
@@ -43,7 +43,7 @@ module GOVUKDesignSystemFormBuilder
43
43
  {
44
44
  id: field_id(link_errors: true),
45
45
  class: classes,
46
- aria: { describedby: combine_references(hint_id, error_id, supplemental_id) }
46
+ aria: { describedby: combine_references(hint_id, error_id) }
47
47
  }
48
48
  end
49
49
 
@@ -11,17 +11,24 @@ module GOVUKDesignSystemFormBuilder
11
11
  include Traits::HTMLClasses
12
12
  include Traits::ContentBeforeAndAfter
13
13
 
14
- def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, javascript:, before_input:, after_input:, **kwargs, &block)
14
+ def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, javascript:, before_input:, after_input:, choose_files_button_text:, drop_instruction_text:, multiple_files_chosen_text:, no_file_chosen_text:, entered_drop_zone_text:, left_drop_zone_text:, **kwargs, &block)
15
15
  super(builder, object_name, attribute_name, &block)
16
16
 
17
- @label = label
18
- @caption = caption
19
- @hint = hint
17
+ @label = label
18
+ @caption = caption
19
+ @hint = hint
20
20
  @html_attributes = kwargs
21
- @form_group = form_group
22
- @javascript = javascript
23
- @before_input = before_input
24
- @after_input = after_input
21
+ @form_group = form_group
22
+ @javascript = javascript
23
+ @before_input = before_input
24
+ @after_input = after_input
25
+
26
+ @choose_files_button_text = choose_files_button_text
27
+ @drop_instruction_text = drop_instruction_text
28
+ @multiple_files_chosen_text = multiple_files_chosen_text
29
+ @no_file_chosen_text = no_file_chosen_text
30
+ @entered_drop_zone_text = entered_drop_zone_text
31
+ @left_drop_zone_text = left_drop_zone_text
25
32
  end
26
33
 
27
34
  def html
@@ -41,20 +48,38 @@ module GOVUKDesignSystemFormBuilder
41
48
  end
42
49
 
43
50
  def file_with_javascript_markup
44
- tag.div(class: "#{brand}-drop-zone", data: { module: "#{brand}-file-upload" }) { file }
51
+ tag.div(class: "#{brand}-drop-zone", data: { module: "#{brand}-file-upload" }, **i18n_data) { file }
45
52
  end
46
53
 
47
54
  def options
48
55
  {
49
56
  id: field_id(link_errors: true),
50
57
  class: classes,
51
- aria: { describedby: combine_references(hint_id, error_id, supplemental_id) }
58
+ aria: { describedby: combine_references(hint_id, error_id) }
52
59
  }
53
60
  end
54
61
 
55
62
  def classes
56
63
  build_classes(%(file-upload), %(file-upload--error) => has_errors?).prefix(brand)
57
64
  end
65
+
66
+ def i18n_data
67
+ data = {
68
+ "data-i18n.choose-files-button" => @choose_files_button_text,
69
+ "data-i18n.drop-instruction" => @drop_instruction_text,
70
+ "data-i18n.no-file-chosen" => @no_file_chosen_text,
71
+ "data-i18n.entered-drop-zone" => @entered_drop_zone_text,
72
+ "data-i18n.left-drop-zone" => @left_drop_zone_text,
73
+ }
74
+
75
+ if @multiple_files_chosen_text.is_a?(Hash)
76
+ @multiple_files_chosen_text.each do |key, value|
77
+ data["data-i18n.multiple-files-chosen.#{key}"] = value
78
+ end
79
+ end
80
+
81
+ data.compact
82
+ end
58
83
  end
59
84
  end
60
85
  end
@@ -43,7 +43,7 @@ module GOVUKDesignSystemFormBuilder
43
43
  {
44
44
  legend: @legend,
45
45
  caption: @caption,
46
- described_by: [error_id, hint_id, supplemental_id]
46
+ described_by: [error_id, hint_id]
47
47
  }
48
48
  end
49
49
 
@@ -10,7 +10,27 @@ module GOVUKDesignSystemFormBuilder
10
10
  include Traits::HTMLAttributes
11
11
  include Traits::HTMLClasses
12
12
 
13
- def initialize(builder, object_name, attribute_name, hint:, label:, caption:, rows:, max_words:, max_chars:, threshold:, form_group:, **kwargs, &block)
13
+ def initialize(
14
+ builder,
15
+ object_name,
16
+ attribute_name,
17
+ hint:,
18
+ label:,
19
+ caption:,
20
+ rows:,
21
+ max_words:,
22
+ max_chars:,
23
+ threshold:,
24
+ form_group:,
25
+ description_other_text:,
26
+ under_limit_other_text:,
27
+ under_limit_one_text:,
28
+ at_limit_text:,
29
+ over_limit_other_text:,
30
+ over_limit_one_text:,
31
+ **kwargs,
32
+ &block
33
+ )
14
34
  super(builder, object_name, attribute_name, &block)
15
35
 
16
36
  fail ArgumentError, 'limit can be words or chars' if max_words && max_chars
@@ -24,10 +44,17 @@ module GOVUKDesignSystemFormBuilder
24
44
  @rows = rows
25
45
  @form_group = form_group
26
46
  @html_attributes = kwargs
47
+
48
+ @description_other_text = description_other_text
49
+ @under_limit_other_text = under_limit_other_text
50
+ @under_limit_one_text = under_limit_one_text
51
+ @at_limit_text = at_limit_text
52
+ @over_limit_other_text = over_limit_other_text
53
+ @over_limit_one_text = over_limit_one_text
27
54
  end
28
55
 
29
56
  def html
30
- Containers::FormGroup.new(*bound, **@form_group.merge(limit_form_group_options)).html do
57
+ Containers::FormGroup.new(*bound, **@form_group.merge(limit_form_group_options), **i18n_data).html do
31
58
  safe_join([label_element, supplemental_content, hint_element, error_element, text_area, limit_description])
32
59
  end
33
60
  end
@@ -47,7 +74,7 @@ module GOVUKDesignSystemFormBuilder
47
74
  id: field_id(link_errors: true),
48
75
  class: classes,
49
76
  rows: @rows,
50
- aria: { describedby: combine_references(hint_id, error_id, supplemental_id, limit_description_id) },
77
+ aria: { describedby: combine_references(hint_id, error_id, limit_description_id) },
51
78
  }
52
79
  end
53
80
 
@@ -109,6 +136,28 @@ module GOVUKDesignSystemFormBuilder
109
136
  def limit_threshold_options
110
137
  { threshold: @threshold }
111
138
  end
139
+
140
+ def i18n_data
141
+ # "data-i18n.textarea-description.other" => @textarea_description_other_text,
142
+ case limit_type
143
+ when 'characters'
144
+ {
145
+ 'data-i18n.characters-at-limit' => @at_limit_text,
146
+ 'data-i18n.characters-under-limit.other' => @under_limit_other_text,
147
+ 'data-i18n.characters-under-limit.one' => @under_limit_one_text,
148
+ 'data-i18n.characters-over-limit.other' => @over_limit_other_text,
149
+ 'data-i18n.characters-over-limit.one' => @over_limit_one_text,
150
+ }.compact
151
+ when 'words'
152
+ {
153
+ 'data-i18n.words-at-limit' => @at_limit_text,
154
+ 'data-i18n.words-under-limit.other' => @under_limit_other_text,
155
+ 'data-i18n.words-under-limit.one' => @under_limit_one_text,
156
+ 'data-i18n.words-over-limit.other' => @over_limit_other_text,
157
+ 'data-i18n.words-over-limit.one' => @over_limit_one_text,
158
+ }.compact
159
+ end
160
+ end
112
161
  end
113
162
  end
114
163
  end
@@ -27,7 +27,7 @@ module GOVUKDesignSystemFormBuilder
27
27
  end
28
28
 
29
29
  def fieldset_options
30
- { legend: @legend, caption: @caption, described_by: [error_id, hint_id, supplemental_id] }
30
+ { legend: @legend, caption: @caption, described_by: [error_id, hint_id] }
31
31
  end
32
32
 
33
33
  def segment_label_text(segment)
@@ -55,7 +55,7 @@ module GOVUKDesignSystemFormBuilder
55
55
  {
56
56
  id: field_id(link_errors: true),
57
57
  class: classes,
58
- aria: { describedby: combine_references(hint_id, error_id, supplemental_id) }
58
+ aria: { describedby: combine_references(hint_id, error_id) }
59
59
  }
60
60
  end
61
61
 
@@ -1,12 +1,6 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Traits
3
3
  module Supplemental
4
- def supplemental_id
5
- return if @block_content.blank?
6
-
7
- build_id('supplemental')
8
- end
9
-
10
4
  private
11
5
 
12
6
  def supplemental_content
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '6.0.0'.freeze
2
+ VERSION = '6.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_design_system_formbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-28 00:00:00.000000000 Z
11
+ date: 2026-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-attributes-utils
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '6.1'
33
+ version: '7.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '6.1'
40
+ version: '7.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '6.1'
47
+ version: '7.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '6.1'
54
+ version: '7.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '6.1'
61
+ version: '7.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '6.1'
68
+ version: '7.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ostruct
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '6.0'
117
+ version: '8.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '6.0'
124
+ version: '8.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop-govuk
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 4.7.0
187
+ version: 5.0.0
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 4.7.0
194
+ version: 5.0.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: rubypants
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -254,14 +254,14 @@ dependencies:
254
254
  requirements:
255
255
  - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: 0.33.0
257
+ version: 0.34.0
258
258
  type: :development
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
- version: 0.33.0
264
+ version: 0.34.0
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: webrick
267
267
  requirement: !ruby/object:Gem::Requirement