govuk_design_system_formbuilder 5.1.0 → 5.3.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: 0c0051ba0d0eb5f3afcf87055e171bb1d0e930c9c063297a35e231537428ad84
4
- data.tar.gz: 28dbcd6291008fe3010aebd3dd79276f452ca030b7f6fc1208646f33510de99d
3
+ metadata.gz: 8e35d673c28b60b7f821d646ce2386de839de096525d8689104b1d972e7cbd41
4
+ data.tar.gz: 59cdb7f48b6d6540e281d2c2953d87c9a54fb570415be01cf5f68d0a15db57c9
5
5
  SHA512:
6
- metadata.gz: c1278d6f46dadbd4574a5551f7b4f758aa907e486d95ed1aca627e9ec4a785c7770edb5bb09bc0a941ec1ea8433888be6e2cc00e33e14ffb589f11a94e65b66c
7
- data.tar.gz: e19a3b4357bcf82918a1f4354f927bbc265e2ec86759844fa7cc56fae4231e4a4f1c0c5106f0c5d1b59146bd2e4e716257de16c1a443ecf2df8dc4ee3f158f44
6
+ metadata.gz: 97062bf75bb33fd65e0e2b82a916f020164274ab4e9920eebbc56bdc7e392708e5fdd2570c5e7b6627a5cdb7c54156dc2ebe6c4ade09af67815122dbe00c0b46
7
+ data.tar.gz: dfb265e232f555c33fc432c15fe84e2a04386ebf2f2a8946fb691c5f64be323ecf2e5c6484d35a0e1697a82fc67c84fdfbaa0f1a31972356a12c74484de0be69
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Gem](https://img.shields.io/gem/dt/govuk_design_system_formbuilder?logo=rubygems)](https://rubygems.org/gems/govuk_design_system_formbuilder)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/110136fb22341d3ba646/test_coverage)](https://codeclimate.com/github/x-govuk/govuk-form-builder/test_coverage)
8
8
  [![GitHub license](https://img.shields.io/github/license/x-govuk/govuk-form-builder)](https://github.com/x-govuk/govuk-form-builder/blob/main/LICENSE)
9
- [![GOV.UK Design System version](https://img.shields.io/badge/GOV.UK%20Design%20System-5.1.0-brightgreen)](https://design-system.service.gov.uk)
9
+ [![GOV.UK Design System version](https://img.shields.io/badge/GOV.UK%20Design%20System-5.3.0-brightgreen)](https://design-system.service.gov.uk)
10
10
  [![Rails](https://img.shields.io/badge/Rails-6.1.7%20%E2%95%B1%207.1.3-E16D6D)](https://weblog.rubyonrails.org/releases/)
11
11
  [![Ruby](https://img.shields.io/badge/Ruby-3.1.4%20%20%E2%95%B1%203.2.3%20%20%E2%95%B1%203.3.0-E16D6D)](https://www.ruby-lang.org/en/downloads/)
12
12
 
@@ -162,57 +162,6 @@ module GOVUKDesignSystemFormBuilder
162
162
  Elements::Inputs::Email.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
163
163
  end
164
164
 
165
- # Generates a input of type +password+
166
- #
167
- # @param attribute_name [Symbol] The name of the attribute
168
- # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
169
- # supplied the hint will be wrapped in a +div+ instead of a +span+
170
- # @option hint text [String] the hint text
171
- # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
172
- # @param width [Integer,String] sets the width of the input, can be +2+, +3+ +4+, +5+, +10+ or +20+ characters
173
- # or +one-quarter+, +one-third+, +one-half+, +two-thirds+ or +full+ width of the container
174
- # @param extra_letter_spacing [Boolean] when true adds space between characters to increase the readability of
175
- # sequences of letters and numbers. Defaults to +false+.
176
- # @param label [Hash,Proc] configures or sets the associated label content
177
- # @option label text [String] the label text
178
- # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
179
- # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
180
- # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
181
- # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
182
- # @param caption [Hash] configures or sets the caption content which is inserted above the label
183
- # @option caption text [String] the caption text
184
- # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
185
- # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
186
- # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
187
- # @param form_group [Hash] configures the form group
188
- # @option form_group kwargs [Hash] additional attributes added to the form group
189
- # @param prefix_text [String] the text placed before the input. No prefix will be added if left +nil+
190
- # @param suffix_text [String] the text placed after the input. No suffix will be added if left +nil+
191
- # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
192
- # @return [ActiveSupport::SafeBuffer] HTML output
193
- # @see https://design-system.service.gov.uk/components/text-input/ GOV.UK Text input
194
- # @see https://design-system.service.gov.uk/patterns/passwords/ GOV.UK Password patterns
195
- # @see https://design-system.service.gov.uk/styles/typography/#headings-with-captions Headings with captions
196
- #
197
- # @example A password field
198
- # = f.govuk_password_field :password,
199
- # label: { text: 'Enter your password' }
200
- #
201
- # @example A password field with injected content
202
- # = f.govuk_password_field :password,
203
- # label: { text: 'Password' } do
204
- #
205
- # p.govuk-inset-text
206
- # | Ensure your password is at least 16 characters long
207
- #
208
- # @example A password field with the label supplied as a proc
209
- # = f.govuk_password_field :passcode,
210
- # label: -> { tag.h3('What is your secret pass code?') }
211
- #
212
- def govuk_password_field(attribute_name, hint: {}, label: {}, width: nil, extra_letter_spacing: false, form_group: {}, caption: {}, prefix_text: nil, suffix_text: nil, **kwargs, &block)
213
- Elements::Inputs::Password.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
214
- end
215
-
216
165
  # Generates a input of type +url+
217
166
  #
218
167
  # @param attribute_name [Symbol] The name of the attribute
@@ -320,6 +269,70 @@ module GOVUKDesignSystemFormBuilder
320
269
  Elements::Inputs::Number.new(self, object_name, attribute_name, hint:, label:, caption:, width:, extra_letter_spacing:, form_group:, prefix_text:, suffix_text:, **kwargs, &block).html
321
270
  end
322
271
 
272
+ # Generates a password input
273
+ #
274
+ # @param attribute_name [Symbol] The name of the attribute
275
+ # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
276
+ # supplied the hint will be wrapped in a +div+ instead of a +span+
277
+ # @option hint text [String] the hint text
278
+ # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
279
+ # @param label [Hash,Proc] configures or sets the associated label content
280
+ # @option label text [String] the label text
281
+ # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
282
+ # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
283
+ # @option label hidden [Boolean] control the visability of the label. Hidden labels will stil be read by screenreaders
284
+ # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
285
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
286
+ # @option caption text [String] the caption text
287
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
288
+ # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
289
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
290
+ # @param form_group [Hash] configures the form group
291
+ # @option form_group kwargs [Hash] additional attributes added to the form group
292
+ # @param show_password_text [String] button text when the password is hidden. Defaults to "Show"
293
+ # @param hide_password_text [String] button text when the password is shown. Defaults to "Hide"
294
+ # @param show_password_aria_label_text [String] button text exposed to assistive technologies, like screen readers, when the password is hidden. Defaults to "Show password"
295
+ # @param hide_password_aria_label_text [String] button text exposed to assistive technologies, like screen readers, when the password is visible. Defaults to "Hide password"
296
+ # @param password_shown_announcement_text [String] Announcement made to screen reader users when their password has become visible in plain text. Defaults to "Your password is visible"
297
+ # @param password_hidden_announcement_text [String] Announcement made to screen reader users when their password has been obscured and is not visible. Defaults to "Your password is hidden"
298
+ #
299
+ # @example A password field
300
+ # = f.govuk_password_field :password
301
+ #
302
+ def govuk_password_field(
303
+ attribute_name,
304
+ hint: {},
305
+ label: {},
306
+ caption: {},
307
+ form_group: {},
308
+ show_password_text: config.default_show_password_text,
309
+ hide_password_text: config.default_hide_password_text,
310
+ show_password_aria_label_text: config.default_show_password_aria_label_text,
311
+ hide_password_aria_label_text: config.default_hide_password_aria_label_text,
312
+ password_shown_announcement_text: config.default_password_shown_announcement_text,
313
+ password_hidden_announcement_text: config.default_password_hidden_announcement_text,
314
+ **kwargs,
315
+ &block
316
+ )
317
+ Elements::Password.new(
318
+ self,
319
+ object_name,
320
+ attribute_name,
321
+ hint:,
322
+ label:,
323
+ caption:,
324
+ form_group:,
325
+ show_password_text:,
326
+ hide_password_text:,
327
+ show_password_aria_label_text:,
328
+ hide_password_aria_label_text:,
329
+ password_shown_announcement_text:,
330
+ password_hidden_announcement_text:,
331
+ **kwargs,
332
+ &block
333
+ ).html
334
+ end
335
+
323
336
  # Generates a +textarea+ element with a label, optional hint. Also offers
324
337
  # the ability to add the GOV.UK character and word counting components
325
338
  # automatically
@@ -655,7 +668,7 @@ module GOVUKDesignSystemFormBuilder
655
668
  # @example A custom divider
656
669
  # = govuk_radio_divider 'Alternatively'
657
670
  def govuk_radio_divider(text = config.default_radio_divider_text)
658
- tag.div(text, class: %w(govuk-radios__divider))
671
+ tag.div(text, class: %(#{config.brand}-radios__divider))
659
672
  end
660
673
 
661
674
  # Generate a list of check boxes from a collection
@@ -0,0 +1,106 @@
1
+ module GOVUKDesignSystemFormBuilder
2
+ module Elements
3
+ class Password < Base
4
+ using PrefixableArray
5
+
6
+ include Traits::Error
7
+ include Traits::Hint
8
+ include Traits::Label
9
+ include Traits::HTMLAttributes
10
+ include Traits::HTMLClasses
11
+
12
+ I18nAttr = Struct.new(:key, :text, :default)
13
+
14
+ def initialize(builder, object_name, attribute_name, label:, caption:, hint:, form_group:, show_password_text:, hide_password_text:, show_password_aria_label_text:, hide_password_aria_label_text:, password_hidden_announcement_text:, password_shown_announcement_text:, **kwargs, &block)
15
+ super(builder, object_name, attribute_name, &block)
16
+
17
+ @label = label
18
+ @caption = caption
19
+ @hint = hint
20
+ @form_group = form_group
21
+ @html_attributes = kwargs
22
+
23
+ @show_password_text = show_password_text
24
+ @hide_password_text = hide_password_text
25
+
26
+ @show_password_aria_label_text = show_password_aria_label_text
27
+ @hide_password_aria_label_text = hide_password_aria_label_text
28
+
29
+ @password_shown_announcement_text = password_shown_announcement_text
30
+ @password_hidden_announcement_text = password_hidden_announcement_text
31
+ end
32
+
33
+ def html
34
+ Containers::FormGroup.new(*bound, **form_group_options).html do
35
+ safe_join([label_element, hint_element, error_element, password_input_and_button])
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def password_input_and_button
42
+ tag.div(class: wrapper_classes) do
43
+ safe_join([password_input, button])
44
+ end
45
+ end
46
+
47
+ def options
48
+ {
49
+ id: field_id(link_errors: true),
50
+ class: classes,
51
+ spellcheck: "false",
52
+ autocomplete: "current-password",
53
+ autocapitalize: "none",
54
+ aria: { describedby: combine_references(hint_id, error_id) }
55
+ }
56
+ end
57
+
58
+ def form_group_options
59
+ {
60
+ **@form_group,
61
+ **i18n_data,
62
+ class: %(#{brand}-password-input),
63
+ data: { module: %(#{brand}-password-input) },
64
+ }
65
+ end
66
+
67
+ def password_input
68
+ @builder.password_field(@attribute_name, attributes(@html_attributes))
69
+ end
70
+
71
+ def classes
72
+ build_classes('input', 'password-input__input', 'js-password-input-input', %(password-input--error) => has_errors?).prefix(brand)
73
+ end
74
+
75
+ def wrapper_classes
76
+ %w(input__wrapper password-input__wrapper).prefix(brand)
77
+ end
78
+
79
+ def button
80
+ tag.button(@show_password_text, **button_options)
81
+ end
82
+
83
+ def button_options
84
+ {
85
+ data: { module: %(#{brand}-button) },
86
+ aria: { label: "Show password", controls: field_id(link_errors: true) },
87
+ type: 'button',
88
+ class: %w(button button--secondary password-input__toggle js-password-input-toggle).prefix(brand)
89
+ }
90
+ end
91
+
92
+ def i18n_data
93
+ [
94
+ I18nAttr.new("data-i18n.show-password", @show_password_text, config.default_show_password_text),
95
+ I18nAttr.new("data-i18n.hide-password", @hide_password_text, config.default_hide_password_text),
96
+ I18nAttr.new("data-i18n.show-password-aria-label", @show_password_aria_label_text, config.default_show_password_aria_label_text),
97
+ I18nAttr.new("data-i18n.hide-password-aria-label", @hide_password_aria_label_text, config.default_hide_password_aria_label_text),
98
+ I18nAttr.new("data-i18n.password-shown-announcement", @password_shown_announcement_text, config.default_password_shown_announcement_text),
99
+ I18nAttr.new("data-i18n.password-hidden-announcement", @password_hidden_announcement_text, config.default_password_hidden_announcement_text),
100
+ ].each_with_object({}) do |attr, h|
101
+ h[attr.key] = attr.text unless attr.text == attr.default
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -13,6 +13,8 @@ module GOVUKDesignSystemFormBuilder
13
13
  def initialize(builder, object_name, attribute_name, hint:, label:, caption:, rows:, max_words:, max_chars:, threshold:, form_group:, **kwargs, &block)
14
14
  super(builder, object_name, attribute_name, &block)
15
15
 
16
+ fail ArgumentError, 'limit can be words or chars' if max_words && max_chars
17
+
16
18
  @label = label
17
19
  @caption = caption
18
20
  @hint = hint
@@ -25,19 +27,13 @@ module GOVUKDesignSystemFormBuilder
25
27
  end
26
28
 
27
29
  def html
28
- Containers::CharacterCount.new(@builder, **character_count_options).html do
29
- Containers::FormGroup.new(*bound, **@form_group).html do
30
- safe_join([label_element, supplemental_content, hint_element, error_element, text_area, limit_description])
31
- end
30
+ Containers::FormGroup.new(*bound, **@form_group.merge(limit_form_group_options)).html do
31
+ safe_join([label_element, supplemental_content, hint_element, error_element, text_area, limit_description])
32
32
  end
33
33
  end
34
34
 
35
35
  private
36
36
 
37
- def character_count_options
38
- { max_words: @max_words, max_chars: @max_chars, threshold: @threshold }
39
- end
40
-
41
37
  def text_area
42
38
  @builder.text_area(@attribute_name, **attributes(@html_attributes))
43
39
  end
@@ -92,6 +88,27 @@ module GOVUKDesignSystemFormBuilder
92
88
 
93
89
  limit_id
94
90
  end
91
+
92
+ def limit_form_group_options
93
+ return {} unless limit?
94
+
95
+ {
96
+ class: %(#{brand}-character-count),
97
+ data: { module: %(#{brand}-character-count) }.merge(**limit_max_options, **limit_threshold_options).compact
98
+ }
99
+ end
100
+
101
+ def limit_max_options
102
+ if @max_words
103
+ { maxwords: @max_words }
104
+ elsif @max_chars
105
+ { maxlength: @max_chars }
106
+ end
107
+ end
108
+
109
+ def limit_threshold_options
110
+ { threshold: @threshold }
111
+ end
95
112
  end
96
113
  end
97
114
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '5.1.0'.freeze
2
+ VERSION = '5.3.0'.freeze
3
3
  end
@@ -102,7 +102,12 @@ module GOVUKDesignSystemFormBuilder
102
102
  default_collection_radio_buttons_include_hidden: true,
103
103
  default_collection_radio_buttons_auto_bold_labels: true,
104
104
  default_submit_validate: false,
105
-
105
+ default_show_password_text: "Show",
106
+ default_hide_password_text: "Hide",
107
+ default_show_password_aria_label_text: "Show password",
108
+ default_hide_password_aria_label_text: "Hide password",
109
+ default_password_shown_announcement_text: "Your password is visible",
110
+ default_password_hidden_announcement_text: "Your password is hidden",
106
111
  localisation_schema_fallback: %i(helpers __context__),
107
112
  localisation_schema_label: nil,
108
113
  localisation_schema_hint: nil,
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: 5.1.0
4
+ version: 5.3.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: 2024-02-19 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-attributes-utils
@@ -310,7 +310,6 @@ files:
310
310
  - lib/govuk_design_system_formbuilder/builder.rb
311
311
  - lib/govuk_design_system_formbuilder/builder_helper.rb
312
312
  - lib/govuk_design_system_formbuilder/containers/button_group.rb
313
- - lib/govuk_design_system_formbuilder/containers/character_count.rb
314
313
  - lib/govuk_design_system_formbuilder/containers/check_boxes.rb
315
314
  - lib/govuk_design_system_formbuilder/containers/check_boxes_fieldset.rb
316
315
  - lib/govuk_design_system_formbuilder/containers/fieldset.rb
@@ -331,13 +330,13 @@ files:
331
330
  - lib/govuk_design_system_formbuilder/elements/hint.rb
332
331
  - lib/govuk_design_system_formbuilder/elements/inputs/email.rb
333
332
  - lib/govuk_design_system_formbuilder/elements/inputs/number.rb
334
- - lib/govuk_design_system_formbuilder/elements/inputs/password.rb
335
333
  - lib/govuk_design_system_formbuilder/elements/inputs/phone.rb
336
334
  - lib/govuk_design_system_formbuilder/elements/inputs/text.rb
337
335
  - lib/govuk_design_system_formbuilder/elements/inputs/url.rb
338
336
  - lib/govuk_design_system_formbuilder/elements/label.rb
339
337
  - lib/govuk_design_system_formbuilder/elements/legend.rb
340
338
  - lib/govuk_design_system_formbuilder/elements/null.rb
339
+ - lib/govuk_design_system_formbuilder/elements/password.rb
341
340
  - lib/govuk_design_system_formbuilder/elements/radios/collection.rb
342
341
  - lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb
343
342
  - lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb
@@ -1,46 +0,0 @@
1
- module GOVUKDesignSystemFormBuilder
2
- module Containers
3
- class CharacterCount < Base
4
- def initialize(builder, max_words:, max_chars:, threshold:)
5
- super(builder, nil, nil)
6
-
7
- fail ArgumentError, 'limit can be words or chars' if max_words && max_chars
8
-
9
- @max_words = max_words
10
- @max_chars = max_chars
11
- @threshold = threshold
12
- end
13
-
14
- def html(&block)
15
- return yield unless limit?
16
-
17
- tag.div(**options, &block)
18
- end
19
-
20
- private
21
-
22
- def options
23
- {
24
- class: %(#{brand}-character-count),
25
- data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
26
- }
27
- end
28
-
29
- def limit
30
- if @max_words
31
- { maxwords: @max_words }
32
- elsif @max_chars
33
- { maxlength: @max_chars }
34
- end
35
- end
36
-
37
- def threshold
38
- { threshold: @threshold }
39
- end
40
-
41
- def limit?
42
- @max_words || @max_chars
43
- end
44
- end
45
- end
46
- end
@@ -1,20 +0,0 @@
1
- module GOVUKDesignSystemFormBuilder
2
- module Elements
3
- module Inputs
4
- class Password < Base
5
- include Traits::Input
6
- include Traits::Error
7
- include Traits::Hint
8
- include Traits::Label
9
- include Traits::Supplemental
10
- include Traits::HTMLAttributes
11
-
12
- private
13
-
14
- def builder_method
15
- :password_field
16
- end
17
- end
18
- end
19
- end
20
- end