@dwp/govuk-casa 8.7.12 → 8.9.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.
Files changed (173) hide show
  1. package/dist/casa.d.ts +12 -1
  2. package/dist/casa.js +10 -2
  3. package/dist/casa.js.map +1 -0
  4. package/dist/lib/CasaTemplateLoader.js +1 -0
  5. package/dist/lib/CasaTemplateLoader.js.map +1 -0
  6. package/dist/lib/JourneyContext.d.ts +12 -3
  7. package/dist/lib/JourneyContext.js +20 -5
  8. package/dist/lib/JourneyContext.js.map +1 -0
  9. package/dist/lib/MutableRouter.js +1 -0
  10. package/dist/lib/MutableRouter.js.map +1 -0
  11. package/dist/lib/Plan.d.ts +1 -1
  12. package/dist/lib/Plan.js +2 -5
  13. package/dist/lib/Plan.js.map +1 -0
  14. package/dist/lib/ValidationError.js +1 -0
  15. package/dist/lib/ValidationError.js.map +1 -0
  16. package/dist/lib/ValidatorFactory.d.ts +2 -2
  17. package/dist/lib/ValidatorFactory.js +3 -2
  18. package/dist/lib/ValidatorFactory.js.map +1 -0
  19. package/dist/lib/configuration-ingestor.js +1 -0
  20. package/dist/lib/configuration-ingestor.js.map +1 -0
  21. package/dist/lib/configure.js +2 -1
  22. package/dist/lib/configure.js.map +1 -0
  23. package/dist/lib/constants.d.ts +9 -0
  24. package/dist/lib/constants.js +13 -0
  25. package/dist/lib/constants.js.map +1 -0
  26. package/dist/lib/end-session.js +1 -0
  27. package/dist/lib/end-session.js.map +1 -0
  28. package/dist/lib/field.js +1 -0
  29. package/dist/lib/field.js.map +1 -0
  30. package/dist/lib/index.js +1 -0
  31. package/dist/lib/index.js.map +1 -0
  32. package/dist/lib/logger.js +1 -0
  33. package/dist/lib/logger.js.map +1 -0
  34. package/dist/lib/mount.js +3 -2
  35. package/dist/lib/mount.js.map +1 -0
  36. package/dist/lib/nunjucks-filters.js +1 -0
  37. package/dist/lib/nunjucks-filters.js.map +1 -0
  38. package/dist/lib/nunjucks.js +1 -0
  39. package/dist/lib/nunjucks.js.map +1 -0
  40. package/dist/lib/utils.d.ts +45 -27
  41. package/dist/lib/utils.js +105 -67
  42. package/dist/lib/utils.js.map +1 -0
  43. package/dist/lib/validators/dateObject.js +4 -3
  44. package/dist/lib/validators/dateObject.js.map +1 -0
  45. package/dist/lib/validators/email.js +1 -0
  46. package/dist/lib/validators/email.js.map +1 -0
  47. package/dist/lib/validators/inArray.js +1 -0
  48. package/dist/lib/validators/inArray.js.map +1 -0
  49. package/dist/lib/validators/index.js +1 -0
  50. package/dist/lib/validators/index.js.map +1 -0
  51. package/dist/lib/validators/nino.js +1 -0
  52. package/dist/lib/validators/nino.js.map +1 -0
  53. package/dist/lib/validators/postalAddressObject.d.ts +2 -2
  54. package/dist/lib/validators/postalAddressObject.js +2 -1
  55. package/dist/lib/validators/postalAddressObject.js.map +1 -0
  56. package/dist/lib/validators/regex.js +1 -0
  57. package/dist/lib/validators/regex.js.map +1 -0
  58. package/dist/lib/validators/required.js +1 -0
  59. package/dist/lib/validators/required.js.map +1 -0
  60. package/dist/lib/validators/strlen.js +1 -0
  61. package/dist/lib/validators/strlen.js.map +1 -0
  62. package/dist/lib/validators/wordCount.js +1 -0
  63. package/dist/lib/validators/wordCount.js.map +1 -0
  64. package/dist/lib/waypoint-url.js +40 -9
  65. package/dist/lib/waypoint-url.js.map +1 -0
  66. package/dist/middleware/body-parser.js +1 -0
  67. package/dist/middleware/body-parser.js.map +1 -0
  68. package/dist/middleware/csrf.js +1 -0
  69. package/dist/middleware/csrf.js.map +1 -0
  70. package/dist/middleware/data.js +1 -0
  71. package/dist/middleware/data.js.map +1 -0
  72. package/dist/middleware/gather-fields.js +10 -2
  73. package/dist/middleware/gather-fields.js.map +1 -0
  74. package/dist/middleware/i18n.js +1 -0
  75. package/dist/middleware/i18n.js.map +1 -0
  76. package/dist/middleware/post.js +1 -0
  77. package/dist/middleware/post.js.map +1 -0
  78. package/dist/middleware/pre.js +1 -0
  79. package/dist/middleware/pre.js.map +1 -0
  80. package/dist/middleware/progress-journey.js +7 -2
  81. package/dist/middleware/progress-journey.js.map +1 -0
  82. package/dist/middleware/sanitise-fields.js +1 -0
  83. package/dist/middleware/sanitise-fields.js.map +1 -0
  84. package/dist/middleware/serve-first-waypoint.js +1 -0
  85. package/dist/middleware/serve-first-waypoint.js.map +1 -0
  86. package/dist/middleware/session.js +1 -0
  87. package/dist/middleware/session.js.map +1 -0
  88. package/dist/middleware/skip-waypoint.js +1 -0
  89. package/dist/middleware/skip-waypoint.js.map +1 -0
  90. package/dist/middleware/steer-journey.js +2 -0
  91. package/dist/middleware/steer-journey.js.map +1 -0
  92. package/dist/middleware/strip-proxy-path.js +1 -0
  93. package/dist/middleware/strip-proxy-path.js.map +1 -0
  94. package/dist/middleware/validate-fields.js +7 -1
  95. package/dist/middleware/validate-fields.js.map +1 -0
  96. package/dist/mjs/esm-wrapper.js +11 -15
  97. package/dist/routes/ancillary.js +1 -0
  98. package/dist/routes/ancillary.js.map +1 -0
  99. package/dist/routes/journey.js +1 -0
  100. package/dist/routes/journey.js.map +1 -0
  101. package/dist/routes/static.js +1 -0
  102. package/dist/routes/static.js.map +1 -0
  103. package/locales/cy/error.json +1 -1
  104. package/locales/en/error.json +1 -1
  105. package/package.json +17 -16
  106. package/src/casa.js +330 -0
  107. package/src/lib/CasaTemplateLoader.js +104 -0
  108. package/src/lib/JourneyContext.js +797 -0
  109. package/src/lib/MutableRouter.js +310 -0
  110. package/src/lib/Plan.js +619 -0
  111. package/src/lib/ValidationError.js +163 -0
  112. package/src/lib/ValidatorFactory.js +105 -0
  113. package/src/lib/configuration-ingestor.js +457 -0
  114. package/src/lib/configure.js +202 -0
  115. package/src/lib/constants.js +9 -0
  116. package/src/lib/dirname.cjs +1 -0
  117. package/src/lib/end-session.js +45 -0
  118. package/src/lib/field.js +456 -0
  119. package/src/lib/index.js +33 -0
  120. package/src/lib/logger.js +16 -0
  121. package/src/lib/mount.js +127 -0
  122. package/src/lib/nunjucks-filters.js +150 -0
  123. package/src/lib/nunjucks.js +53 -0
  124. package/src/lib/utils.js +232 -0
  125. package/src/lib/validators/dateObject.js +169 -0
  126. package/src/lib/validators/email.js +55 -0
  127. package/src/lib/validators/inArray.js +81 -0
  128. package/src/lib/validators/index.js +24 -0
  129. package/src/lib/validators/nino.js +57 -0
  130. package/src/lib/validators/postalAddressObject.js +162 -0
  131. package/src/lib/validators/regex.js +48 -0
  132. package/src/lib/validators/required.js +74 -0
  133. package/src/lib/validators/strlen.js +66 -0
  134. package/src/lib/validators/wordCount.js +70 -0
  135. package/src/lib/waypoint-url.js +126 -0
  136. package/src/middleware/body-parser.js +31 -0
  137. package/src/middleware/csrf.js +29 -0
  138. package/src/middleware/data.js +105 -0
  139. package/src/middleware/dirname.cjs +1 -0
  140. package/src/middleware/gather-fields.js +58 -0
  141. package/src/middleware/i18n.js +106 -0
  142. package/src/middleware/post.js +61 -0
  143. package/src/middleware/pre.js +91 -0
  144. package/src/middleware/progress-journey.js +96 -0
  145. package/src/middleware/sanitise-fields.js +58 -0
  146. package/src/middleware/serve-first-waypoint.js +28 -0
  147. package/src/middleware/session.js +129 -0
  148. package/src/middleware/skip-waypoint.js +46 -0
  149. package/src/middleware/steer-journey.js +79 -0
  150. package/src/middleware/strip-proxy-path.js +56 -0
  151. package/src/middleware/validate-fields.js +89 -0
  152. package/src/routes/ancillary.js +29 -0
  153. package/src/routes/dirname.cjs +1 -0
  154. package/src/routes/journey.js +212 -0
  155. package/src/routes/static.js +77 -0
  156. package/views/casa/components/character-count/README.md +10 -0
  157. package/views/casa/components/character-count/template.njk +6 -2
  158. package/views/casa/components/checkboxes/README.md +43 -34
  159. package/views/casa/components/checkboxes/template.njk +8 -7
  160. package/views/casa/components/date-input/README.md +11 -1
  161. package/views/casa/components/date-input/template.njk +6 -4
  162. package/views/casa/components/input/README.md +9 -0
  163. package/views/casa/components/input/template.njk +6 -2
  164. package/views/casa/components/postal-address-object/README.md +10 -0
  165. package/views/casa/components/postal-address-object/template.njk +20 -5
  166. package/views/casa/components/radios/README.md +49 -24
  167. package/views/casa/components/radios/template.njk +6 -3
  168. package/views/casa/components/select/README.md +65 -0
  169. package/views/casa/components/select/macro.njk +3 -0
  170. package/views/casa/components/select/template.njk +49 -0
  171. package/views/casa/components/textarea/README.md +9 -0
  172. package/views/casa/components/textarea/template.njk +6 -2
  173. package/views/casa/layouts/journey.njk +1 -1
@@ -13,45 +13,66 @@ Custom parameters:
13
13
  Basic example:
14
14
 
15
15
  ```nunjucks
16
- {% from "casa/components/radios/macro.njk" import casaGovukRadios with context %}
16
+ {% from 'casa/components/radios/macro.njk' import casaGovukRadios with context %}
17
17
 
18
18
  {{ casaGovukRadios({
19
- name: 'myInput',
20
- casaValue: formData.myInput,
19
+ name: 'preference',
20
+ casaValue: formData.preference,
21
21
  casaErrors: formErrors,
22
- items: [{
23
- text: 'Yes',
24
- value: 'yes'
25
- }, {
26
- text: 'No',
27
- value: 'no'
28
- }]
22
+ fieldset: {
23
+ legend: {
24
+ text: 'Choose your preference',
25
+ isPageHeading: true,
26
+ classes: 'govuk-fieldset__legend--xl'
27
+ }
28
+ },
29
+ hint: {
30
+ text: 'Some instructive hints'
31
+ },
32
+ items: [
33
+ {
34
+ value: 'twoReeds',
35
+ text: 'Two Reeds'
36
+ }, {
37
+ value: 'twistedFlax',
38
+ text: 'Twisted Flax'
39
+ }, {
40
+ value: 'water',
41
+ text: 'Water'
42
+ }, {
43
+ value: 'eyeOfHorus',
44
+ text: 'Eye of Horus'
45
+ }
46
+ ]
29
47
  }) }}
30
48
  ```
31
49
 
32
50
  If you want one of the radio items to toggle the display of an element:
33
51
 
34
52
  ```nunjucks
35
- {% from "casa/components/radios/macro.njk" import casaGovukRadios with context %}
53
+ {% from 'casa/components/radios/macro.njk' import casaGovukRadios with context %}
36
54
 
37
55
  {% set panel %}
38
- This panel will remain hidden until the "Yes" radio button is chosen
56
+ This panel will remain hidden until the 'Yes' radio button is chosen
39
57
  {% endset %}
40
58
 
41
59
  {{ casaGovukRadios({
42
- name: 'myInput',
43
- casaValue: formData.myInput,
60
+ name: 'preference',
61
+ casaValue: formData.preference,
44
62
  casaErrors: formErrors,
45
- items: [{
46
- text: 'Yes',
47
- value: 'yes',
48
- conditional: {
49
- html: panel
63
+ items: [
64
+ {
65
+ value: 'yes',
66
+ text: 'Yes',
67
+ conditional: {
68
+ html: panel
69
+ }
70
+ },
71
+ {
72
+ value: 'no',
73
+ text: 'No'
50
74
  }
51
- }, {
52
- text: 'No',
53
- value: 'no'
54
- }]
75
+ ]
55
76
  }) }}
56
77
  ```
57
78
 
@@ -61,13 +82,17 @@ ref: <https://design-system.service.gov.uk/components/error-summary/>
61
82
 
62
83
  The error summary link must set focus on the first radio in the group. Unless you have specified an explicit `id` for the first item in the list, this macro will explicitly set that `id` to `f-<name>`, e.g. `f-preferences` in order for links from the error summary to work as expected.
63
84
 
64
- ## Google Tag Manager
85
+ ## Google Analytics
65
86
 
66
87
  The following attributes will be attached to each `<input>` option if `casaWithAnalytics` is `true`:
67
88
 
68
89
  * `data-ga-question`: Holds the fieldset legend's content
69
90
  * `data-ga-answer`: Holds the specific answer's text/html value
70
91
 
92
+ The following attributes will be attached to the error `<p>` tag if `casaWithAnalytics` is `true`:
93
+
94
+ * `data-ga-question`: Holds the fieldset legend's content after removing all html tags
95
+
71
96
  These are the conventions used by DWP.
72
97
 
73
98
  > **IMPORTANT:** DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google
@@ -1,4 +1,4 @@
1
- {% from "govuk/components/radios/macro.njk" import govukRadios %}
1
+ {% from 'govuk/components/radios/macro.njk' import govukRadios %}
2
2
 
3
3
  {% set fieldErrors = params.casaErrors[params.name] %}
4
4
 
@@ -10,7 +10,7 @@
10
10
  }) %}
11
11
  {% endif %}
12
12
 
13
- {# Add checked flag to chosen input #}
13
+ {# Add checked flag to chosen item #}
14
14
  {% set mergedItems = [] %}
15
15
  {% for item in params.items %}
16
16
  {% set item = mergeObjects({
@@ -30,7 +30,10 @@
30
30
  attributes: mergedAttributes,
31
31
  items: mergedItems,
32
32
  errorMessage: {
33
- text: t(params.casaErrors[params.name][0].inline, params.casaErrors[params.name][0].variables)
33
+ text: t(params.casaErrors[params.name][0].inline, params.casaErrors[params.name][0].variables),
34
+ attributes: {
35
+ 'data-ga-question': params.fieldset.legend.text or params.fieldset.legend.html | striptags
36
+ } if params.casaWithAnalytics else {}
34
37
  } if params.casaErrors[params.name].length
35
38
  }) %}
36
39
 
@@ -0,0 +1,65 @@
1
+ # `casaGovukSelect()`
2
+
3
+ Extends the [`govukSelect()`](https://design-system.service.gov.uk/components/select/) macro.
4
+
5
+ Custom parameters:
6
+
7
+ * `casaValue` - the value of the selected option. This is a convenience for toggling the `selected` flag on the appropriate `item`, but you can also manually set `selected` on each item of you need to use more specific logic for determining selected state.
8
+ * `casaErrors` - form errors (just pass `formErrors`)
9
+ * `casaWithAnalytics` - enable DWP's conventional Google Analytics attributes (`data-ga-question` and `data-ga-answer`) - `false` by default; **IMPORTANT: DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google**
10
+
11
+ ## Example usage
12
+
13
+ Basic example:
14
+
15
+ ```nunjucks
16
+ {% from 'casa/components/select/macro.njk' import casaGovukSelect with context %}
17
+
18
+ {{ casaGovukSelect({
19
+ name: 'preference',
20
+ casaValue: formData.preference,
21
+ casaErrors: formErrors,
22
+ label: {
23
+ text: 'Choose your preference'
24
+ },
25
+ hint: {
26
+ text: 'Some instructive hints'
27
+ },
28
+ items: [
29
+ {
30
+ value: 'twoReeds',
31
+ text: 'Two Reeds'
32
+ }, {
33
+ value: 'twistedFlax',
34
+ text: 'Twisted Flax'
35
+ }, {
36
+ value: 'water',
37
+ text: 'Water'
38
+ }, {
39
+ value: 'eyeOfHorus',
40
+ text: 'Eye of Horus'
41
+ }
42
+ ]
43
+ }) }}
44
+ ```
45
+
46
+ <!-- ## Displaying errors
47
+
48
+ ref: <https://design-system.service.gov.uk/components/error-summary/>
49
+
50
+ The error summary link must set focus on the select item in the group. Unless you have specified an explicit `id` for the first item in the list, this macro will explicitly set that `id` to `f-<name>`, e.g. `f-preferences` in order for links from the error summary to work as expected. -->
51
+
52
+ ## Google Analytics
53
+
54
+ The following attributes will be attached to each `<input>` option if `casaWithAnalytics` is `true`:
55
+
56
+ * `data-ga-question`: Holds the fieldset legend's content
57
+ * `data-ga-answer`: Holds the specific answer's text/html value
58
+
59
+ The following attributes will be attached to the error `<p>` tag if `casaWithAnalytics` is `true`:
60
+
61
+ * `data-ga-question`: Holds the fieldset legend's content after removing all html tags
62
+
63
+ These are the conventions used by DWP.
64
+
65
+ > **IMPORTANT:** DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google
@@ -0,0 +1,3 @@
1
+ {% macro casaGovukSelect(params) %}
2
+ {%- include './template.njk' -%}
3
+ {% endmacro %}
@@ -0,0 +1,49 @@
1
+ {% from 'govuk/components/select/macro.njk' import govukSelect %}
2
+
3
+ {% set fieldErrors = params.casaErrors[params.name] %}
4
+
5
+ {# Generate validation data- attributes #}
6
+ {% set mergedAttributes = params.attributes or {} %}
7
+ {% if fieldErrors %}
8
+ {% set mergedAttributes = mergeObjects(mergedAttributes, {
9
+ 'data-validation': {fn: params.name, va: fieldErrors[0].validator} | dump
10
+ }) %}
11
+ {% endif %}
12
+
13
+ {# Add selected flag to chosen item #}
14
+ {% set mergedItems = [] %}
15
+ {% for item in params.items %}
16
+ {% set item = mergeObjects({
17
+ attributes: {
18
+ 'data-ga-question': params.label.text or params.label.html,
19
+ 'data-ga-answer': item.text or item.html
20
+ }
21
+ } if params.casaWithAnalytics else {}, item, {
22
+ selected: true if item.selected or item.value == params.casaValue else false
23
+ }) %}
24
+ {% set mergedItems = (mergedItems.push(item), mergedItems) %}
25
+ {% endfor %}
26
+
27
+ {# Merge parameters #}
28
+ {% set mergedParams = mergeObjects(params, {
29
+ id: params.id if params.id else 'f-' + params.name,
30
+ attributes: mergedAttributes,
31
+ items: mergedItems,
32
+ errorMessage: {
33
+ text: t(params.casaErrors[params.name][0].inline, params.casaErrors[params.name][0].variables),
34
+ attributes: {
35
+ 'data-ga-question': params.label.text or params.label.html | striptags
36
+ } if params.casaWithAnalytics else {}
37
+ } if params.casaErrors[params.name].length
38
+ }) %}
39
+
40
+ {# Ensure that the first item has the id matching `f-<name>` in order for error summary linkage to work
41
+ {% if not mergedParams.items[0].id %}
42
+ {% set mergedParams = mergeObjects(mergedParams, {
43
+ items: [{
44
+ id: 'f-' + params.name
45
+ }]
46
+ }) %}
47
+ {% endif %} #}
48
+
49
+ {{ govukSelect(mergedParams) }}
@@ -19,3 +19,12 @@ casaGovukTextarea({
19
19
  casaErrors: formErrors
20
20
  })
21
21
  ```
22
+ ## Google Tag Manager
23
+
24
+ The following attributes will be attached to the error `<p>` tag if `casaWithAnalytics` is `true`:
25
+
26
+ * `data-ga-question`: Holds the fieldset label's text content after removing all html tags
27
+
28
+ These are the conventions used by DWP.
29
+
30
+ > **IMPORTANT:** DO NOT ENABLE this option if the question or answer may contain personally-identifiable information as values will be pushed to Google
@@ -1,4 +1,4 @@
1
- {% from "govuk/components/textarea/macro.njk" import govukTextarea %}
1
+ {% from 'govuk/components/textarea/macro.njk' import govukTextarea %}
2
2
 
3
3
  {% set fieldErrors = params.casaErrors[params.name] %}
4
4
 
@@ -10,11 +10,15 @@
10
10
  }) %}
11
11
  {% endif %}
12
12
 
13
+ {# Merge parameters #}
13
14
  {% set mergedParams = mergeObjects(params, {
14
15
  id: params.id if params.id else 'f-' + params.name,
15
16
  attributes: mergedAttributes,
16
17
  errorMessage: {
17
- text: t(params.casaErrors[params.name][0].inline, params.casaErrors[params.name][0].variables)
18
+ text: t(params.casaErrors[params.name][0].inline, params.casaErrors[params.name][0].variables),
19
+ attributes: {
20
+ 'data-ga-question': params.label.text or params.label.html | striptags
21
+ } if params.casaWithAnalytics else {}
18
22
  } if params.casaErrors[params.name].length
19
23
  }) %}
20
24
 
@@ -22,7 +22,7 @@
22
22
 
23
23
  {# Use `casaPageTitle` instead of `pageTitle` if you want CASA to automatically prefix with `Error` when appropriate #}
24
24
  {% block pageTitle -%}
25
- {{- t("error:documentTtlePrefix") if formErrors -}}
25
+ {{- t("error:documentTitlePrefix") if formErrors -}}
26
26
  {% block casaPageTitle %}{% endblock %}
27
27
  {%- endblock %}
28
28