katalyst-govuk-formbuilder 1.9.3 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "govuk_design_system_formbuilder"
4
+
5
+ module Katalyst
6
+ module GOVUK
7
+ module Formbuilder
8
+ module Traits
9
+ # Extend GovukDesignSystemFormBuilder::Traits::Label set the default size to small for non-nested labels.
10
+ module Label
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ private
15
+
16
+ def label_content
17
+ default = @builder.fieldset_context.count.positive? ? {} : { size: "s" }
18
+
19
+ case @label
20
+ when Hash
21
+ default.merge(@label)
22
+ when Proc
23
+ default.merge(content: @label)
24
+ else
25
+ fail(ArgumentError, %(label must be a Proc or Hash))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,16 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "govuk_design_system_formbuilder"
4
- require "govuk_design_system_formbuilder/elements/rich_text_area"
5
- require "govuk_design_system_formbuilder/elements/check_box_field"
6
-
7
- require "katalyst/govuk/formbuilder/engine"
8
- require "katalyst/govuk/formbuilder/extensions"
9
- require "katalyst/govuk/formbuilder/frontend"
10
-
11
3
  module Katalyst
12
4
  module GOVUK
13
5
  module Formbuilder
14
6
  end
15
7
  end
16
8
  end
9
+
10
+ require "katalyst/govuk/formbuilder/engine"
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.9.3
4
+ version: 1.10.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: 2024-06-13 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -33,17 +33,24 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
+ - app/assets/builds/katalyst/govuk/formbuilder.css
37
+ - app/assets/builds/katalyst/govuk/formbuilder.js
38
+ - app/assets/builds/katalyst/govuk/formbuilder.min.js
36
39
  - app/assets/config/katalyst-govuk-formbuilder.js
37
40
  - app/assets/stylesheets/katalyst/govuk/components/richtextarea/_index.scss
38
41
  - app/assets/stylesheets/katalyst/govuk/components/richtextarea/_richtextarea.scss
39
42
  - app/assets/stylesheets/katalyst/govuk/formbuilder.scss
40
43
  - config/importmap.rb
41
- - lib/govuk_design_system_formbuilder/elements/check_box_field.rb
42
- - lib/govuk_design_system_formbuilder/elements/rich_text_area.rb
43
44
  - lib/katalyst/govuk/formbuilder.rb
45
+ - lib/katalyst/govuk/formbuilder/builder.rb
46
+ - lib/katalyst/govuk/formbuilder/containers/fieldset_context.rb
47
+ - lib/katalyst/govuk/formbuilder/elements/label.rb
48
+ - lib/katalyst/govuk/formbuilder/elements/legend.rb
49
+ - lib/katalyst/govuk/formbuilder/elements/rich_text_area.rb
44
50
  - lib/katalyst/govuk/formbuilder/engine.rb
45
51
  - lib/katalyst/govuk/formbuilder/extensions.rb
46
52
  - lib/katalyst/govuk/formbuilder/frontend.rb
53
+ - lib/katalyst/govuk/formbuilder/traits/label.rb
47
54
  - node_modules/govuk-frontend/dist/govuk/_base.scss
48
55
  - node_modules/govuk-frontend/dist/govuk/all.scss
49
56
  - node_modules/govuk-frontend/dist/govuk/components/_all.scss
@@ -195,14 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
202
  requirements:
196
203
  - - ">="
197
204
  - !ruby/object:Gem::Version
198
- version: '0'
205
+ version: '3.3'
199
206
  required_rubygems_version: !ruby/object:Gem::Requirement
200
207
  requirements:
201
208
  - - ">="
202
209
  - !ruby/object:Gem::Version
203
210
  version: '0'
204
211
  requirements: []
205
- rubygems_version: 3.5.9
212
+ rubygems_version: 3.5.11
206
213
  signing_key:
207
214
  specification_version: 4
208
215
  summary: Repackaging of UK.GOV forms for Rails 7 asset pipeline
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "govuk_design_system_formbuilder"
4
-
5
- module GOVUKDesignSystemFormBuilder
6
- module Builder
7
- # Generates a check box within a fieldset to be used as a boolean toggle for a single attribute.
8
- # The values are 1 (toggled on), and 0 (toggled off).
9
- #
10
- # @param attribute_name [Symbol] The name of the attribute
11
- # @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
12
- # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
13
- # supplied the hint will be wrapped in a +div+ instead of a +span+
14
- # @option hint text [String] the hint text
15
- # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
16
- # @param link_errors [Boolean] controls whether this checkbox should be linked to from {#govuk_error_summary}
17
- # @option label text [String] the label text
18
- # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
19
- # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
20
- # @option label hidden [Boolean] control the visibility of the label. Hidden labels will be read by screenreaders
21
- # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
22
- # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
23
- # @param block [Block] any HTML passed in will form the contents of the fieldset
24
- # @return [ActiveSupport::SafeBuffer] HTML output
25
- #
26
- # @example A single check box for terms and conditions
27
- # = f.govuk_check_box_field :terms_agreed,
28
- # link_errors: true,
29
- # label: { text: 'Do you agree with our terms and conditions?' },
30
- # hint: { text: 'You will not be able to proceed unless you do' }
31
- #
32
- def govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0,
33
- small: true, hint: {}, label: {}, link_errors: false, **kwargs, &block)
34
- govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small:) do
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
45
- end
46
- end
47
- end
48
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "govuk_design_system_formbuilder"
4
-
5
- module GOVUKDesignSystemFormBuilder
6
- module Elements
7
- class RichTextArea < Base
8
- using PrefixableArray
9
-
10
- include Traits::Error
11
- include Traits::Hint
12
- include Traits::Label
13
- include Traits::Supplemental
14
- include Traits::HTMLAttributes
15
- include Traits::HTMLClasses
16
-
17
- def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, **kwargs, &block)
18
- super(builder, object_name, attribute_name, &block)
19
-
20
- @label = label
21
- @caption = caption
22
- @hint = hint
23
- @form_group = form_group
24
- @html_attributes = kwargs
25
- end
26
-
27
- def html
28
- Containers::FormGroup.new(*bound, **@form_group).html do
29
- safe_join([label_element, supplemental_content, hint_element, error_element, rich_text_area])
30
- end
31
- end
32
-
33
- private
34
-
35
- def rich_text_area
36
- @builder.rich_text_area(@attribute_name, **attributes(@html_attributes))
37
- end
38
-
39
- def classes
40
- build_classes(%(richtextarea), %(richtextarea--error) => has_errors?).prefix(brand)
41
- end
42
-
43
- def options
44
- {
45
- id: field_id(link_errors: true),
46
- class: classes,
47
- aria: { describedby: combine_references(hint_id, error_id, supplemental_id) },
48
- }
49
- end
50
- end
51
- end
52
- end
53
-
54
- module GOVUKDesignSystemFormBuilder
55
- module Builder
56
- # Generates a pair of +trix-toolbar+ and +trix-editor+ elements with a label, optional hint. Requires action-text to
57
- # be correctly setup in the application
58
- #
59
- # @param attribute_name [Symbol] The name of the attribute
60
- # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
61
- # supplied the hint will be wrapped in a +div+ instead of a +span+
62
- # @option hint text [String] the hint text
63
- # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
64
- # @param label [Hash,Proc] configures or sets the associated label content
65
- # @option label text [String] the label text
66
- # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
67
- # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
68
- # @option label hidden [Boolean] control the visibility of the label. Hidden labels will still be read by screen
69
- # readers
70
- # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
71
- # @param caption [Hash] configures or sets the caption content which is inserted above the label
72
- # @option caption text [String] the caption text
73
- # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
74
- # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
75
- # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +trix-editor+ element. This is
76
- # picked up and handled by the action-text gem
77
- # @param form_group [Hash] configures the form group
78
- # @option form_group classes [Array,String] sets the form group's classes
79
- # @option form_group kwargs [Hash] additional attributes added to the form group
80
- # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
81
- # @return [ActiveSupport::SafeBuffer] HTML output
82
- #
83
- # @example A rich text area with injected content
84
- # = f.govuk_rich_text_area :description,
85
- # label: { text: 'Where did the incident take place?' } do
86
- #
87
- # p.govuk-inset-text
88
- # | If you don't know exactly leave this section blank
89
- #
90
- # @example A rich text area with the label supplied as a proc
91
- # = f.govuk_rich_text_area :instructions,
92
- # label: -> { tag.h3("How do you set it up?") }
93
- #
94
- # @example A rich text area with a custom direct upload url and a custom stimulus controller
95
- # = f.govuk_rich_text_area :description,
96
- # data: {
97
- # direct_upload_url: direct_uploads_url,
98
- # controller: "content--editor--trix",
99
- # action: "trix-initialize->content--editor--trix#trixInitialize",
100
- # }
101
- #
102
- def govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
103
- Elements::RichTextArea.new(self, object_name, attribute_name,
104
- hint:, label:, caption:, form_group:, **kwargs, &block).html
105
- end
106
- end
107
- end