katalyst-govuk-formbuilder 1.11.0 → 1.12.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 205c71b26044c257f432d3ab429eff7beeeb0c924f775df314732703d240a04f
4
- data.tar.gz: 9a1733f6a7e41eefdeb6c096f21cbe7a328d6d7a159b6c57b3382d3f6e153236
3
+ metadata.gz: 2d371dc77a725f4e009f3a0a61e75d085f3080bad8cb64857299a3a7264fb95e
4
+ data.tar.gz: 392fcc8460909ba2a4190352a15cdd536a5e5e6e3d3ce896ae874a56a5aebef6
5
5
  SHA512:
6
- metadata.gz: 5ccc46b82e579a72033f4f79b5afd9f8928962cc67b4f19d4e0a8b513ded75b56c96af01e567e9456a1ab85c520c83da1a2854a27c961561f680e89be14b25f4
7
- data.tar.gz: 6ed137133d42622545c5f3b9178f7165976a7eaf732f29bcd353ddcd10232bd84a20dc93488257cb9765a2b0713a05561702c69291efc38d1619633a45f211aa
6
+ metadata.gz: cefbeb3e8423be0a86e33b324f59a3745aab8fd7e8a150a9e0be5dc4f874378108253db1f722c68b67defc3d96606db4dcef6576684f895445463cd905bf7f43
7
+ data.tar.gz: 8d688517167cc77a120aa50ac7d5e101524e8478c381071d603f650e303cc17ed9b0ea802cb6be15859717a2555f30589868768e55f7848df5c4072cdec87c04
data/README.md CHANGED
@@ -27,6 +27,12 @@ Add the stylesheet to your default layout:
27
27
  <%= stylesheet_link_tag "katalyst/govuk/formbuilder" %>
28
28
  ```
29
29
 
30
+ You can also add it to your SASS build:
31
+
32
+ ```scss
33
+ @use "katalyst/govuk/formbuilder";
34
+ ```
35
+
30
36
  Some GOVUK components require javascript enhancements
31
37
  (see [GOVUK docs](https://frontend.design-system.service.gov.uk/get-started/#5-get-the-javascript-working)).
32
38
 
@@ -43,6 +49,30 @@ You'll need to include the helper to make this method available, which you can a
43
49
  helper Katalyst::GOVUK::Formbuilder::Frontend
44
50
  ```
45
51
 
52
+ ## Extensions
53
+
54
+ We include some optional extensions for integrating with gems that we (Katalyst) commonly use.
55
+
56
+ These require additional steps to use.
57
+
58
+ ### Hotwire Combobox
59
+
60
+ [Hotwire Combobox](https://hotwirecombobox.com) is a promising option for adding asynchronous multi-select inputs to
61
+ Rails forms. We're assuming importmaps and Turbo if this option is used.
62
+
63
+ There's no explicit dependency so if you want to use this input you'll need to add:
64
+
65
+ ```
66
+ gem "hotwire_combobox"
67
+ ```
68
+
69
+ JS is added by the gem automatically (via importmaps), but you'll need to explicitly add CSS:
70
+
71
+ ```scss
72
+ @use "katalyst/govuk/formbuilder";
73
+ @use "katalyst/govuk/components/combobox";
74
+ ```
75
+
46
76
  ## Contributing
47
77
 
48
78
  Bug reports and pull requests are welcome on GitHub at https://github.com/katalyst/govuk-formbuilder.
@@ -1365,7 +1365,7 @@
1365
1365
  border-radius: 0;
1366
1366
  color: #ffffff;
1367
1367
  background-color: #00703c;
1368
- box-shadow: 0 2px 0 #002d18;
1368
+ box-shadow: 0 2px 0 rgb(0, 44.8, 24);
1369
1369
  text-align: center;
1370
1370
  vertical-align: top;
1371
1371
  cursor: pointer;
@@ -1407,7 +1407,7 @@
1407
1407
  border: 0;
1408
1408
  }
1409
1409
  .govuk-button:hover {
1410
- background-color: #005a30;
1410
+ background-color: rgb(0, 89.6, 48);
1411
1411
  }
1412
1412
  .govuk-button:active {
1413
1413
  top: 2px;
@@ -1446,18 +1446,18 @@
1446
1446
  }
1447
1447
  .govuk-button[disabled]:active {
1448
1448
  top: 0;
1449
- box-shadow: 0 2px 0 #002d18;
1449
+ box-shadow: 0 2px 0 rgb(0, 44.8, 24);
1450
1450
  }
1451
1451
 
1452
1452
  .govuk-button--secondary {
1453
1453
  background-color: #f3f2f1;
1454
- box-shadow: 0 2px 0 #929191;
1454
+ box-shadow: 0 2px 0 rgb(145.8, 145.2, 144.6);
1455
1455
  }
1456
1456
  .govuk-button--secondary, .govuk-button--secondary:link, .govuk-button--secondary:visited, .govuk-button--secondary:active, .govuk-button--secondary:hover {
1457
1457
  color: #0b0c0c;
1458
1458
  }
1459
1459
  .govuk-button--secondary:hover {
1460
- background-color: #dbdad9;
1460
+ background-color: rgb(218.7, 217.8, 216.9);
1461
1461
  }
1462
1462
  .govuk-button--secondary:hover[disabled] {
1463
1463
  background-color: #f3f2f1;
@@ -1465,13 +1465,13 @@
1465
1465
 
1466
1466
  .govuk-button--warning {
1467
1467
  background-color: #d4351c;
1468
- box-shadow: 0 2px 0 #55150b;
1468
+ box-shadow: 0 2px 0 rgb(84.8, 21.2, 11.2);
1469
1469
  }
1470
1470
  .govuk-button--warning, .govuk-button--warning:link, .govuk-button--warning:visited, .govuk-button--warning:active, .govuk-button--warning:hover {
1471
1471
  color: #ffffff;
1472
1472
  }
1473
1473
  .govuk-button--warning:hover {
1474
- background-color: #aa2a16;
1474
+ background-color: rgb(169.6, 42.4, 22.4);
1475
1475
  }
1476
1476
  .govuk-button--warning:hover[disabled] {
1477
1477
  background-color: #d4351c;
@@ -1479,13 +1479,13 @@
1479
1479
 
1480
1480
  .govuk-button--inverse {
1481
1481
  background-color: #ffffff;
1482
- box-shadow: 0 2px 0 #144e81;
1482
+ box-shadow: 0 2px 0 rgb(20.3, 78.4, 128.8);
1483
1483
  }
1484
1484
  .govuk-button--inverse, .govuk-button--inverse:link, .govuk-button--inverse:visited, .govuk-button--inverse:active, .govuk-button--inverse:hover {
1485
1485
  color: #1d70b8;
1486
1486
  }
1487
1487
  .govuk-button--inverse:hover {
1488
- background-color: #e8f1f8;
1488
+ background-color: rgb(232.4, 240.7, 247.9);
1489
1489
  }
1490
1490
  .govuk-button--inverse:hover[disabled] {
1491
1491
  background-color: #ffffff;
@@ -2380,7 +2380,7 @@
2380
2380
  color: #d4351c;
2381
2381
  }
2382
2382
  .govuk-error-summary__list a:hover {
2383
- color: #942514;
2383
+ color: rgb(148.4, 37.1, 19.6);
2384
2384
  }
2385
2385
  .govuk-error-summary__list a:active {
2386
2386
  color: #d4351c;
@@ -0,0 +1,100 @@
1
+ // assumes that hotwire_combobox is in the load paths, implies dartsass-rails is the compiler
2
+ @use "hotwire_combobox";
3
+
4
+ @import "govuk-frontend/dist/govuk/base";
5
+ @import "govuk-frontend/dist/govuk/components/error-message/index";
6
+ @import "govuk-frontend/dist/govuk/components/hint/index";
7
+ @import "govuk-frontend/dist/govuk/components/label/index";
8
+
9
+ // Based on components/select
10
+ @include govuk-exports("govuk/component/combobox") {
11
+ .hw-combobox:has(.govuk-combobox) {
12
+ --hw-border-radius: 0;
13
+ --hw-border-width--slim: #{$govuk-border-width-form-element};
14
+ --hw-border-color: #{$govuk-input-border-colour};
15
+ --hw-focus-color: #{$govuk-focus-colour};
16
+ --hw-combobox-width: 100%;
17
+ --hw-combobox-width--multiple: 100%;
18
+ --hw-active-bg-color: #{govuk-colour("blue")};
19
+ --hw-padding--slim: #{govuk-spacing(1)};
20
+ --hw-padding--slimmer: #{govuk-spacing(1)};
21
+ --hw-padding--thick: #{govuk-spacing(1)};
22
+ --hw-font-size: 1rem;
23
+ --hw-line-height: 1.25;
24
+
25
+ display: flex;
26
+
27
+ .hw-combobox__main__wrapper {
28
+ // This min-width was chosen because:
29
+ // - it makes the Select wider than it is tall (which is what users expect)
30
+ // - 11.5em matches the 'length-10' variant of the input component
31
+ // - it fits comfortably on screens as narrow as 240px wide
32
+ min-width: 11.5em;
33
+ max-width: var(--text-width, 100%);
34
+
35
+ display: flex;
36
+ min-height: 2.5rem;
37
+ align-items: center;
38
+
39
+ // Default user agent colours for selects can have low contrast,
40
+ // and may look disabled (#2435)
41
+ color: $govuk-text-colour;
42
+ background-color: govuk-colour("white");
43
+ }
44
+
45
+ .hw-combobox__main__wrapper:focus-within {
46
+ outline: $govuk-focus-width solid $govuk-focus-colour;
47
+ // Ensure outline appears outside of the element
48
+ outline-offset: 0;
49
+ // Double the border by adding its width again. Use `box-shadow` to do
50
+ // this instead of changing `border-width` (which changes element size)
51
+ // and since `outline` is already used for the yellow focus state.
52
+ box-shadow: inset 0 0 0 $govuk-border-width-form-element;
53
+ }
54
+
55
+ .govuk-combobox {
56
+ @include govuk-font($size: 16, $line-height: 1.25);
57
+
58
+ // override input styles from form/govuk
59
+ border: none;
60
+ outline: none;
61
+ box-shadow: none;
62
+ width: 100%;
63
+ padding: 0;
64
+ height: unset;
65
+ }
66
+
67
+ // disabled
68
+ &:has(.govuk-combobox:disabled) {
69
+ opacity: 0.5;
70
+ color: inherit;
71
+ cursor: not-allowed;
72
+ }
73
+
74
+ // extend existing hover/active styles (--hw-active-bg-color)
75
+ .hw-combobox__option:hover,
76
+ .hw-combobox__option--navigated,
77
+ .hw-combobox__option--selected {
78
+ color: govuk-colour("white");
79
+ }
80
+
81
+ .hw-combobox__dialog__input {
82
+ width: 100%;
83
+ }
84
+
85
+ .hw-combobox__listbox {
86
+ left: -$govuk-border-width-form-element;
87
+ right: -$govuk-border-width-form-element;
88
+ top: calc(100% + $govuk-border-width-form-element * 2 + 0.2rem);
89
+ width: unset;
90
+ }
91
+ }
92
+
93
+ .govuk-combobox--error {
94
+ border-color: $govuk-error-colour;
95
+
96
+ .hw-combobox__main__wrapper:focus-within {
97
+ border-color: $govuk-input-border-colour;
98
+ }
99
+ }
100
+ }
@@ -2,12 +2,11 @@
2
2
  @import "govuk-frontend/dist/govuk/components/hint/index";
3
3
  @import "govuk-frontend/dist/govuk/components/label/index";
4
4
 
5
- // Based on components/textarea
6
5
  @include govuk-exports("govuk/component/richtextarea") {
7
6
  .govuk-richtextarea {
8
7
  @include govuk-font($size: 19, $line-height: 1.25);
9
8
 
10
- box-sizing: border-box; // should this be global?
9
+ box-sizing: border-box;
11
10
  display: block;
12
11
  width: 100%;
13
12
  // min-height inherited from trix-editor styles
@@ -26,8 +25,8 @@
26
25
  // Ensure outline appears outside of the element
27
26
  outline-offset: 0;
28
27
  // Double the border by adding its width again. Use `box-shadow` to do
29
- // this instead of changing `border-width` (which changes element size) and
30
- // since `outline` is already used for the yellow focus state.
28
+ // this instead of changing `border-width` (which changes element size)
29
+ // and since `outline` is already used for the yellow focus state.
31
30
  box-shadow: inset 0 0 0 $govuk-border-width-form-element;
32
31
  }
33
32
 
@@ -157,7 +157,7 @@ module Katalyst
157
157
  # @param form_group [Hash] configures the form group
158
158
  # @option form_group classes [Array,String] sets the form group's classes
159
159
  # @option form_group kwargs [Hash] additional attributes added to the form group
160
- # @param block [Block] arbitrary HTML that will be rendered between the hint and the input
160
+ # @param & [Block] arbitrary HTML that will be rendered between the hint and the input
161
161
  # @return [ActiveSupport::SafeBuffer] HTML output
162
162
  #
163
163
  # @example A rich text area with injected content
@@ -186,6 +186,46 @@ module Katalyst
186
186
  ).html
187
187
  end
188
188
 
189
+ # Generates a +combobox+ element that uses Hotwire Combobox to generate a combobox selection element.
190
+ # @see https://hotwirecombobox.com
191
+ # @see https://github.com/josefarias/hotwire_combobox
192
+ #
193
+ # @param attribute_name [Symbol] The name of the attribute
194
+ # @param options_or_src [Array] The +option+ values or a source path for async combobox
195
+ # @param options [Hash] Options hash passed through to the +combobox+ helper
196
+ # @param hint [Hash,Proc] The content of the hint. No hint will be added if 'text' is left +nil+.
197
+ # When a +Proc+ is supplied the hint will be wrapped in a +div+ instead of a +span+
198
+ # @option hint text [String] the hint text
199
+ # @option hint kwargs [Hash] additional arguments are applied as attributes to the hint
200
+ # @param label [Hash,Proc] configures or sets the associated label content
201
+ # @option label text [String] the label text
202
+ # @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
203
+ # @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
204
+ # @option label hidden [Boolean] control the visibility of the label.
205
+ # Hidden labels will still be read by screenreaders
206
+ # @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
207
+ # @param form_group [Hash] configures the form group
208
+ # @option form_group kwargs [Hash] additional attributes added to the form group
209
+ # @return [ActiveSupport::SafeBuffer] HTML output
210
+ #
211
+ # @example A combobox that allows the user to choose from a list of states
212
+ #
213
+ # = f.combobox "state", State.all
214
+ #
215
+ # @example A combobox that allows the user to choose from an asynchronous states endpoint
216
+ #
217
+ # = f.combobox "state", states_path
218
+ #
219
+ # @example A multi-select combobox that allows the user to choose multiple states
220
+ #
221
+ # = f.combobox "state", State.all, multiselect_chip_src: states_chips_path
222
+ #
223
+ def govuk_combobox(attribute_name, options_or_src = [], options: {}, label: {}, hint: {}, form_group: {},
224
+ caption: {}, **, &)
225
+ Elements::Combobox.new(self, object_name, attribute_name, options_or_src,
226
+ options:, label:, hint:, form_group:, caption:, **, &).html
227
+ end
228
+
189
229
  # Keep track of whether we are inside a fieldset
190
230
  # This allows labels to default to bold ("s") normally but use the default otherwise
191
231
  def fieldset_context
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "govuk_design_system_formbuilder"
4
+
5
+ module Katalyst
6
+ module GOVUK
7
+ module Formbuilder
8
+ module Elements
9
+ class Combobox < GOVUKDesignSystemFormBuilder::Base
10
+ include GOVUKDesignSystemFormBuilder::Traits::Error
11
+ include GOVUKDesignSystemFormBuilder::Traits::Label
12
+ include GOVUKDesignSystemFormBuilder::Traits::Hint
13
+ include GOVUKDesignSystemFormBuilder::Traits::HTMLAttributes
14
+
15
+ def initialize(builder, object_name, attribute_name, options_or_src, options:, form_group:, label:, hint:,
16
+ caption:, **kwargs, &block)
17
+ super(builder, object_name, attribute_name)
18
+ @block = block
19
+
20
+ @form_group = form_group
21
+ @hint = hint
22
+ @label = label
23
+ @caption = caption
24
+ @options_or_src = options_or_src
25
+ @options = options
26
+ @html_attributes = kwargs
27
+ end
28
+
29
+ def html
30
+ GOVUKDesignSystemFormBuilder::Containers::FormGroup.new(*bound, **@form_group).html do
31
+ safe_join([label_element, hint_element, error_element, combobox])
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def combobox
38
+ @builder.combobox(@attribute_name, @options_or_src, **@options, **attributes(@html_attributes), &@block)
39
+ end
40
+
41
+ def options
42
+ {
43
+ id: field_id(link_errors: true),
44
+ class: classes,
45
+ aria: { describedby: combine_references(hint_id, error_id) },
46
+ }
47
+ end
48
+
49
+ def classes
50
+ combine_references(%(#{brand}-combobox), error_class)
51
+ end
52
+
53
+ def error_class
54
+ %(#{brand}-combobox--error) if has_errors?
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
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.11.0
4
+ version: 1.12.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-09-16 00:00:00.000000000 Z
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -37,13 +37,14 @@ files:
37
37
  - app/assets/builds/katalyst/govuk/formbuilder.js
38
38
  - app/assets/builds/katalyst/govuk/formbuilder.min.js
39
39
  - app/assets/config/katalyst-govuk-formbuilder.js
40
+ - app/assets/stylesheets/katalyst/govuk/components/combobox/_index.scss
40
41
  - app/assets/stylesheets/katalyst/govuk/components/richtextarea/_index.scss
41
- - app/assets/stylesheets/katalyst/govuk/components/richtextarea/_richtextarea.scss
42
42
  - app/assets/stylesheets/katalyst/govuk/formbuilder.scss
43
43
  - config/importmap.rb
44
44
  - lib/katalyst/govuk/formbuilder.rb
45
45
  - lib/katalyst/govuk/formbuilder/builder.rb
46
46
  - lib/katalyst/govuk/formbuilder/containers/fieldset_context.rb
47
+ - lib/katalyst/govuk/formbuilder/elements/combobox.rb
47
48
  - lib/katalyst/govuk/formbuilder/elements/label.rb
48
49
  - lib/katalyst/govuk/formbuilder/elements/legend.rb
49
50
  - lib/katalyst/govuk/formbuilder/elements/rich_text_area.rb
@@ -1,2 +0,0 @@
1
- @import "govuk-frontend/dist/govuk/base";
2
- @import "./index";