hof 22.12.0-unit-of-measure-beta.1 → 22.13.0-frontend-v4-beta.1

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 (48) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/README.md +0 -78
  3. package/build/tasks/images/index.js +20 -5
  4. package/build/tasks/watch/index.js +10 -2
  5. package/components/date/templates/date.html +1 -1
  6. package/components/index.js +0 -1
  7. package/config/builder-defaults.js +6 -2
  8. package/controller/controller.js +3 -5
  9. package/controller/validation/index.js +1 -1
  10. package/controller/validation/validators.js +1 -0
  11. package/frontend/govuk-template/build/config.js +1 -0
  12. package/frontend/govuk-template/build/govuk_template.html +58 -42
  13. package/frontend/govuk-template/govuk_template_generated.html +118 -0
  14. package/frontend/template-mixins/mixins/template-mixins.js +10 -59
  15. package/frontend/template-mixins/partials/forms/checkbox.html +5 -1
  16. package/frontend/template-mixins/partials/forms/input-text-date.html +2 -1
  17. package/frontend/template-mixins/partials/forms/input-text-group.html +1 -1
  18. package/frontend/template-mixins/partials/forms/textarea-group.html +1 -1
  19. package/frontend/template-partials/views/layout.html +1 -1
  20. package/frontend/template-partials/views/partials/cookie-banner.html +50 -32
  21. package/frontend/template-partials/views/partials/navigation.html +2 -2
  22. package/frontend/themes/gov-uk/client-js/cookieSettings.js +35 -23
  23. package/frontend/themes/gov-uk/styles/govuk.scss +0 -1
  24. package/frontend/toolkit/assets/javascript/form-focus.js +0 -4
  25. package/frontend/toolkit/assets/rebrand/images/govuk-logo.svg +25 -0
  26. package/index.js +4 -2
  27. package/package.json +2 -2
  28. package/sandbox/apps/sandbox/fields.js +1 -18
  29. package/sandbox/apps/sandbox/index.js +0 -4
  30. package/sandbox/apps/sandbox/sections/summary-data-sections.js +1 -7
  31. package/sandbox/apps/sandbox/translations/en/default.json +0 -33
  32. package/sandbox/apps/sandbox/translations/src/en/fields.json +0 -10
  33. package/sandbox/apps/sandbox/translations/src/en/pages.json +0 -3
  34. package/sandbox/apps/sandbox/translations/src/en/validation.json +0 -12
  35. package/sandbox/package.json +1 -1
  36. package/sandbox/public/css/app.css +2996 -1330
  37. package/sandbox/public/images/govuk-logo.svg +25 -0
  38. package/sandbox/public/js/bundle.js +4751 -2217
  39. package/sandbox/yarn.lock +4 -4
  40. package/components/amount-with-unit-select/amount-with-unit-select.js +0 -107
  41. package/components/amount-with-unit-select/fields.js +0 -15
  42. package/components/amount-with-unit-select/hooks.js +0 -168
  43. package/components/amount-with-unit-select/templates/amount-with-unit-select.html +0 -20
  44. package/components/amount-with-unit-select/utils.js +0 -191
  45. package/components/amount-with-unit-select/validation.js +0 -175
  46. package/frontend/template-mixins/partials/forms/grouped-inputs-select.html +0 -13
  47. package/frontend/template-mixins/partials/forms/grouped-inputs-text.html +0 -37
  48. package/frontend/themes/gov-uk/styles/_grouped-input.scss +0 -5
@@ -1,175 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
- const controller = require('../../controller/controller').prototype;
5
- const utils = require('./utils');
6
-
7
- /**
8
- * Validates the value is a string consisting of two hyphen-separated values.
9
- * Can be passed to the list of field validators to run as a custom validator.
10
- * @param {string} value - The amountWithUnitSelect value to validate (E.G. '1-Litre').
11
- * @returns {boolean} Returns true if the value is in the expected format, false otherwise.
12
- */
13
- const isTwoHyphenSeparatedValues = value => {
14
- if (typeof value !== 'string' || value.indexOf('-') === -1) {
15
- return false;
16
- }
17
- const selectValue = [value.split('-').pop()];
18
- return Array.isArray(selectValue) && selectValue.length;
19
- };
20
-
21
- /**
22
- * Creates a custom 'equal' validator for a select component.
23
- * @param {Object[]} options - The select component options.
24
- * @returns {Object[]} Returns a custom 'equal' validator object for the select component.
25
- */
26
- const createCustomEqualValidator = options => [{
27
- type: 'equal',
28
- arguments: _.map(options, opt =>
29
- typeof opt === 'string' ? opt : opt.value)
30
- }];
31
-
32
- /**
33
- * Adds a validator to a field's validate array, ensuring no duplicates.
34
- * @param {Object} field - The field to add the validator to.
35
- * @param {Object|Object[]|string|string[]|function(string): boolean|(function(string): boolean)[]} newValidator -
36
- * The validator to add.
37
- */
38
- const addValidator = (field, newValidator) => {
39
- field.validate = _.uniq(field.validate.concat(newValidator));
40
- };
41
-
42
- /**
43
- * Adds the 'groupedFieldsWithOptions' property to the specified field.
44
- * This property prevents the 'equal' validator being applied to the parent component by default,
45
- * and enables it to separately be added to the unit child component instead.
46
- * @param {Object} field - The field to add the property to.
47
- */
48
- const addGroupedFieldsWithOptionsProperty = field => {
49
- field.groupedFieldsWithOptions = true;
50
- };
51
-
52
- /**
53
- * Resolves configurations related to making the amount and/or unit fields optional (E.G. amountOptional, unitOptional).
54
- * @param {Object[]} parentField - The parent component's field definition and configuration.
55
- * @param {Object[]} childFields - The child component's field definitions and configurations.
56
- * @param {Array} validators - The list of validators assigned to the parent component.
57
- * @param {string} key - The parent component's key.
58
- */
59
- const resolveOptionalFields = (parentField, childFields, validators, key) => {
60
- // adds existing required validators from parent component to the child components
61
- // and resolves configurations that determine if the child components should be optional
62
- validators?.indexOf('required') !== -1 || parentField[key]?.amountOptional !== 'true' &&
63
- addValidator(childFields[`${key}-amount`], 'required');
64
- validators?.indexOf('required') !== -1 || parentField[key]?.unitOptional !== 'true' &&
65
- addValidator(childFields[`${key}-unit`], 'required');
66
- };
67
-
68
- /**
69
- * Propagates the child component's (amount and unit) field data and values into the form request to enable validation.
70
- * @param {Object} formReq - The form's request object.
71
- * @param {Object[]} fields - The child components' definitions and configurations.
72
- * @param {string} key - The parent component's key.
73
- */
74
- const propagateChildFieldValidation = (formReq, fields, key) => {
75
- // adds child component field definitions to the form request
76
- Object.assign(formReq.options.fields,
77
- { 'amountWithUnitSelect-amount': fields[`${key}-amount`] },
78
- { 'amountWithUnitSelect-unit': fields[`${key}-unit`] }
79
- );
80
- // splits and assigns the component's values to the form request
81
- const amountWithUnitSelectValues = utils.getAmountWithUnitSelectValues(formReq.values.amountWithUnitSelect);
82
- Object.assign(formReq.values,
83
- { 'amountWithUnitSelect-amount': amountWithUnitSelectValues[0] },
84
- { 'amountWithUnitSelect-unit': amountWithUnitSelectValues[1] }
85
- );
86
- };
87
-
88
- /**
89
- * Moves validators, that are not the 'required' or 'equal' type, from the parent component to
90
- * the 'amount' child component,
91
- * ensuring all other validators are applied to the amount field only.
92
- * @param {Object} formReqFields - The fields in the form's request object (req.form.options.fields).
93
- * @param {Object[]} fields - The child components' definitions and configurations.
94
- * @param {string} key - The parent component's key.
95
- */
96
- const moveExcessValidatorToChildComponent = (formReqFields, fields, key) => {
97
- _.remove(formReqFields?.amountWithUnitSelect?.validate, validator => {
98
- if (!((typeof validator === 'object' &&
99
- (validator.type === 'equal' ||
100
- validator.type === 'required')) ||
101
- (typeof validator === 'string' &&
102
- (validator === 'equal' ||
103
- validator === 'required')))) {
104
- if (formReqFields[`${key}-amount`] === null) {
105
- Object.assign(formReqFields, {
106
- 'amountWithUnitSelect-amount': fields[`${key}-amount`]
107
- });
108
- }
109
- if (!formReqFields[`${key}-amount`]?.validate?.includes(validator)) {
110
- formReqFields[`${key}-amount`].validate.push(validator);
111
- }
112
- return true;
113
- }
114
- return false;
115
- });
116
- };
117
-
118
- /**
119
- * Creates and adds a validation error for a child component into the form request's errors list.
120
- * @param {Object} req - The request object given to the component.
121
- * @param {Object} res - The response object given to the component.
122
- * @param {Object[]} errors - The validation errors recorded in the session model.
123
- * @param {string} pKey - The parent component's key.
124
- * @param {string} key - The child component's key.
125
- */
126
- const addValidationError = (req, res, errors, pKey, key) => {
127
- // manually creates and adds an error object
128
- req.form.errors[`${pKey}-${key}`] = {
129
- errorLinkId: `${pKey}-${key}`,
130
- key: errors[`${pKey}-${key}`]?.key || `${key}-${key}`,
131
- type: errors[`${pKey}-${key}`]?.type || null
132
- };
133
- // ensure the error message is processed and translated by the controller
134
- req.form.errors[`${pKey}-${key}`].message =
135
- controller.getErrorMessage(req.form.errors[`${pKey}-${key}`], req, res) ||
136
- controller.getErrorMessage({
137
- errorLinkId: `${pKey}-${key}`,
138
- key: `${pKey}`,
139
- type: errors[`${pKey}-${key}`]?.type || null
140
- }, req, res);
141
- };
142
-
143
- /**
144
- * Inserts child component validation errors into the form request if there is no parent component error.
145
- * Only one error from the component is added to the request's error list in the order of the parent, amount,
146
- * and then unit component.
147
- * @param {Object} req - The request object given to the component.
148
- * @param {Object} res - The response object given to the component.
149
- * @param {Object[]} errors - The validation errors recorded in the session model.
150
- */
151
- const insertChildValidationErrors = (req, res, errors) => {
152
- const pKey = 'amountWithUnitSelect';
153
- let key;
154
- if (errors && !errors[pKey] && req?.form?.errors) {
155
- if (errors[`${pKey}-amount`] && req.form.errors[`${pKey}-amount`]) {
156
- key = 'amount';
157
- } else if (errors[`${pKey}-unit`] && req.form.errors[`${pKey}-unit`]) {
158
- key = 'unit';
159
- }
160
- }
161
- // if there are not parent or child errors, no errors are added
162
- key && addValidationError(req, res, errors, pKey, key);
163
- };
164
-
165
- module.exports = {
166
- isTwoHyphenSeparatedValues,
167
- createCustomEqualValidator,
168
- addValidator,
169
- addGroupedFieldsWithOptionsProperty,
170
- resolveOptionalFields,
171
- propagateChildFieldValidation,
172
- moveExcessValidatorToChildComponent,
173
- addValidationError,
174
- insertChildValidationErrors
175
- };
@@ -1,13 +0,0 @@
1
- <div class="{{amountWithUnitSelectItemClassName}}">
2
- <div id="{{id}}-group" class="{{#compound}} form-group-compound{{/compound}}{{#formGroupClassName}} {{formGroupClassName}}{{/formGroupClassName}}">
3
- <label for="{{id}}" class="{{labelClassName}}">
4
- <span class="label-text">{{{label}}}</span>
5
- </label>
6
- {{#hint}}<div {{$hintId}}id="{{hintId}}" {{/hintId}}class="govuk-hint">{{{hint}}}</div>{{/hint}}
7
- <select id="{{id}}" class="govuk-select{{#className}} {{className}}{{/className}}{{#error}} govuk-select--error{{/error}}" name="{{id}}" aria-required="{{required}}">
8
- {{#options}}
9
- <option value="{{value}}" {{#selected}}selected{{/selected}}>{{label}}</option>
10
- {{/options}}
11
- </select>
12
- </div>
13
- </div>
@@ -1,37 +0,0 @@
1
- <div class="{{amountWithUnitSelectItemClassName}}">
2
- <div id="{{id}}-group" class="{{#formGroupClassName}} {{formGroupClassName}}{{/formGroupClassName}}">
3
- <label for="{{id}}" class="{{labelClassName}}">
4
- <span class="label-text">{{{label}}}</span>
5
- </label>
6
- {{#hint}}<span {{$hintId}}id="{{hintId}}" {{/hintId}}class="govuk-hint">{{{hint}}}</span>{{/hint}}
7
- {{#renderChild}}{{/renderChild}}
8
- {{#attributes}}
9
- {{#prefix}}
10
- <div class="govuk-input__prefix" aria-hidden="true">{{prefix}}</div>
11
- {{/prefix}}
12
- {{/attributes}}
13
- <input
14
- type="{{type}}"
15
- name="{{id}}"
16
- id="{{id}}"
17
- class="govuk-input{{#className}} {{className}}{{/className}}{{#error}} govuk-input--error{{/error}}"
18
- aria-required="{{required}}"
19
- {{#value}} value="{{value}}"{{/value}}
20
- {{#min}} min="{{min}}"{{/min}}
21
- {{#max}} max="{{max}}"{{/max}}
22
- {{#maxlength}} maxlength="{{maxlength}}"{{/maxlength}}
23
- {{#pattern}} pattern="{{pattern}}"{{/pattern}}
24
- {{#hintId}} aria-describedby="{{hintId}}"{{/hintId}}
25
- {{#error}} aria-invalid="true"{{/error}}
26
- {{#autocomplete}} autocomplete="{{autocomplete}}"{{/autocomplete}}
27
- {{#attributes}}
28
- {{attribute}}="{{value}}"
29
- {{/attributes}}
30
- >
31
- {{#attributes}}
32
- {{#suffix}}
33
- <div class="govuk-input__prefix" aria-hidden="true">{{suffix}}</div>
34
- {{/suffix}}
35
- {{/attributes}}
36
- </div>
37
- </div>
@@ -1,5 +0,0 @@
1
- .grouped-inputs__item {
2
- display: inline-block;
3
- margin-right: 20px;
4
- margin-bottom: 0;
5
- }