govuk_design_system_formbuilder 1.1.11 → 1.2.0b1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/govuk_design_system_formbuilder/base.rb +12 -0
  3. data/lib/govuk_design_system_formbuilder/builder.rb +1 -1
  4. data/lib/govuk_design_system_formbuilder/containers/character_count.rb +2 -2
  5. data/lib/govuk_design_system_formbuilder/containers/check_boxes.rb +5 -3
  6. data/lib/govuk_design_system_formbuilder/containers/fieldset.rb +10 -9
  7. data/lib/govuk_design_system_formbuilder/containers/form_group.rb +4 -2
  8. data/lib/govuk_design_system_formbuilder/containers/radios.rb +7 -5
  9. data/lib/govuk_design_system_formbuilder/elements/check_boxes/collection_check_box.rb +4 -2
  10. data/lib/govuk_design_system_formbuilder/elements/check_boxes/fieldset_check_box.rb +5 -3
  11. data/lib/govuk_design_system_formbuilder/elements/check_boxes/label.rb +3 -1
  12. data/lib/govuk_design_system_formbuilder/elements/date.rb +9 -7
  13. data/lib/govuk_design_system_formbuilder/elements/error_message.rb +4 -2
  14. data/lib/govuk_design_system_formbuilder/elements/error_summary.rb +4 -4
  15. data/lib/govuk_design_system_formbuilder/elements/file.rb +4 -2
  16. data/lib/govuk_design_system_formbuilder/elements/hint.rb +5 -3
  17. data/lib/govuk_design_system_formbuilder/elements/inputs/email.rb +2 -0
  18. data/lib/govuk_design_system_formbuilder/elements/inputs/number.rb +2 -0
  19. data/lib/govuk_design_system_formbuilder/elements/inputs/password.rb +2 -0
  20. data/lib/govuk_design_system_formbuilder/elements/inputs/phone.rb +2 -0
  21. data/lib/govuk_design_system_formbuilder/elements/inputs/text.rb +2 -0
  22. data/lib/govuk_design_system_formbuilder/elements/inputs/url.rb +2 -0
  23. data/lib/govuk_design_system_formbuilder/elements/label.rb +11 -9
  24. data/lib/govuk_design_system_formbuilder/elements/radios/collection_radio_button.rb +4 -2
  25. data/lib/govuk_design_system_formbuilder/elements/radios/fieldset_radio_button.rb +5 -3
  26. data/lib/govuk_design_system_formbuilder/elements/select.rb +4 -2
  27. data/lib/govuk_design_system_formbuilder/elements/submit.rb +7 -6
  28. data/lib/govuk_design_system_formbuilder/elements/text_area.rb +10 -4
  29. data/lib/govuk_design_system_formbuilder/traits/input.rb +14 -14
  30. data/lib/govuk_design_system_formbuilder/version.rb +1 -1
  31. data/lib/govuk_design_system_formbuilder.rb +5 -0
  32. metadata +32 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9fcd048d44600ed48957b2c4d18d67a9d705878f897bc8206576f3a7ffebe37
4
- data.tar.gz: 2958f99bb9a5d74432da272a4a7bae6563ec5c898626fcfe276e9385b0e860dc
3
+ metadata.gz: b26402e9e41729882759af55f46d0ca77021301c3e47d1fdf71674a5b7e10635
4
+ data.tar.gz: 29f61cc4bb6086cf19c08f57648be973aab134ef8a0b1ebded5a175cb8f79564
5
5
  SHA512:
6
- metadata.gz: 42f2696075a68ee286b0e8f45980247aabbbb5da7c64e57f90ef06858efce3ee2d80c551753aaa50c454567bdb1abbe1947a1c864639a7e5453f67c0799dd3f5
7
- data.tar.gz: 7354580f9774a3b35e163c64e2531da89be06a1e1a8f6b535fcb38e215350953c20b5339ff9bf9cd6e8ac40dd25a2d505eacd51c0fc47d2baa5c384445c51ef3
6
+ metadata.gz: d5c38d0cc478cddeb01c6624abb8b4bced314197bd6e1f788a36d94f8ca5c62d2c19a2da96a7e7a3c2555af994a07cf3b10d4ed83dd270135e3af86157c11f6f
7
+ data.tar.gz: 95ca19e5a70cfc2f163e3ffadbd59b9644dc9f471723f468b56ea3e2d8a15c10761f651fc522ccf220a20c7b607083d3a0d71048d2ba240d5562e2cb06b2fae1
@@ -1,4 +1,12 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
+ module PrefixableArray
3
+ refine Array do
4
+ def prefix(text, delimiter: '-')
5
+ map { |item| text + delimiter + item }
6
+ end
7
+ end
8
+ end
9
+
2
10
  class Base
3
11
  delegate :capture, :content_tag, :safe_join, :tag, :raw, :link_to, to: :@builder
4
12
  delegate :config, to: GOVUKDesignSystemFormBuilder
@@ -12,6 +20,10 @@ module GOVUKDesignSystemFormBuilder
12
20
 
13
21
  private
14
22
 
23
+ def brand(override = nil)
24
+ override || config.brand
25
+ end
26
+
15
27
  # returns the id value used for the input
16
28
  #
17
29
  # @note field_id is overridden so that the error summary can link to the
@@ -660,7 +660,7 @@ module GOVUKDesignSystemFormBuilder
660
660
  # @see https://design-system.service.gov.uk/components/fieldset/ GOV.UK fieldset
661
661
  # @return [ActiveSupport::SafeBuffer] HTML output
662
662
  def govuk_fieldset(legend: { text: 'Fieldset heading' }, described_by: nil, &block)
663
- Containers::Fieldset.new(self, legend: legend, described_by: described_by, &block).html
663
+ Containers::Fieldset.new(self, legend: legend, described_by: described_by).html(&block)
664
664
  end
665
665
 
666
666
  # Generates an input of type +file+
@@ -16,8 +16,8 @@ module GOVUKDesignSystemFormBuilder
16
16
 
17
17
  content_tag(
18
18
  'div',
19
- class: 'govuk-character-count',
20
- data: { module: 'govuk-character-count' }.merge(**limit, **threshold).compact
19
+ class: %(#{brand}-character-count),
20
+ data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact
21
21
  ) do
22
22
  yield
23
23
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class CheckBoxes < Base
4
+ using PrefixableArray
5
+
4
6
  def initialize(builder, small:, classes: nil)
5
7
  @builder = builder
6
8
  @small = small
@@ -8,7 +10,7 @@ module GOVUKDesignSystemFormBuilder
8
10
  end
9
11
 
10
12
  def html
11
- content_tag('div', class: check_boxes_classes, data: { module: 'govuk-checkboxes' }) do
13
+ content_tag('div', class: check_boxes_classes, data: { module: %(#{brand}-checkboxes) }) do
12
14
  yield
13
15
  end
14
16
  end
@@ -16,8 +18,8 @@ module GOVUKDesignSystemFormBuilder
16
18
  private
17
19
 
18
20
  def check_boxes_classes
19
- %w(govuk-checkboxes).tap do |c|
20
- c.push('govuk-checkboxes--small') if @small
21
+ %w(checkboxes).prefix(brand).tap do |c|
22
+ c.push(%(#{brand}-checkboxes--small)) if @small
21
23
  c.push(@classes) if @classes
22
24
  end
23
25
  end
@@ -1,12 +1,14 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class Fieldset < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Localisation
5
7
 
6
8
  LEGEND_SIZES = %w(xl l m s).freeze
7
9
 
8
- def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil, &block)
9
- super(builder, object_name, attribute_name, &block)
10
+ def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, described_by: nil)
11
+ super(builder, object_name, attribute_name)
10
12
 
11
13
  @legend = legend_defaults.merge(legend)
12
14
  @described_by = described_by(described_by)
@@ -15,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
15
17
 
16
18
  def html
17
19
  content_tag('fieldset', class: fieldset_classes, aria: { describedby: @described_by }) do
18
- safe_join([build_legend, (@block_content || yield)])
20
+ safe_join([build_legend, yield])
19
21
  end
20
22
  end
21
23
 
@@ -43,21 +45,20 @@ module GOVUKDesignSystemFormBuilder
43
45
  end
44
46
 
45
47
  def fieldset_classes
46
- %w(govuk-fieldset)
48
+ %w(fieldset).prefix(brand)
47
49
  end
48
50
 
49
51
  def legend_classes
50
52
  size = @legend.dig(:size)
51
53
  fail "invalid size '#{size}', must be #{LEGEND_SIZES.join(', ')}" unless size.in?(LEGEND_SIZES)
52
54
 
53
- classes = %W(govuk-fieldset__legend govuk-fieldset__legend--#{size})
54
- classes.push('govuk-visually-hidden') if @legend.dig(:hidden)
55
-
56
- classes
55
+ [%(fieldset__legend), %(fieldset__legend--#{size})].prefix(brand).tap do |classes|
56
+ classes.push(%(#{brand}-visually-hidden)) if @legend.dig(:hidden)
57
+ end
57
58
  end
58
59
 
59
60
  def legend_heading_classes
60
- %(govuk-fieldset__heading)
61
+ %w(fieldset__heading).prefix(brand)
61
62
  end
62
63
  end
63
64
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class FormGroup < Base
4
+ using PrefixableArray
5
+
4
6
  def initialize(builder, object_name, attribute_name)
5
7
  super(builder, object_name, attribute_name)
6
8
  end
@@ -14,8 +16,8 @@ module GOVUKDesignSystemFormBuilder
14
16
  private
15
17
 
16
18
  def form_group_classes
17
- %w(govuk-form-group).tap do |classes|
18
- classes.push('govuk-form-group--error') if has_errors?
19
+ %w(form-group).prefix(brand).tap do |classes|
20
+ classes.push(%(#{brand}-form-group--error)) if has_errors?
19
21
  end
20
22
  end
21
23
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Containers
3
3
  class Radios < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Hint
5
7
 
6
8
  def initialize(builder, inline:, small:, classes:)
@@ -11,7 +13,7 @@ module GOVUKDesignSystemFormBuilder
11
13
  end
12
14
 
13
15
  def html
14
- content_tag('div', class: radios_classes, data: { module: 'govuk-radios' }) do
16
+ content_tag('div', class: radios_classes, data: { module: %(#{brand}-radios) }) do
15
17
  yield
16
18
  end
17
19
  end
@@ -19,10 +21,10 @@ module GOVUKDesignSystemFormBuilder
19
21
  private
20
22
 
21
23
  def radios_classes
22
- %w(govuk-radios).tap do |c|
23
- c.push('govuk-radios--inline') if @inline
24
- c.push('govuk-radios--small') if @small
25
- c.push(@classes) if @classes
24
+ %w(radios).prefix(brand).tap do |c|
25
+ c.push(%(#{brand}-radios--inline)) if @inline
26
+ c.push(%(#{brand}-radios--small)) if @small
27
+ c.push(@classes) if @classes
26
28
  end
27
29
  end
28
30
  end
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module CheckBoxes
4
4
  class CollectionCheckBox < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::CollectionItem
6
8
  include Traits::Hint
7
9
 
@@ -16,12 +18,12 @@ module GOVUKDesignSystemFormBuilder
16
18
  end
17
19
 
18
20
  def html
19
- content_tag('div', class: 'govuk-checkboxes__item') do
21
+ content_tag('div', class: %(#{brand}-checkboxes__item)) do
20
22
  safe_join(
21
23
  [
22
24
  @checkbox.check_box(
23
25
  id: field_id(link_errors: @link_errors),
24
- class: "govuk-checkboxes__input",
26
+ class: %(#{brand}-checkboxes__input),
25
27
  aria: { describedby: hint_id }
26
28
  ),
27
29
  label_element.html,
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module CheckBoxes
4
4
  class FieldsetCheckBox < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Hint
6
8
  include Traits::Conditional
7
9
 
@@ -23,7 +25,7 @@ module GOVUKDesignSystemFormBuilder
23
25
  def html
24
26
  safe_join(
25
27
  [
26
- content_tag('div', class: 'govuk-checkboxes__item') do
28
+ content_tag('div', class: %(#{brand}-checkboxes__item)) do
27
29
  safe_join(
28
30
  [
29
31
  input,
@@ -63,11 +65,11 @@ module GOVUKDesignSystemFormBuilder
63
65
  end
64
66
 
65
67
  def conditional_classes
66
- %w(govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden)
68
+ %w(checkboxes__conditional checkboxes__conditional--hidden).prefix(brand)
67
69
  end
68
70
 
69
71
  def check_box_classes
70
- %w(govuk-checkboxes__input)
72
+ %w(checkboxes__input).prefix(brand)
71
73
  end
72
74
  end
73
75
  end
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module CheckBoxes
4
4
  class Label < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Localisation
6
8
 
7
9
  def initialize(builder, object_name, attribute_name, checkbox, value:, link_errors: true)
@@ -21,7 +23,7 @@ module GOVUKDesignSystemFormBuilder
21
23
  private
22
24
 
23
25
  def label_classes
24
- %w(govuk-label govuk-checkboxes__label)
26
+ %w(label checkboxes__label).prefix(brand)
25
27
  end
26
28
  end
27
29
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Date < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Error
5
7
  include Traits::Hint
6
8
  include Traits::Supplemental
@@ -24,7 +26,7 @@ module GOVUKDesignSystemFormBuilder
24
26
  supplemental_content.html,
25
27
  hint_element.html,
26
28
  error_element.html,
27
- content_tag('div', class: 'govuk-date-input') do
29
+ content_tag('div', class: %(#{brand}-date-input)) do
28
30
  safe_join([day, month, year])
29
31
  end
30
32
  ]
@@ -56,8 +58,8 @@ module GOVUKDesignSystemFormBuilder
56
58
  def date_input_item(segment, width: 2, link_errors: false)
57
59
  value = @builder.object.try(@attribute_name).try(segment)
58
60
 
59
- content_tag('div', class: %w(govuk-date-input__item)) do
60
- content_tag('div', class: %w(govuk-form-group)) do
61
+ content_tag('div', class: %w(date-input__item).prefix(brand)) do
62
+ content_tag('div', class: %w(form-group).prefix(brand)) do
61
63
  safe_join(
62
64
  [
63
65
  tag.label(
@@ -83,14 +85,14 @@ module GOVUKDesignSystemFormBuilder
83
85
  end
84
86
 
85
87
  def date_input_classes(width)
86
- %w(govuk-input govuk-date-input__input).tap do |classes|
87
- classes.push("govuk-input--width-#{width}")
88
- classes.push("govuk-input--error") if has_errors?
88
+ %w(input date-input__input).prefix(brand).tap do |classes|
89
+ classes.push(%(#{brand}-input--width-#{width}))
90
+ classes.push(%(#{brand}-input--error)) if has_errors?
89
91
  end
90
92
  end
91
93
 
92
94
  def date_input_label_classes
93
- %w(govuk-label govuk-date-input__label)
95
+ %w(label date-input__label).prefix(brand)
94
96
  end
95
97
 
96
98
  # if the field has errors we want the govuk_error_summary to
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class ErrorMessage < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Error
5
7
 
6
8
  def initialize(builder, object_name, attribute_name)
@@ -10,10 +12,10 @@ module GOVUKDesignSystemFormBuilder
10
12
  def html
11
13
  return nil unless has_errors?
12
14
 
13
- content_tag('span', class: 'govuk-error-message', id: error_id) do
15
+ content_tag('span', class: %(#{brand}-error-message), id: error_id) do
14
16
  safe_join(
15
17
  [
16
- tag.span('Error: ', class: 'govuk-visually-hidden'),
18
+ tag.span('Error: ', class: %(#{brand}-visually-hidden)),
17
19
  message
18
20
  ]
19
21
  )
@@ -17,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
17
17
  [
18
18
  tag.h2(@title, id: error_summary_title_id, class: summary_class('title')),
19
19
  content_tag('div', class: summary_class('body')) do
20
- content_tag('ul', class: ['govuk-list', summary_class('list')]) do
20
+ content_tag('ul', class: [%(#{brand}-list), summary_class('list')]) do
21
21
  safe_join(
22
22
  @builder.object.errors.messages.map do |attribute, messages|
23
23
  error_list_item(attribute, messages.first)
@@ -50,9 +50,9 @@ module GOVUKDesignSystemFormBuilder
50
50
 
51
51
  def summary_class(part = nil)
52
52
  if part
53
- 'govuk-error-summary'.concat('__', part)
53
+ %(#{brand}-error-summary).concat('__', part)
54
54
  else
55
- 'govuk-error-summary'
55
+ %(#{brand}-error-summary)
56
56
  end
57
57
  end
58
58
 
@@ -73,7 +73,7 @@ module GOVUKDesignSystemFormBuilder
73
73
  tabindex: -1,
74
74
  role: 'alert',
75
75
  data: {
76
- module: 'govuk-error-summary'
76
+ module: %(#{brand}-error-summary)
77
77
  },
78
78
  aria: {
79
79
  labelledby: error_summary_title_id
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class File < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Error
5
7
  include Traits::Hint
6
8
  include Traits::Label
@@ -37,8 +39,8 @@ module GOVUKDesignSystemFormBuilder
37
39
  private
38
40
 
39
41
  def file_classes
40
- %w(govuk-file-upload).tap do |c|
41
- c.push('govuk-file-upload--error') if has_errors?
42
+ %w(file-upload).prefix(brand).tap do |c|
43
+ c.push(%(#{brand}-file-upload--error)) if has_errors?
42
44
  end
43
45
  end
44
46
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Hint < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Hint
5
7
  include Traits::Localisation
6
8
 
@@ -29,15 +31,15 @@ module GOVUKDesignSystemFormBuilder
29
31
  end
30
32
 
31
33
  def hint_classes
32
- %w(govuk-hint).push(@radio_class, @checkbox_class).compact
34
+ %w(hint).prefix(brand).push(@radio_class, @checkbox_class).compact
33
35
  end
34
36
 
35
37
  def radio_class(radio)
36
- radio ? 'govuk-radios__hint' : nil
38
+ radio ? %(#{brand}-radios__hint) : nil
37
39
  end
38
40
 
39
41
  def checkbox_class(checkbox)
40
- checkbox ? 'govuk-checkboxes__hint' : nil
42
+ checkbox ? %(#{brand}-checkboxes__hint) : nil
41
43
  end
42
44
  end
43
45
  end
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Email < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Input
6
8
  include Traits::Error
7
9
  include Traits::Hint
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Number < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Input
6
8
  include Traits::Error
7
9
  include Traits::Hint
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Password < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Input
6
8
  include Traits::Error
7
9
  include Traits::Hint
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Phone < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Input
6
8
  include Traits::Error
7
9
  include Traits::Hint
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class Text < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Input
6
8
  include Traits::Error
7
9
  include Traits::Hint
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Inputs
4
4
  class URL < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Input
6
8
  include Traits::Error
7
9
  include Traits::Hint
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Label < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Localisation
5
7
 
6
8
  def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true)
@@ -19,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
19
21
  return nil if @text.blank?
20
22
 
21
23
  if @tag.present?
22
- content_tag(@tag, class: 'govuk-label-wrapper') { build_label }
24
+ content_tag(@tag, class: %(#{brand}-label-wrapper)) { build_label }
23
25
  else
24
26
  build_label
25
27
  end
@@ -32,7 +34,7 @@ module GOVUKDesignSystemFormBuilder
32
34
  @attribute_name,
33
35
  value: @value,
34
36
  for: field_id(link_errors: @link_errors),
35
- class: %w(govuk-label).push(@size_class, @weight_class, @radio_class, @checkbox_class).compact
37
+ class: %w(label).prefix(brand).push(@size_class, @weight_class, @radio_class, @checkbox_class).compact
36
38
  ) do
37
39
  @text
38
40
  end
@@ -42,26 +44,26 @@ module GOVUKDesignSystemFormBuilder
42
44
  text = [option_text, localised_text(:label), @attribute_name.capitalize].compact.first.to_s
43
45
 
44
46
  if hidden
45
- tag.span(text, class: %w(govuk-visually-hidden))
47
+ tag.span(text, class: %w(visually-hidden).prefix(brand))
46
48
  else
47
49
  text
48
50
  end
49
51
  end
50
52
 
51
53
  def radio_class(radio)
52
- radio ? 'govuk-radios__label' : nil
54
+ radio ? %(#{brand}-radios__label) : nil
53
55
  end
54
56
 
55
57
  def checkbox_class(checkbox)
56
- checkbox ? 'govuk-checkboxes__label' : nil
58
+ checkbox ? %(#{brand}-checkboxes__label) : nil
57
59
  end
58
60
 
59
61
  def label_size_class(size)
60
62
  case size
61
- when 'xl' then "govuk-label--xl"
62
- when 'l' then "govuk-label--l"
63
- when 'm' then "govuk-label--m"
64
- when 's' then "govuk-label--s"
63
+ when 'xl' then %(#{brand}-label--xl)
64
+ when 'l' then %(#{brand}-label--l)
65
+ when 'm' then %(#{brand}-label--m)
66
+ when 's' then %(#{brand}-label--s)
65
67
  when nil then nil
66
68
  else
67
69
  fail "invalid size '#{size}', must be xl, l, m, s or nil"
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Radios
4
4
  class CollectionRadioButton < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Hint
6
8
  include Traits::CollectionItem
7
9
 
@@ -21,7 +23,7 @@ module GOVUKDesignSystemFormBuilder
21
23
  end
22
24
 
23
25
  def html
24
- content_tag('div', class: 'govuk-radios__item') do
26
+ content_tag('div', class: %(#{brand}-radios__item)) do
25
27
  safe_join(
26
28
  [
27
29
  @builder.radio_button(
@@ -29,7 +31,7 @@ module GOVUKDesignSystemFormBuilder
29
31
  @value,
30
32
  id: field_id(link_errors: @link_errors),
31
33
  aria: { describedby: hint_id },
32
- class: %w(govuk-radios__input)
34
+ class: %w(radios__input).prefix(brand)
33
35
  ),
34
36
  label_element.html,
35
37
  hint_element.html
@@ -2,6 +2,8 @@ module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  module Radios
4
4
  class FieldsetRadioButton < Base
5
+ using PrefixableArray
6
+
5
7
  include Traits::Hint
6
8
  include Traits::Conditional
7
9
 
@@ -22,7 +24,7 @@ module GOVUKDesignSystemFormBuilder
22
24
  def html
23
25
  safe_join(
24
26
  [
25
- content_tag('div', class: 'govuk-radios__item') do
27
+ content_tag('div', class: %(#{brand}-radios__item)) do
26
28
  safe_join(
27
29
  [
28
30
  input,
@@ -53,12 +55,12 @@ module GOVUKDesignSystemFormBuilder
53
55
  id: field_id(link_errors: @link_errors),
54
56
  aria: { describedby: hint_id },
55
57
  data: { 'aria-controls' => @conditional_id },
56
- class: %w(govuk-radios__input)
58
+ class: %w(radios__input).prefix(brand)
57
59
  )
58
60
  end
59
61
 
60
62
  def conditional_classes
61
- %w(govuk-radios__conditional govuk-radios__conditional--hidden)
63
+ %w(radios__conditional radios__conditional--hidden).prefix(brand)
62
64
  end
63
65
  end
64
66
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Select < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Error
5
7
  include Traits::Label
6
8
  include Traits::Hint
@@ -50,8 +52,8 @@ module GOVUKDesignSystemFormBuilder
50
52
  end
51
53
 
52
54
  def select_classes
53
- %w(govuk-select).tap do |classes|
54
- classes.push('govuk-select--error') if has_errors?
55
+ %w(select).prefix(brand).tap do |classes|
56
+ classes.push(%(#{brand}-select--error)) if has_errors?
55
57
  end
56
58
  end
57
59
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class Submit < Base
4
+ using PrefixableArray
5
+
4
6
  def initialize(builder, text, warning:, secondary:, classes:, prevent_double_click:, validate:, &block)
5
7
  fail ArgumentError, 'buttons can be warning or secondary' if warning && secondary
6
8
 
@@ -19,7 +21,7 @@ module GOVUKDesignSystemFormBuilder
19
21
  [
20
22
  @builder.submit(
21
23
  @text,
22
- class: %w(govuk-button).push(
24
+ class: %w(button).prefix(brand).push(
23
25
  warning_class,
24
26
  secondary_class,
25
27
  @classes,
@@ -35,23 +37,22 @@ module GOVUKDesignSystemFormBuilder
35
37
  private
36
38
 
37
39
  def warning_class
38
- 'govuk-button--warning' if @warning
40
+ %(#{brand}-button--warning) if @warning
39
41
  end
40
42
 
41
43
  def secondary_class
42
- 'govuk-button--secondary' if @secondary
44
+ %(#{brand}-button--secondary) if @secondary
43
45
  end
44
46
 
45
47
  def padding_class(content_present)
46
- 'govuk-!-margin-right-1' if content_present
48
+ %(#{brand}-!-margin-right-1) if content_present
47
49
  end
48
50
 
49
51
  def extra_args
50
52
  {
51
53
  formnovalidate: !@validate,
52
54
  data: {
53
- module: 'govuk-button',
54
- 'prevent-double-click' => @prevent_double_click
55
+ module: %(#{brand}-button), 'prevent-double-click' => @prevent_double_click
55
56
  }.select { |_k, v| v.present? }
56
57
  }
57
58
  end
@@ -1,6 +1,8 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
2
  module Elements
3
3
  class TextArea < Base
4
+ using PrefixableArray
5
+
4
6
  include Traits::Error
5
7
  include Traits::Hint
6
8
  include Traits::Label
@@ -48,9 +50,9 @@ module GOVUKDesignSystemFormBuilder
48
50
  private
49
51
 
50
52
  def govuk_textarea_classes
51
- %w(govuk-textarea).tap do |classes|
52
- classes.push('govuk-textarea--error') if has_errors?
53
- classes.push('govuk-js-character-count') if limit?
53
+ %w(textarea).prefix(brand).tap do |classes|
54
+ classes.push(%(#{brand}-textarea--error)) if has_errors?
55
+ classes.push(%(#{brand}-js-character-count)) if limit?
54
56
  end
55
57
  end
56
58
 
@@ -69,11 +71,15 @@ module GOVUKDesignSystemFormBuilder
69
71
  def limit_description
70
72
  return nil unless limit?
71
73
 
72
- content_tag('span', id: limit_id, class: %w(govuk-hint govuk-character-count__message), aria: { live: 'polite' }) do
74
+ content_tag('span', id: limit_id, class: limit_description_classes, aria: { live: 'polite' }) do
73
75
  "You can enter up to #{limit_quantity} #{limit_type}"
74
76
  end
75
77
  end
76
78
 
79
+ def limit_description_classes
80
+ %w(hint character-count__message).prefix(brand)
81
+ end
82
+
77
83
  def limit_quantity
78
84
  @max_words || @max_chars
79
85
  end
@@ -40,11 +40,11 @@ module GOVUKDesignSystemFormBuilder
40
40
  private
41
41
 
42
42
  def input_classes
43
- %w(govuk-input).push(width_classes, error_classes).compact
43
+ [%(#{brand}-input)].push(width_classes, error_classes).compact
44
44
  end
45
45
 
46
46
  def error_classes
47
- 'govuk-input--error' if has_errors?
47
+ %(#{brand}-input--error) if has_errors?
48
48
  end
49
49
 
50
50
  def width_classes
@@ -53,20 +53,20 @@ module GOVUKDesignSystemFormBuilder
53
53
  case @width
54
54
 
55
55
  # fixed (character) widths
56
- when 20 then 'govuk-input--width-20'
57
- when 10 then 'govuk-input--width-10'
58
- when 5 then 'govuk-input--width-5'
59
- when 4 then 'govuk-input--width-4'
60
- when 3 then 'govuk-input--width-3'
61
- when 2 then 'govuk-input--width-2'
56
+ when 20 then %(#{brand}-input--width-20)
57
+ when 10 then %(#{brand}-input--width-10)
58
+ when 5 then %(#{brand}-input--width-5)
59
+ when 4 then %(#{brand}-input--width-4)
60
+ when 3 then %(#{brand}-input--width-3)
61
+ when 2 then %(#{brand}-input--width-2)
62
62
 
63
63
  # fluid widths
64
- when 'full' then 'govuk-!-width-full'
65
- when 'three-quarters' then 'govuk-!-width-three-quarters'
66
- when 'two-thirds' then 'govuk-!-width-two-thirds'
67
- when 'one-half' then 'govuk-!-width-one-half'
68
- when 'one-third' then 'govuk-!-width-one-third'
69
- when 'one-quarter' then 'govuk-!-width-one-quarter'
64
+ when 'full' then %(#{brand}-!-width-full)
65
+ when 'three-quarters' then %(#{brand}-!-width-three-quarters)
66
+ when 'two-thirds' then %(#{brand}-!-width-two-thirds)
67
+ when 'one-half' then %(#{brand}-!-width-one-half)
68
+ when 'one-third' then %(#{brand}-!-width-one-third)
69
+ when 'one-quarter' then %(#{brand}-!-width-one-quarter)
70
70
 
71
71
  else fail(ArgumentError, "invalid width '#{@width}'")
72
72
  end
@@ -1,3 +1,3 @@
1
1
  module GOVUKDesignSystemFormBuilder
2
- VERSION = '1.1.11'.freeze
2
+ VERSION = '1.2.0b1'.freeze
3
3
  end
@@ -11,6 +11,9 @@ module GOVUKDesignSystemFormBuilder
11
11
 
12
12
  # Default form builder configuration
13
13
  #
14
+ # * +:brand+ sets the value used to prefix all classes, used to allow the
15
+ # builder to be branded for alternative (similar) design systems.
16
+ #
14
17
  # * +:default_legend_size+ controls the default size of legend text.
15
18
  # Can be either +xl+, +l+, +m+ or +s+.
16
19
  #
@@ -38,6 +41,8 @@ module GOVUKDesignSystemFormBuilder
38
41
  # particular context, allowing them to be independently customised.
39
42
  # ===
40
43
  DEFAULTS = {
44
+ brand: 'govuk',
45
+
41
46
  default_legend_size: 'm',
42
47
  default_legend_tag: 'h1',
43
48
  default_submit_button_text: 'Continue',
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: 1.1.11
4
+ version: 1.2.0b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -142,6 +142,34 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: 0.17.1
145
+ - !ruby/object:Gem::Dependency
146
+ name: adsf
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 1.4.2
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: 1.4.2
159
+ - !ruby/object:Gem::Dependency
160
+ name: adsf-live
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: 1.4.2
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: 1.4.2
145
173
  - !ruby/object:Gem::Dependency
146
174
  name: htmlbeautifier
147
175
  requirement: !ruby/object:Gem::Requirement
@@ -311,9 +339,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
311
339
  version: '0'
312
340
  required_rubygems_version: !ruby/object:Gem::Requirement
313
341
  requirements:
314
- - - ">="
342
+ - - ">"
315
343
  - !ruby/object:Gem::Version
316
- version: '0'
344
+ version: 1.3.1
317
345
  requirements: []
318
346
  rubygems_version: 3.0.3
319
347
  signing_key: