katalyst-govuk-formbuilder 1.6.0 → 1.7.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: 8fe8b8fab00b8f7b6f76dfda5f890c3e75d272273f3246bf3bbcae40ea33255b
4
- data.tar.gz: df00a746df46fba7758343b92b44f8ff9807780371a0c75b2e0e4fd0ca7ad480
3
+ metadata.gz: da18c9d693b01288822028e2c8a5ba21100f572a6456e71139cb494bdf71055b
4
+ data.tar.gz: 82a435c77c19acc42f02b130d3a01b6471829295d7ff3c3c99c2b005cf4e87f2
5
5
  SHA512:
6
- metadata.gz: b7a6bde01a0587ffdfbbfcbd88993fc942ab9a00825d0ddb1f85694bc13ddfcc710527410800faec22b739010b69bfee30a31f84e226ea035fccf4b41dcb6a6f
7
- data.tar.gz: 253baadde1f08d806eba2ebb734e8e9e620f6d6994852e24d4114398672d8745046adb2aff8bc23a850694c5b863351240c40843bb0f906162992430cda9bb52
6
+ metadata.gz: e6c9fa57613d0f2bec841a478cfcaa2a283b006f3d7f2d8fb2802859bc5eb9d0c409b598aa143fa15ec8147f417433a508ddc5ce4b42f8a4ff57028fa48a5d5a
7
+ data.tar.gz: f4cd060ee723cc5f029ec7270969f262afd8a0dbf4a6a1d55f86b660d84a68d9b23d650e3722bbdc3ec1e23da7b1b37acf4d5a90e0916aef1a5c090073cf299b
@@ -30,15 +30,18 @@ module GOVUKDesignSystemFormBuilder
30
30
  # hint: { text: 'You will not be able to proceed unless you do' }
31
31
  #
32
32
  def govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0,
33
- small: false, hint: {}, label: {}, link_errors: false, **kwargs, &block)
33
+ small: true, hint: {}, label: {}, link_errors: false, **kwargs, &block)
34
34
  govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small:) do
35
- govuk_check_box(attribute_name, value, unchecked_value,
36
- hint:,
37
- label:,
38
- link_errors:,
39
- multiple: false,
40
- exclusive: false,
41
- **kwargs, &block)
35
+ fieldset_context.pop # undo push from fieldset extension, labels should be bold unless already nested
36
+ checkbox = govuk_check_box(attribute_name, value, unchecked_value,
37
+ hint:,
38
+ label:,
39
+ link_errors:,
40
+ multiple: false,
41
+ exclusive: false,
42
+ **kwargs, &block)
43
+ fieldset_context.push attribute_name # restore push from fieldset
44
+ checkbox
42
45
  end
43
46
  end
44
47
  end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "govuk_design_system_formbuilder"
4
+
5
+ module Katalyst
6
+ module GOVUK
7
+ module Formbuilder
8
+ module Extensions
9
+ module Fieldset
10
+ def initialize(builder, object_name = nil, attribute_name = nil, &)
11
+ builder.fieldset_context << attribute_name
12
+
13
+ super
14
+
15
+ builder.fieldset_context.pop
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module GOVUKDesignSystemFormBuilder
24
+ module Builder
25
+ # Keep track of whether we are inside a fieldset
26
+ # This allows labels to default to bold ("s") normally but use the default otherwise
27
+ def fieldset_context
28
+ @fieldset_context ||= []
29
+ end
30
+
31
+ # Overwrite GOVUK default to set small to true
32
+ # @see GOVUKDesignSystemFormBuilder::Builder#govuk_collection_radio_buttons
33
+ def govuk_collection_radio_buttons(attribute_name, collection, value_method, text_method = nil, hint_method = nil,
34
+ hint: {}, legend: {}, caption: {}, inline: false, small: true, bold_labels: nil,
35
+ include_hidden: config.default_collection_radio_buttons_include_hidden,
36
+ form_group: {}, **kwargs, &block)
37
+ Elements::Radios::Collection.new(
38
+ self,
39
+ object_name,
40
+ attribute_name,
41
+ collection,
42
+ value_method:,
43
+ text_method:,
44
+ hint_method:,
45
+ hint:,
46
+ legend:,
47
+ caption:,
48
+ inline:,
49
+ small:,
50
+ bold_labels:,
51
+ form_group:,
52
+ include_hidden:,
53
+ **kwargs,
54
+ &block
55
+ ).html
56
+ end
57
+
58
+ # Overwrite GOVUK default to set small to true
59
+ # @see GOVUKDesignSystemFormBuilder::Builder#govuk_radio_buttons_fieldset
60
+ def govuk_radio_buttons_fieldset(attribute_name, hint: {}, legend: {}, caption: {}, inline: false, small: true,
61
+ form_group: {}, **kwargs, &block)
62
+ Containers::RadioButtonsFieldset.new(self, object_name, attribute_name,
63
+ hint:, legend:, caption:, inline:, small:, form_group:,
64
+ **kwargs, &block).html
65
+ end
66
+
67
+ # Overwrite GOVUK default to set small to true
68
+ # @see GOVUKDesignSystemFormBuilder::Builder#govuk_collection_check_boxes
69
+ def govuk_collection_check_boxes(attribute_name, collection, value_method, text_method, hint_method = nil,
70
+ hint: {}, legend: {}, caption: {}, small: true, form_group: {},
71
+ include_hidden: config.default_collection_check_boxes_include_hidden,
72
+ **kwargs, &block)
73
+ Elements::CheckBoxes::Collection.new(
74
+ self,
75
+ object_name,
76
+ attribute_name,
77
+ collection,
78
+ value_method:,
79
+ text_method:,
80
+ hint_method:,
81
+ hint:,
82
+ legend:,
83
+ caption:,
84
+ small:,
85
+ form_group:,
86
+ include_hidden:,
87
+ **kwargs,
88
+ &block
89
+ ).html
90
+ end
91
+
92
+ # Overwrite GOVUK default to set small to true
93
+ # @see GOVUKDesignSystemFormBuilder::Builder#govuk_check_boxes_fieldset
94
+ def govuk_check_boxes_fieldset(attribute_name, legend: {}, caption: {}, hint: {}, small: true, form_group: {},
95
+ multiple: true, **kwargs, &block)
96
+ Containers::CheckBoxesFieldset.new(
97
+ self,
98
+ object_name,
99
+ attribute_name,
100
+ hint:,
101
+ legend:,
102
+ caption:,
103
+ small:,
104
+ form_group:,
105
+ multiple:,
106
+ **kwargs,
107
+ &block
108
+ ).html
109
+ end
110
+ end
111
+
112
+ # Extend Traits::Label set the default size to small for non-nested labels.
113
+ module Traits
114
+ module Label
115
+ private
116
+
117
+ def label_content
118
+ default = @builder.fieldset_context.count.positive? ? {} : { size: "s" }
119
+
120
+ case @label
121
+ when Hash
122
+ default.merge(@label)
123
+ when Proc
124
+ default.merge(content: @label)
125
+ else
126
+ fail(ArgumentError, %(label must be a Proc or Hash))
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ # Extend Elements::Label to add support for human_attribute_name as a fallback
133
+ module Elements
134
+ class Label
135
+ def retrieve_text(option_text, hidden)
136
+ text = option_text.presence ||
137
+ localised_text(:label).presence ||
138
+ human_attribute_name.presence ||
139
+ @attribute_name.to_s.humanize.capitalize.presence
140
+
141
+ if hidden
142
+ tag.span(text, class: %(#{brand}-visually-hidden))
143
+ else
144
+ text
145
+ end
146
+ end
147
+
148
+ def human_attribute_name
149
+ return unless @object_name.present? && @attribute_name.present?
150
+ return unless @builder.object&.class.respond_to?(:human_attribute_name)
151
+
152
+ @builder.object.class.human_attribute_name(@attribute_name)
153
+ end
154
+ end
155
+ end
156
+
157
+ module Containers
158
+ class Fieldset
159
+ include Katalyst::GOVUK::Formbuilder::Extensions::Fieldset
160
+ end
161
+
162
+ class CheckBoxesFieldset
163
+ include Katalyst::GOVUK::Formbuilder::Extensions::Fieldset
164
+ end
165
+
166
+ class RadioButtonsFieldset
167
+ include Katalyst::GOVUK::Formbuilder::Extensions::Fieldset
168
+ end
169
+ end
170
+ end
@@ -5,6 +5,7 @@ require "govuk_design_system_formbuilder/elements/rich_text_area"
5
5
  require "govuk_design_system_formbuilder/elements/check_box_field"
6
6
 
7
7
  require "katalyst/govuk/formbuilder/engine"
8
+ require "katalyst/govuk/formbuilder/extensions"
8
9
  require "katalyst/govuk/formbuilder/frontend"
9
10
 
10
11
  module Katalyst
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katalyst-govuk-formbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-10 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -45,6 +45,7 @@ files:
45
45
  - lib/govuk_design_system_formbuilder/elements/rich_text_area.rb
46
46
  - lib/katalyst/govuk/formbuilder.rb
47
47
  - lib/katalyst/govuk/formbuilder/engine.rb
48
+ - lib/katalyst/govuk/formbuilder/extensions.rb
48
49
  - lib/katalyst/govuk/formbuilder/frontend.rb
49
50
  - vendor/assets/stylesheets/govuk-frontend/dist/govuk/_base.scss
50
51
  - vendor/assets/stylesheets/govuk-frontend/dist/govuk/all.scss