katalyst-govuk-formbuilder 1.1.1 → 1.2.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: 55dbcc46de912ec5d085cec6a9012f2c9519fab9faac2e75dc4db78b9fb11c8b
4
- data.tar.gz: 33c0503e13126fdf81e7bc749d51137793e56c264b5866ff22416cc135cf1eb4
3
+ metadata.gz: 0b3226cf4e2ecbf980efe6f5cdab612b5aafe57ffa4377cde05151f42843dc2d
4
+ data.tar.gz: 3b2e6aa556e25ffce43e021fe50153a3de7f4385844906c626297cbf36a676dd
5
5
  SHA512:
6
- metadata.gz: 26f134d6a93f1cf1c1569037a667818ffda1471d5ab5c1a1a71a0a026ed2361d6576556522d6c1902a59e55cbb4373ecef6c874c7a09bdab7d858511973f9e7e
7
- data.tar.gz: 79abd30427a6b08a18bdff4254d9e95749ca3021a9071ae68d3f9a79c46954c3d8204c8a5064efb4e89957917e40886111757505111ec0da6549474dd81bead2
6
+ metadata.gz: c0c6e25bebd4cb6783b23d99756355dac5f67456eb25df653ca9c47af5cf735e41a3ccc3020632c07056bd02615f6c31001652a3124be9d3660ef8fbd9dfd104
7
+ data.tar.gz: 8fe14e36cd46640fa7af588b1ca674ad0fbba35194a9b8b4c663bd0bebd4a6242251fc8d95a126d5256d6e00ac2ead0fb9eb86da56e6f4d5b115c1c015815582
@@ -4090,3 +4090,57 @@ x:-moz-any-link {
4090
4090
  width: 25% !important;
4091
4091
  }
4092
4092
  }
4093
+
4094
+ .govuk-richtextarea {
4095
+ font-family: "Open Sans", sans-serif;
4096
+ -webkit-font-smoothing: antialiased;
4097
+ -moz-osx-font-smoothing: grayscale;
4098
+ font-weight: 400;
4099
+ font-size: 16px;
4100
+ font-size: 1rem;
4101
+ line-height: 1.25;
4102
+ box-sizing: border-box;
4103
+ display: block;
4104
+ width: 100%;
4105
+ margin-bottom: 20px;
4106
+ padding: 5px;
4107
+ resize: vertical;
4108
+ border: 2px solid #0b0c0c;
4109
+ border-radius: 0;
4110
+ -webkit-appearance: none;
4111
+ }
4112
+ @media print {
4113
+ .govuk-richtextarea {
4114
+ font-family: sans-serif;
4115
+ }
4116
+ }
4117
+ @media (min-width: 40.0625em) {
4118
+ .govuk-richtextarea {
4119
+ font-size: 19px;
4120
+ font-size: 1.1875rem;
4121
+ line-height: 1.25;
4122
+ }
4123
+ }
4124
+ @media print {
4125
+ .govuk-richtextarea {
4126
+ font-size: 14pt;
4127
+ line-height: 1.25;
4128
+ }
4129
+ }
4130
+ @media (min-width: 40.0625em) {
4131
+ .govuk-richtextarea {
4132
+ margin-bottom: 30px;
4133
+ }
4134
+ }
4135
+ .govuk-richtextarea:focus {
4136
+ outline: 3px solid #ffdd00;
4137
+ outline-offset: 0;
4138
+ box-shadow: inset 0 0 0 2px;
4139
+ }
4140
+
4141
+ .govuk-richtextarea--error {
4142
+ border-color: #d4351c;
4143
+ }
4144
+ .govuk-richtextarea--error:focus {
4145
+ border-color: #0b0c0c;
4146
+ }
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "govuk_design_system_formbuilder"
4
+
5
+ module GOVUKDesignSystemFormBuilder
6
+ module Builder
7
+
8
+ # Generates a check box within a fieldset to be used as a boolean toggle for a single attribute.
9
+ # The values are 1 (toggled on), and 0 (toggled off).
10
+ #
11
+ # @param attribute_name [Symbol] The name of the attribute
12
+ # @param small [Boolean] controls whether small check boxes are used instead of regular-sized ones
13
+ # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
14
+ # supplied the hint will be wrapped in a +div+ instead of a +span+
15
+ # @option hint text [String] the hint text
16
+ # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
17
+ # @param link_errors [Boolean] controls whether this checkbox should be linked to from {#govuk_error_summary}
18
+ # @option label text [String] the label text
19
+ # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
20
+ # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
21
+ # @option label hidden [Boolean] control the visibility of the label. Hidden labels will still be read by screenreaders
22
+ # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
23
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
24
+ # @param block [Block] any HTML passed in will form the contents of the fieldset
25
+ # @return [ActiveSupport::SafeBuffer] HTML output
26
+ #
27
+ # @example A single check box for terms and conditions
28
+ # = f.govuk_boolean_checkbox_field :terms_agreed,
29
+ # link_errors: true,
30
+ # label: { text: 'Do you agree with our terms and conditions?' },
31
+ # hint: { text: 'You will not be able to proceed unless you do' }
32
+ #
33
+ def govuk_boolean_checkbox_field(attribute_name, small: true, hint: {}, label: {}, link_errors: false, **kwargs, &block)
34
+ govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small: small) do
35
+ govuk_check_box(attribute_name, 1, 0,
36
+ hint: hint,
37
+ label: label,
38
+ link_errors: link_errors,
39
+ multiple: false,
40
+ exclusive: false,
41
+ **kwargs, &block)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,108 @@
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
+ delegate :config, to: GOVUKDesignSystemFormBuilder
57
+
58
+ # Generates a pair of +trix-toolbar+ and +trix-editor+ elements with a label, optional hint. Requires action-text to
59
+ # be correctly setup in the application
60
+ #
61
+ # @param attribute_name [Symbol] The name of the attribute
62
+ # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+. When a +Proc+ is
63
+ # supplied the hint will be wrapped in a +div+ instead of a +span+
64
+ # @option hint text [String] the hint text
65
+ # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
66
+ # @param label [Hash,Proc] configures or sets the associated label content
67
+ # @option label text [String] the label text
68
+ # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
69
+ # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
70
+ # @option label hidden [Boolean] control the visibility of the label. Hidden labels will still be read by screen
71
+ # readers
72
+ # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
73
+ # @param caption [Hash] configures or sets the caption content which is inserted above the label
74
+ # @option caption text [String] the caption text
75
+ # @option caption size [String] the size of the caption, can be +xl+, +l+ or +m+. Defaults to +m+
76
+ # @option caption kwargs [Hash] additional arguments are applied as attributes on the caption +span+ element
77
+ # @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +trix-editor+ element. This is
78
+ # picked up and handled by the action-text gem
79
+ # @param form_group [Hash] configures the form group
80
+ # @option form_group classes [Array,String] sets the form group's classes
81
+ # @option form_group kwargs [Hash] additional attributes added to the form group
82
+ # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
83
+ # @return [ActiveSupport::SafeBuffer] HTML output
84
+ #
85
+ # @example A rich text area with injected content
86
+ # = f.govuk_rich_text_area :description,
87
+ # label: { text: 'Where did the incident take place?' } do
88
+ #
89
+ # p.govuk-inset-text
90
+ # | If you don't know exactly leave this section blank
91
+ #
92
+ # @example A rich text area with the label supplied as a proc
93
+ # = f.govuk_rich_text_area :instructions,
94
+ # label: -> { tag.h3("How do you set it up?") }
95
+ #
96
+ # @example A rich text area with a custom direct upload url and a custom stimulus controller
97
+ # = f.govuk_rich_text_area :description,
98
+ # data: {
99
+ # direct_upload_url: direct_uploads_url,
100
+ # controller: "content--editor--trix",
101
+ # action: "trix-initialize->content--editor--trix#trixInitialize",
102
+ # }
103
+ #
104
+ def govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
105
+ Elements::RichTextArea.new(self, object_name, attribute_name, hint: hint, label: label, caption: caption, form_group: form_group, **kwargs, &block).html
106
+ end
107
+ end
108
+ end
@@ -1,7 +1,7 @@
1
1
  module Katalyst
2
2
  module GOVUK
3
3
  module Formbuilder
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,4 +1,6 @@
1
1
  require "govuk_design_system_formbuilder"
2
+ require "govuk_design_system_formbuilder/elements/rich_text_area"
3
+ require "govuk_design_system_formbuilder/elements/boolean_checkbox_field"
2
4
 
3
5
  require "katalyst/govuk/formbuilder/engine"
4
6
  require "katalyst/govuk/formbuilder/frontend"
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.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -38,6 +38,8 @@ files:
38
38
  - app/assets/javascripts/katalyst/govuk/formbuilder.js
39
39
  - app/assets/javascripts/katalyst/govuk/formbuilder.min.js
40
40
  - config/importmap.rb
41
+ - lib/govuk_design_system_formbuilder/elements/boolean_checkbox_field.rb
42
+ - lib/govuk_design_system_formbuilder/elements/rich_text_area.rb
41
43
  - lib/katalyst/govuk/formbuilder.rb
42
44
  - lib/katalyst/govuk/formbuilder/engine.rb
43
45
  - lib/katalyst/govuk/formbuilder/frontend.rb