govuk_design_system_formbuilder 5.2.0 → 5.3.1

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: ee29cb5609e4c2624e66de9a8f4458f4998eb999078635e4b8be3028fe4d07ed
4
- data.tar.gz: 8a4d5a2e0190649716e5b2f20612f410a227b551ff1fc1654fd0ff2086cef429
3
+ metadata.gz: 51a139b376822ea5bfdbeef995d5b8daef3d0a67fa6d035165253dbfafe2496f
4
+ data.tar.gz: 8a2a50e44d2ecf48edba85535cf876f95fc6a22f89188a219edba6c97570f5eb
5
5
  SHA512:
6
- metadata.gz: 6c382d9cc75632a6fc44353a94d0fb91662c3fd4da19dc28b25af151f7bbcfd120d22c7d2eda10f85f7cfa1010b800bfb7ab3d1d8f4b4644381b1f4dcdae2afb
7
- data.tar.gz: dca5669205b2086610ef538c4e0d1f37f068787489aa1363599e4d2482c781763725315f5701dbf834759b4bacc361d32bca892b930d11616a85ebc2253dc18e
6
+ metadata.gz: 6c1052d946ea83b6d301c1acf02e6c9b6f8da14fd70409ef91bd0908d47fc57e25e130e214e12b0fa22fb7fe63adf85b809a76d8f78708f4e1da12990bfa0fd2
7
+ data.tar.gz: b543d521fe7fd10597942fc70c8a45513d876e28a624e3064f51d6e7a303031cec3e5e01e66e399717eacae5a1a714fcc0fb4c3c4981ffb62ac3edd18a33a2a9
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
@@ -8,7 +8,6 @@ module GOVUKDesignSystemFormBuilder
8
8
  include Traits::Supplemental
9
9
  include Traits::HTMLClasses
10
10
 
11
- SEGMENTS = { day: '3i', month: '2i', year: '1i' }.freeze
12
11
  MULTIPARAMETER_KEY = { day: 3, month: 2, year: 1 }.freeze
13
12
 
14
13
  def initialize(builder, object_name, attribute_name, legend:, caption:, hint:, omit_day:, maxlength_enabled:, form_group:, date_of_birth: false, **kwargs, &block)
@@ -34,6 +33,10 @@ module GOVUKDesignSystemFormBuilder
34
33
 
35
34
  private
36
35
 
36
+ def segments
37
+ config.default_date_segments
38
+ end
39
+
37
40
  def fieldset_options
38
41
  { legend: @legend, caption: @caption, described_by: [error_id, hint_id, supplemental_id] }
39
42
  end
@@ -136,7 +139,7 @@ module GOVUKDesignSystemFormBuilder
136
139
  if has_errors? && link_errors
137
140
  field_id(link_errors:)
138
141
  else
139
- [@object_name, @attribute_name, SEGMENTS.fetch(segment)].join("_")
142
+ [@object_name, @attribute_name, segments.fetch(segment)].join("_")
140
143
  end
141
144
  end
142
145
 
@@ -145,7 +148,7 @@ module GOVUKDesignSystemFormBuilder
145
148
  "%<object_name>s[%<input_name>s(%<segment>s)]",
146
149
  object_name: @object_name,
147
150
  input_name: @attribute_name,
148
- segment: SEGMENTS.fetch(segment)
151
+ segment: segments.fetch(segment)
149
152
  )
150
153
  end
151
154
 
@@ -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.2.0'.freeze
2
+ VERSION = '5.3.1'.freeze
3
3
  end
@@ -27,16 +27,17 @@ module GOVUKDesignSystemFormBuilder
27
27
  # * +:default_submit_button_text+ sets the value assigned to +govuk_submit+,
28
28
  # defaults to 'Continue'.
29
29
  #
30
+ # * +:default_date_segments+ allows the date segments used by Rails'
31
+ # multiparameter attributes to be configured. This is useful if you want to
32
+ # override the standard behaviour where Rails tries to cast the values
33
+ # into a +Date+. Defaults to +{ day: '3i', month: '2i', year: '1i' }+
34
+ #
30
35
  # * +:default_radio_divider_text+ sets the text automatically added to the
31
36
  # radio button divider, defaults to 'or'
32
37
  #
33
38
  # * +:default_check_box_divider_text+ sets the text automatically added to the
34
39
  # checkbox divider, defaults to 'or'
35
40
  #
36
- # * +:default_submit_button_text+ sets the text used to divide the last radio
37
- # button in radio button fieldsets. As per the GOV.UK Design System spec,
38
- # it defaults to 'or'.
39
- #
40
41
  # * +:default_collection_check_boxes_include_hidden+ controls whether or not
41
42
  # a hidden field is added when rendering a collection of check boxes
42
43
  #
@@ -92,6 +93,7 @@ module GOVUKDesignSystemFormBuilder
92
93
  default_legend_tag: nil,
93
94
  default_caption_size: 'm',
94
95
  default_submit_button_text: 'Continue',
96
+ default_date_segments: { day: '3i', month: '2i', year: '1i' },
95
97
  default_radio_divider_text: 'or',
96
98
  default_check_box_divider_text: 'or',
97
99
  default_error_summary_title: 'There is a problem',
@@ -102,7 +104,12 @@ module GOVUKDesignSystemFormBuilder
102
104
  default_collection_radio_buttons_include_hidden: true,
103
105
  default_collection_radio_buttons_auto_bold_labels: true,
104
106
  default_submit_validate: false,
105
-
107
+ default_show_password_text: "Show",
108
+ default_hide_password_text: "Hide",
109
+ default_show_password_aria_label_text: "Show password",
110
+ default_hide_password_aria_label_text: "Hide password",
111
+ default_password_shown_announcement_text: "Your password is visible",
112
+ default_password_hidden_announcement_text: "Your password is hidden",
106
113
  localisation_schema_fallback: %i(helpers __context__),
107
114
  localisation_schema_label: nil,
108
115
  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.2.0
4
+ version: 5.3.1
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-22 00:00:00.000000000 Z
11
+ date: 2024-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-attributes-utils
@@ -134,14 +134,14 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: 4.14.0
137
+ version: 4.16.0
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: 4.14.0
144
+ version: 4.16.0
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: simplecov
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -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