@ministryofjustice/frontend 4.0.1 → 5.1.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 (256) hide show
  1. package/govuk-prototype-kit.config.json +19 -4
  2. package/moj/_base.scss +2 -0
  3. package/moj/_base.scss.map +1 -0
  4. package/moj/all.bundle.js +3010 -0
  5. package/moj/all.bundle.js.map +1 -0
  6. package/moj/all.bundle.mjs +3293 -0
  7. package/moj/all.bundle.mjs.map +1 -0
  8. package/moj/all.mjs +17 -110
  9. package/moj/all.mjs.map +1 -1
  10. package/moj/all.scss +3 -0
  11. package/moj/all.scss.map +1 -0
  12. package/moj/common/index.mjs +57 -0
  13. package/moj/common/index.mjs.map +1 -0
  14. package/moj/common/moj-frontend-version.mjs +14 -0
  15. package/moj/common/moj-frontend-version.mjs.map +1 -0
  16. package/moj/components/_all.scss +2 -0
  17. package/moj/components/_all.scss.map +1 -0
  18. package/moj/components/action-bar/_action-bar.scss +2 -0
  19. package/moj/components/action-bar/_action-bar.scss.map +1 -0
  20. package/moj/components/add-another/_add-another.scss +2 -0
  21. package/moj/components/add-another/_add-another.scss.map +1 -0
  22. package/moj/components/add-another/add-another.bundle.js +157 -0
  23. package/moj/components/add-another/add-another.bundle.js.map +1 -0
  24. package/moj/components/add-another/add-another.bundle.mjs +271 -0
  25. package/moj/components/add-another/add-another.bundle.mjs.map +1 -0
  26. package/moj/components/add-another/add-another.mjs +135 -91
  27. package/moj/components/add-another/add-another.mjs.map +1 -1
  28. package/moj/components/alert/_alert.scss +4 -0
  29. package/moj/components/alert/_alert.scss.map +1 -0
  30. package/moj/components/alert/alert.bundle.js +254 -0
  31. package/moj/components/alert/alert.bundle.js.map +1 -0
  32. package/moj/components/alert/alert.bundle.mjs +490 -0
  33. package/moj/components/alert/alert.bundle.mjs.map +1 -0
  34. package/moj/components/alert/alert.mjs +97 -218
  35. package/moj/components/alert/alert.mjs.map +1 -1
  36. package/moj/components/alert/{alert.spec.helper.js → alert.spec.helper.bundle.js} +1 -1
  37. package/moj/components/alert/alert.spec.helper.bundle.js.map +1 -0
  38. package/moj/components/alert/alert.spec.helper.bundle.mjs +67 -0
  39. package/moj/components/alert/alert.spec.helper.bundle.mjs.map +1 -0
  40. package/moj/components/alert/alert.spec.helper.mjs.map +1 -1
  41. package/moj/components/badge/_badge.scss +2 -0
  42. package/moj/components/badge/_badge.scss.map +1 -0
  43. package/moj/components/banner/_banner.scss +2 -0
  44. package/moj/components/banner/_banner.scss.map +1 -0
  45. package/moj/components/button-menu/README.md +12 -6
  46. package/moj/components/button-menu/_button-menu.scss +4 -1
  47. package/moj/components/button-menu/_button-menu.scss.map +1 -0
  48. package/moj/components/button-menu/button-menu.bundle.js +270 -0
  49. package/moj/components/button-menu/button-menu.bundle.js.map +1 -0
  50. package/moj/components/button-menu/button-menu.bundle.mjs +506 -0
  51. package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -0
  52. package/moj/components/button-menu/button-menu.mjs +214 -280
  53. package/moj/components/button-menu/button-menu.mjs.map +1 -1
  54. package/moj/components/cookie-banner/_cookie-banner.scss +2 -0
  55. package/moj/components/cookie-banner/_cookie-banner.scss.map +1 -0
  56. package/moj/components/currency-input/_currency-input.scss +2 -0
  57. package/moj/components/currency-input/_currency-input.scss.map +1 -0
  58. package/moj/components/date-picker/_date-picker.scss +2 -0
  59. package/moj/components/date-picker/_date-picker.scss.map +1 -0
  60. package/moj/components/date-picker/date-picker.bundle.js +804 -0
  61. package/moj/components/date-picker/date-picker.bundle.js.map +1 -0
  62. package/moj/components/date-picker/date-picker.bundle.mjs +1040 -0
  63. package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -0
  64. package/moj/components/date-picker/date-picker.mjs +663 -827
  65. package/moj/components/date-picker/date-picker.mjs.map +1 -1
  66. package/moj/components/filter/_filter.scss +2 -0
  67. package/moj/components/filter/_filter.scss.map +1 -0
  68. package/moj/components/filter/template.njk +1 -1
  69. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +185 -0
  70. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -0
  71. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +421 -0
  72. package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -0
  73. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +166 -81
  74. package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
  75. package/moj/components/form-validator/form-validator.bundle.js +288 -0
  76. package/moj/components/form-validator/form-validator.bundle.js.map +1 -0
  77. package/moj/components/form-validator/form-validator.bundle.mjs +524 -0
  78. package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -0
  79. package/moj/components/form-validator/form-validator.mjs +226 -149
  80. package/moj/components/form-validator/form-validator.mjs.map +1 -1
  81. package/moj/components/header/_header.scss +2 -0
  82. package/moj/components/header/_header.scss.map +1 -0
  83. package/moj/components/identity-bar/_identity-bar.scss +2 -0
  84. package/moj/components/identity-bar/_identity-bar.scss.map +1 -0
  85. package/moj/components/interruption-card/_interruption-card.scss +2 -0
  86. package/moj/components/interruption-card/_interruption-card.scss.map +1 -0
  87. package/moj/components/messages/_messages.scss +2 -0
  88. package/moj/components/messages/_messages.scss.map +1 -0
  89. package/moj/components/multi-file-upload/_multi-file-upload.scss +2 -0
  90. package/moj/components/multi-file-upload/_multi-file-upload.scss.map +1 -0
  91. package/moj/components/multi-file-upload/multi-file-upload.bundle.js +397 -0
  92. package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -0
  93. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +633 -0
  94. package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -0
  95. package/moj/components/multi-file-upload/multi-file-upload.mjs +384 -213
  96. package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
  97. package/moj/components/multi-file-upload/template.njk +1 -1
  98. package/moj/components/multi-select/_multi-select.scss +2 -0
  99. package/moj/components/multi-select/_multi-select.scss.map +1 -0
  100. package/moj/components/multi-select/multi-select.bundle.js +143 -0
  101. package/moj/components/multi-select/multi-select.bundle.js.map +1 -0
  102. package/moj/components/multi-select/multi-select.bundle.mjs +379 -0
  103. package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -0
  104. package/moj/components/multi-select/multi-select.mjs +123 -64
  105. package/moj/components/multi-select/multi-select.mjs.map +1 -1
  106. package/moj/components/notification-badge/_notification-badge.scss +2 -0
  107. package/moj/components/notification-badge/_notification-badge.scss.map +1 -0
  108. package/moj/components/organisation-switcher/_organisation-switcher.scss +2 -0
  109. package/moj/components/organisation-switcher/_organisation-switcher.scss.map +1 -0
  110. package/moj/components/page-header-actions/_page-header-actions.scss +2 -0
  111. package/moj/components/page-header-actions/_page-header-actions.scss.map +1 -0
  112. package/moj/components/pagination/_pagination.scss +2 -2
  113. package/moj/components/pagination/_pagination.scss.map +1 -0
  114. package/moj/components/password-reveal/_password-reveal.scss +5 -1
  115. package/moj/components/password-reveal/_password-reveal.scss.map +1 -0
  116. package/moj/components/password-reveal/password-reveal.bundle.js +52 -0
  117. package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -0
  118. package/moj/components/password-reveal/password-reveal.bundle.mjs +166 -0
  119. package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -0
  120. package/moj/components/password-reveal/password-reveal.mjs +39 -29
  121. package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
  122. package/moj/components/primary-navigation/_primary-navigation.scss +2 -0
  123. package/moj/components/primary-navigation/_primary-navigation.scss.map +1 -0
  124. package/moj/components/progress-bar/_progress-bar.scss +2 -0
  125. package/moj/components/progress-bar/_progress-bar.scss.map +1 -0
  126. package/moj/components/rich-text-editor/README.md +16 -9
  127. package/moj/components/rich-text-editor/_rich-text-editor.scss +2 -0
  128. package/moj/components/rich-text-editor/_rich-text-editor.scss.map +1 -0
  129. package/moj/components/rich-text-editor/rich-text-editor.bundle.js +210 -0
  130. package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -0
  131. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +446 -0
  132. package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -0
  133. package/moj/components/rich-text-editor/rich-text-editor.mjs +186 -140
  134. package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
  135. package/moj/components/search/_search.scss +2 -0
  136. package/moj/components/search/_search.scss.map +1 -0
  137. package/moj/components/search-toggle/{search-toggle.scss → _search-toggle.scss} +2 -0
  138. package/moj/components/search-toggle/_search-toggle.scss.map +1 -0
  139. package/moj/components/search-toggle/search-toggle.bundle.js +122 -0
  140. package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -0
  141. package/moj/components/search-toggle/search-toggle.bundle.mjs +358 -0
  142. package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -0
  143. package/moj/components/search-toggle/search-toggle.mjs +104 -43
  144. package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
  145. package/moj/components/side-navigation/_side-navigation.scss +2 -0
  146. package/moj/components/side-navigation/_side-navigation.scss.map +1 -0
  147. package/moj/components/sortable-table/_sortable-table.scss +2 -2
  148. package/moj/components/sortable-table/_sortable-table.scss.map +1 -0
  149. package/moj/components/sortable-table/sortable-table.bundle.js +202 -0
  150. package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -0
  151. package/moj/components/sortable-table/sortable-table.bundle.mjs +438 -0
  152. package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -0
  153. package/moj/components/sortable-table/sortable-table.mjs +179 -122
  154. package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
  155. package/moj/components/sub-navigation/_sub-navigation.scss +2 -0
  156. package/moj/components/sub-navigation/_sub-navigation.scss.map +1 -0
  157. package/moj/components/tag/_tag.scss +2 -0
  158. package/moj/components/tag/_tag.scss.map +1 -0
  159. package/moj/components/task-list/_task-list.scss +2 -0
  160. package/moj/components/task-list/_task-list.scss.map +1 -0
  161. package/moj/components/ticket-panel/_ticket-panel.scss +2 -0
  162. package/moj/components/ticket-panel/_ticket-panel.scss.map +1 -0
  163. package/moj/components/timeline/_timeline.scss +2 -0
  164. package/moj/components/timeline/_timeline.scss.map +1 -0
  165. package/moj/core/_all.scss +3 -0
  166. package/moj/core/_all.scss.map +1 -0
  167. package/moj/core/_moj-frontend-properties.scss +7 -0
  168. package/moj/core/_moj-frontend-properties.scss.map +1 -0
  169. package/moj/filters/all.js +44 -22
  170. package/moj/filters/prototype-kit-13-filters.js +4 -3
  171. package/moj/helpers/_all.scss +2 -0
  172. package/moj/helpers/_all.scss.map +1 -0
  173. package/moj/helpers/_hidden.scss +2 -0
  174. package/moj/helpers/_hidden.scss.map +1 -0
  175. package/moj/helpers/_links.scss +2 -0
  176. package/moj/helpers/_links.scss.map +1 -0
  177. package/moj/helpers.bundle.js +140 -0
  178. package/moj/helpers.bundle.js.map +1 -0
  179. package/moj/helpers.bundle.mjs +128 -0
  180. package/moj/helpers.bundle.mjs.map +1 -0
  181. package/moj/helpers.mjs +50 -77
  182. package/moj/helpers.mjs.map +1 -1
  183. package/moj/init.js +11 -2
  184. package/moj/moj-frontend.min.css +1 -1
  185. package/moj/moj-frontend.min.css.map +1 -1
  186. package/moj/moj-frontend.min.js +1 -1
  187. package/moj/moj-frontend.min.js.map +1 -1
  188. package/moj/objects/_all.scss +2 -0
  189. package/moj/objects/_all.scss.map +1 -0
  190. package/moj/objects/_button-group.scss +2 -0
  191. package/moj/objects/_button-group.scss.map +1 -0
  192. package/moj/objects/_filter-layout.scss +2 -0
  193. package/moj/objects/_filter-layout.scss.map +1 -0
  194. package/moj/objects/_scrollable-pane.scss +2 -0
  195. package/moj/objects/_scrollable-pane.scss.map +1 -0
  196. package/moj/objects/_width-container.scss +2 -0
  197. package/moj/objects/_width-container.scss.map +1 -0
  198. package/moj/settings/_all.scss +2 -0
  199. package/moj/settings/_all.scss.map +1 -0
  200. package/moj/settings/_assets.scss +2 -0
  201. package/moj/settings/_assets.scss.map +1 -0
  202. package/moj/settings/_colours.scss +2 -0
  203. package/moj/settings/_colours.scss.map +1 -0
  204. package/moj/settings/_measurements.scss +2 -0
  205. package/moj/settings/_measurements.scss.map +1 -0
  206. package/moj/settings/_typography.scss +2 -0
  207. package/moj/settings/_typography.scss.map +1 -0
  208. package/moj/template.njk +13 -0
  209. package/moj/utilities/_all.scss +2 -0
  210. package/moj/utilities/_all.scss.map +1 -0
  211. package/moj/utilities/_hidden.scss +2 -0
  212. package/moj/utilities/_hidden.scss.map +1 -0
  213. package/moj/utilities/_width-container.scss +2 -0
  214. package/moj/utilities/_width-container.scss.map +1 -0
  215. package/moj/vendor/govuk-frontend/_base.scss +2 -0
  216. package/moj/vendor/govuk-frontend/_base.scss.map +1 -0
  217. package/moj/vendor/govuk-frontend/_index.scss +2 -0
  218. package/moj/vendor/govuk-frontend/_index.scss.map +1 -0
  219. package/package.json +5 -6
  220. package/moj/all.jquery.min.js +0 -1
  221. package/moj/all.jquery.min.js.map +0 -1
  222. package/moj/all.js +0 -2662
  223. package/moj/all.js.map +0 -1
  224. package/moj/components/add-another/add-another.js +0 -115
  225. package/moj/components/add-another/add-another.js.map +0 -1
  226. package/moj/components/alert/alert.js +0 -356
  227. package/moj/components/alert/alert.js.map +0 -1
  228. package/moj/components/alert/alert.spec.helper.js.map +0 -1
  229. package/moj/components/button-menu/button-menu.js +0 -338
  230. package/moj/components/button-menu/button-menu.js.map +0 -1
  231. package/moj/components/date-picker/date-picker.js +0 -970
  232. package/moj/components/date-picker/date-picker.js.map +0 -1
  233. package/moj/components/filter-toggle-button/filter-toggle-button.js +0 -102
  234. package/moj/components/filter-toggle-button/filter-toggle-button.js.map +0 -1
  235. package/moj/components/form-validator/form-validator.js +0 -205
  236. package/moj/components/form-validator/form-validator.js.map +0 -1
  237. package/moj/components/multi-file-upload/multi-file-upload.js +0 -241
  238. package/moj/components/multi-file-upload/multi-file-upload.js.map +0 -1
  239. package/moj/components/multi-select/multi-select.js +0 -86
  240. package/moj/components/multi-select/multi-select.js.map +0 -1
  241. package/moj/components/password-reveal/password-reveal.js +0 -44
  242. package/moj/components/password-reveal/password-reveal.js.map +0 -1
  243. package/moj/components/rich-text-editor/rich-text-editor.js +0 -166
  244. package/moj/components/rich-text-editor/rich-text-editor.js.map +0 -1
  245. package/moj/components/search-toggle/search-toggle.js +0 -63
  246. package/moj/components/search-toggle/search-toggle.js.map +0 -1
  247. package/moj/components/sortable-table/sortable-table.js +0 -147
  248. package/moj/components/sortable-table/sortable-table.js.map +0 -1
  249. package/moj/helpers.js +0 -200
  250. package/moj/helpers.js.map +0 -1
  251. package/moj/vendor/html5shiv.js +0 -326
  252. package/moj/vendor/jquery.js +0 -9300
  253. package/moj/version.js +0 -12
  254. package/moj/version.js.map +0 -1
  255. package/moj/version.mjs +0 -4
  256. package/moj/version.mjs.map +0 -1
@@ -0,0 +1,271 @@
1
+ function isInitialised($root, moduleName) {
2
+ return $root instanceof HTMLElement && $root.hasAttribute(`data-${moduleName}-init`);
3
+ }
4
+
5
+ /**
6
+ * Checks if GOV.UK Frontend is supported on this page
7
+ *
8
+ * Some browsers will load and run our JavaScript but GOV.UK Frontend
9
+ * won't be supported.
10
+ *
11
+ * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support
12
+ * @returns {boolean} Whether GOV.UK Frontend is supported on this page
13
+ */
14
+ function isSupported($scope = document.body) {
15
+ if (!$scope) {
16
+ return false;
17
+ }
18
+ return $scope.classList.contains('govuk-frontend-supported');
19
+ }
20
+ function formatErrorMessage(Component, message) {
21
+ return `${Component.moduleName}: ${message}`;
22
+ }
23
+
24
+ class GOVUKFrontendError extends Error {
25
+ constructor(...args) {
26
+ super(...args);
27
+ this.name = 'GOVUKFrontendError';
28
+ }
29
+ }
30
+ class SupportError extends GOVUKFrontendError {
31
+ /**
32
+ * Checks if GOV.UK Frontend is supported on this page
33
+ *
34
+ * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support
35
+ */
36
+ constructor($scope = document.body) {
37
+ const supportMessage = 'noModule' in HTMLScriptElement.prototype ? 'GOV.UK Frontend initialised without `<body class="govuk-frontend-supported">` from template `<script>` snippet' : 'GOV.UK Frontend is not supported in this browser';
38
+ super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type="module">`');
39
+ this.name = 'SupportError';
40
+ }
41
+ }
42
+ class ElementError extends GOVUKFrontendError {
43
+ constructor(messageOrOptions) {
44
+ let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
45
+ if (typeof messageOrOptions === 'object') {
46
+ const {
47
+ component,
48
+ identifier,
49
+ element,
50
+ expectedType
51
+ } = messageOrOptions;
52
+ message = identifier;
53
+ message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';
54
+ message = formatErrorMessage(component, message);
55
+ }
56
+ super(message);
57
+ this.name = 'ElementError';
58
+ }
59
+ }
60
+ class InitError extends GOVUKFrontendError {
61
+ constructor(componentOrMessage) {
62
+ const message = typeof componentOrMessage === 'string' ? componentOrMessage : formatErrorMessage(componentOrMessage, `Root element (\`$root\`) already initialised`);
63
+ super(message);
64
+ this.name = 'InitError';
65
+ }
66
+ }
67
+
68
+ class Component {
69
+ /**
70
+ * Returns the root element of the component
71
+ *
72
+ * @protected
73
+ * @returns {RootElementType} - the root element of component
74
+ */
75
+ get $root() {
76
+ return this._$root;
77
+ }
78
+ constructor($root) {
79
+ this._$root = void 0;
80
+ const childConstructor = this.constructor;
81
+ if (typeof childConstructor.moduleName !== 'string') {
82
+ throw new InitError(`\`moduleName\` not defined in component`);
83
+ }
84
+ if (!($root instanceof childConstructor.elementType)) {
85
+ throw new ElementError({
86
+ element: $root,
87
+ component: childConstructor,
88
+ identifier: 'Root element (`$root`)',
89
+ expectedType: childConstructor.elementType.name
90
+ });
91
+ } else {
92
+ this._$root = $root;
93
+ }
94
+ childConstructor.checkSupport();
95
+ this.checkInitialised();
96
+ const moduleName = childConstructor.moduleName;
97
+ this.$root.setAttribute(`data-${moduleName}-init`, '');
98
+ }
99
+ checkInitialised() {
100
+ const constructor = this.constructor;
101
+ const moduleName = constructor.moduleName;
102
+ if (moduleName && isInitialised(this.$root, moduleName)) {
103
+ throw new InitError(constructor);
104
+ }
105
+ }
106
+ static checkSupport() {
107
+ if (!isSupported()) {
108
+ throw new SupportError();
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * @typedef ChildClass
115
+ * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component
116
+ */
117
+
118
+ /**
119
+ * @typedef {typeof Component & ChildClass} ChildClassConstructor
120
+ */
121
+ Component.elementType = HTMLElement;
122
+
123
+ class AddAnother extends Component {
124
+ /**
125
+ * @param {Element | null} $root - HTML element to use for add another
126
+ */
127
+ constructor($root) {
128
+ super($root);
129
+ this.$root.addEventListener('click', this.onRemoveButtonClick.bind(this));
130
+ this.$root.addEventListener('click', this.onAddButtonClick.bind(this));
131
+ const $buttons = this.$root.querySelectorAll('.moj-add-another__add-button, moj-add-another__remove-button');
132
+ $buttons.forEach($button => {
133
+ if (!($button instanceof HTMLButtonElement)) {
134
+ return;
135
+ }
136
+ $button.type = 'button';
137
+ });
138
+ }
139
+
140
+ /**
141
+ * @param {MouseEvent} event - Click event
142
+ */
143
+ onAddButtonClick(event) {
144
+ const $button = event.target;
145
+ if (!$button || !($button instanceof HTMLButtonElement) || !$button.classList.contains('moj-add-another__add-button')) {
146
+ return;
147
+ }
148
+ const $items = this.getItems();
149
+ const $item = this.getNewItem();
150
+ if (!$item || !($item instanceof HTMLElement)) {
151
+ return;
152
+ }
153
+ this.updateAttributes($item, $items.length);
154
+ this.resetItem($item);
155
+ const $firstItem = $items[0];
156
+ if (!this.hasRemoveButton($firstItem)) {
157
+ this.createRemoveButton($firstItem);
158
+ }
159
+ $items[$items.length - 1].after($item);
160
+ const $input = $item.querySelector('input, textarea, select');
161
+ if ($input && $input instanceof HTMLInputElement) {
162
+ $input.focus();
163
+ }
164
+ }
165
+
166
+ /**
167
+ * @param {HTMLElement} $item - Add another item
168
+ */
169
+ hasRemoveButton($item) {
170
+ return $item.querySelectorAll('.moj-add-another__remove-button').length;
171
+ }
172
+ getItems() {
173
+ if (!this.$root) {
174
+ return [];
175
+ }
176
+ const $items = Array.from(this.$root.querySelectorAll('.moj-add-another__item'));
177
+ return $items.filter(item => item instanceof HTMLElement);
178
+ }
179
+ getNewItem() {
180
+ const $items = this.getItems();
181
+ const $item = $items[0].cloneNode(true);
182
+ if (!$item || !($item instanceof HTMLElement)) {
183
+ return;
184
+ }
185
+ if (!this.hasRemoveButton($item)) {
186
+ this.createRemoveButton($item);
187
+ }
188
+ return $item;
189
+ }
190
+
191
+ /**
192
+ * @param {HTMLElement} $item - Add another item
193
+ * @param {number} index - Add another item index
194
+ */
195
+ updateAttributes($item, index) {
196
+ $item.querySelectorAll('[data-name]').forEach($input => {
197
+ if (!($input instanceof HTMLInputElement)) {
198
+ return;
199
+ }
200
+ const name = $input.getAttribute('data-name') || '';
201
+ const id = $input.getAttribute('data-id') || '';
202
+ const originalId = $input.id;
203
+ $input.name = name.replace(/%index%/, `${index}`);
204
+ $input.id = id.replace(/%index%/, `${index}`);
205
+ const $label = $input.parentElement.querySelector('label') || $input.closest('label') || $item.querySelector(`[for="${originalId}"]`);
206
+ if ($label && $label instanceof HTMLLabelElement) {
207
+ $label.htmlFor = $input.id;
208
+ }
209
+ });
210
+ }
211
+
212
+ /**
213
+ * @param {HTMLElement} $item - Add another item
214
+ */
215
+ createRemoveButton($item) {
216
+ const $button = document.createElement('button');
217
+ $button.type = 'button';
218
+ $button.classList.add('govuk-button', 'govuk-button--secondary', 'moj-add-another__remove-button');
219
+ $button.textContent = 'Remove';
220
+ $item.append($button);
221
+ }
222
+
223
+ /**
224
+ * @param {HTMLElement} $item - Add another item
225
+ */
226
+ resetItem($item) {
227
+ $item.querySelectorAll('[data-name], [data-id]').forEach($input => {
228
+ if (!($input instanceof HTMLInputElement)) {
229
+ return;
230
+ }
231
+ if ($input.type === 'checkbox' || $input.type === 'radio') {
232
+ $input.checked = false;
233
+ } else {
234
+ $input.value = '';
235
+ }
236
+ });
237
+ }
238
+
239
+ /**
240
+ * @param {MouseEvent} event - Click event
241
+ */
242
+ onRemoveButtonClick(event) {
243
+ const $button = event.target;
244
+ if (!$button || !($button instanceof HTMLButtonElement) || !$button.classList.contains('moj-add-another__remove-button')) {
245
+ return;
246
+ }
247
+ $button.closest('.moj-add-another__item').remove();
248
+ const $items = this.getItems();
249
+ if ($items.length === 1) {
250
+ $items[0].querySelector('.moj-add-another__remove-button').remove();
251
+ }
252
+ $items.forEach(($item, index) => {
253
+ this.updateAttributes($item, index);
254
+ });
255
+ this.focusHeading();
256
+ }
257
+ focusHeading() {
258
+ const $heading = this.$root.querySelector('.moj-add-another__heading');
259
+ if ($heading && $heading instanceof HTMLElement) {
260
+ $heading.focus();
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Name for the component used when initialising using data-module attributes.
266
+ */
267
+ }
268
+ AddAnother.moduleName = 'moj-add-another';
269
+
270
+ export { AddAnother };
271
+ //# sourceMappingURL=add-another.bundle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-another.bundle.mjs","sources":["../../../../node_modules/govuk-frontend/dist/govuk/common/index.mjs","../../../../node_modules/govuk-frontend/dist/govuk/errors/index.mjs","../../../../node_modules/govuk-frontend/dist/govuk/component.mjs","../../../../src/moj/components/add-another/add-another.mjs"],"sourcesContent":["function getFragmentFromUrl(url) {\n if (!url.includes('#')) {\n return undefined;\n }\n return url.split('#').pop();\n}\nfunction getBreakpoint(name) {\n const property = `--govuk-frontend-breakpoint-${name}`;\n const value = window.getComputedStyle(document.documentElement).getPropertyValue(property);\n return {\n property,\n value: value || undefined\n };\n}\nfunction setFocus($element, options = {}) {\n var _options$onBeforeFocu;\n const isFocusable = $element.getAttribute('tabindex');\n if (!isFocusable) {\n $element.setAttribute('tabindex', '-1');\n }\n function onFocus() {\n $element.addEventListener('blur', onBlur, {\n once: true\n });\n }\n function onBlur() {\n var _options$onBlur;\n (_options$onBlur = options.onBlur) == null || _options$onBlur.call($element);\n if (!isFocusable) {\n $element.removeAttribute('tabindex');\n }\n }\n $element.addEventListener('focus', onFocus, {\n once: true\n });\n (_options$onBeforeFocu = options.onBeforeFocus) == null || _options$onBeforeFocu.call($element);\n $element.focus();\n}\nfunction isInitialised($root, moduleName) {\n return $root instanceof HTMLElement && $root.hasAttribute(`data-${moduleName}-init`);\n}\n\n/**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * Some browsers will load and run our JavaScript but GOV.UK Frontend\n * won't be supported.\n *\n * @param {HTMLElement | null} [$scope] - (internal) `<body>` HTML element checked for browser support\n * @returns {boolean} Whether GOV.UK Frontend is supported on this page\n */\nfunction isSupported($scope = document.body) {\n if (!$scope) {\n return false;\n }\n return $scope.classList.contains('govuk-frontend-supported');\n}\nfunction isArray(option) {\n return Array.isArray(option);\n}\nfunction isObject(option) {\n return !!option && typeof option === 'object' && !isArray(option);\n}\nfunction formatErrorMessage(Component, message) {\n return `${Component.moduleName}: ${message}`;\n}\n/**\n * @typedef ComponentWithModuleName\n * @property {string} moduleName - Name of the component\n */\n/**\n * @import { ObjectNested } from './configuration.mjs'\n */\n\nexport { formatErrorMessage, getBreakpoint, getFragmentFromUrl, isInitialised, isObject, isSupported, setFocus };\n//# sourceMappingURL=index.mjs.map\n","import { formatErrorMessage } from '../common/index.mjs';\n\nclass GOVUKFrontendError extends Error {\n constructor(...args) {\n super(...args);\n this.name = 'GOVUKFrontendError';\n }\n}\nclass SupportError extends GOVUKFrontendError {\n /**\n * Checks if GOV.UK Frontend is supported on this page\n *\n * @param {HTMLElement | null} [$scope] - HTML element `<body>` checked for browser support\n */\n constructor($scope = document.body) {\n const supportMessage = 'noModule' in HTMLScriptElement.prototype ? 'GOV.UK Frontend initialised without `<body class=\"govuk-frontend-supported\">` from template `<script>` snippet' : 'GOV.UK Frontend is not supported in this browser';\n super($scope ? supportMessage : 'GOV.UK Frontend initialised without `<script type=\"module\">`');\n this.name = 'SupportError';\n }\n}\nclass ConfigError extends GOVUKFrontendError {\n constructor(...args) {\n super(...args);\n this.name = 'ConfigError';\n }\n}\nclass ElementError extends GOVUKFrontendError {\n constructor(messageOrOptions) {\n let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';\n if (typeof messageOrOptions === 'object') {\n const {\n component,\n identifier,\n element,\n expectedType\n } = messageOrOptions;\n message = identifier;\n message += element ? ` is not of type ${expectedType != null ? expectedType : 'HTMLElement'}` : ' not found';\n message = formatErrorMessage(component, message);\n }\n super(message);\n this.name = 'ElementError';\n }\n}\nclass InitError extends GOVUKFrontendError {\n constructor(componentOrMessage) {\n const message = typeof componentOrMessage === 'string' ? componentOrMessage : formatErrorMessage(componentOrMessage, `Root element (\\`$root\\`) already initialised`);\n super(message);\n this.name = 'InitError';\n }\n}\n/**\n * @import { ComponentWithModuleName } from '../common/index.mjs'\n */\n\nexport { ConfigError, ElementError, GOVUKFrontendError, InitError, SupportError };\n//# sourceMappingURL=index.mjs.map\n","import { isInitialised, isSupported } from './common/index.mjs';\nimport { InitError, ElementError, SupportError } from './errors/index.mjs';\n\nclass Component {\n /**\n * Returns the root element of the component\n *\n * @protected\n * @returns {RootElementType} - the root element of component\n */\n get $root() {\n return this._$root;\n }\n constructor($root) {\n this._$root = void 0;\n const childConstructor = this.constructor;\n if (typeof childConstructor.moduleName !== 'string') {\n throw new InitError(`\\`moduleName\\` not defined in component`);\n }\n if (!($root instanceof childConstructor.elementType)) {\n throw new ElementError({\n element: $root,\n component: childConstructor,\n identifier: 'Root element (`$root`)',\n expectedType: childConstructor.elementType.name\n });\n } else {\n this._$root = $root;\n }\n childConstructor.checkSupport();\n this.checkInitialised();\n const moduleName = childConstructor.moduleName;\n this.$root.setAttribute(`data-${moduleName}-init`, '');\n }\n checkInitialised() {\n const constructor = this.constructor;\n const moduleName = constructor.moduleName;\n if (moduleName && isInitialised(this.$root, moduleName)) {\n throw new InitError(constructor);\n }\n }\n static checkSupport() {\n if (!isSupported()) {\n throw new SupportError();\n }\n }\n}\n\n/**\n * @typedef ChildClass\n * @property {string} moduleName - The module name that'll be looked for in the DOM when initialising the component\n */\n\n/**\n * @typedef {typeof Component & ChildClass} ChildClassConstructor\n */\nComponent.elementType = HTMLElement;\n\nexport { Component };\n//# sourceMappingURL=component.mjs.map\n","import { Component } from 'govuk-frontend'\n\nexport class AddAnother extends Component {\n /**\n * @param {Element | null} $root - HTML element to use for add another\n */\n constructor($root) {\n super($root)\n\n this.$root.addEventListener('click', this.onRemoveButtonClick.bind(this))\n this.$root.addEventListener('click', this.onAddButtonClick.bind(this))\n\n const $buttons = this.$root.querySelectorAll(\n '.moj-add-another__add-button, moj-add-another__remove-button'\n )\n\n $buttons.forEach(($button) => {\n if (!($button instanceof HTMLButtonElement)) {\n return\n }\n\n $button.type = 'button'\n })\n }\n\n /**\n * @param {MouseEvent} event - Click event\n */\n onAddButtonClick(event) {\n const $button = event.target\n\n if (\n !$button ||\n !($button instanceof HTMLButtonElement) ||\n !$button.classList.contains('moj-add-another__add-button')\n ) {\n return\n }\n\n const $items = this.getItems()\n const $item = this.getNewItem()\n\n if (!$item || !($item instanceof HTMLElement)) {\n return\n }\n\n this.updateAttributes($item, $items.length)\n this.resetItem($item)\n\n const $firstItem = $items[0]\n if (!this.hasRemoveButton($firstItem)) {\n this.createRemoveButton($firstItem)\n }\n\n $items[$items.length - 1].after($item)\n\n const $input = $item.querySelector('input, textarea, select')\n if ($input && $input instanceof HTMLInputElement) {\n $input.focus()\n }\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n */\n hasRemoveButton($item) {\n return $item.querySelectorAll('.moj-add-another__remove-button').length\n }\n\n getItems() {\n if (!this.$root) {\n return []\n }\n\n const $items = Array.from(\n this.$root.querySelectorAll('.moj-add-another__item')\n )\n\n return $items.filter((item) => item instanceof HTMLElement)\n }\n\n getNewItem() {\n const $items = this.getItems()\n const $item = $items[0].cloneNode(true)\n\n if (!$item || !($item instanceof HTMLElement)) {\n return\n }\n\n if (!this.hasRemoveButton($item)) {\n this.createRemoveButton($item)\n }\n\n return $item\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n * @param {number} index - Add another item index\n */\n updateAttributes($item, index) {\n $item.querySelectorAll('[data-name]').forEach(($input) => {\n if (!($input instanceof HTMLInputElement)) {\n return\n }\n\n const name = $input.getAttribute('data-name') || ''\n const id = $input.getAttribute('data-id') || ''\n const originalId = $input.id\n\n $input.name = name.replace(/%index%/, `${index}`)\n $input.id = id.replace(/%index%/, `${index}`)\n\n const $label =\n $input.parentElement.querySelector('label') ||\n $input.closest('label') ||\n $item.querySelector(`[for=\"${originalId}\"]`)\n\n if ($label && $label instanceof HTMLLabelElement) {\n $label.htmlFor = $input.id\n }\n })\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n */\n createRemoveButton($item) {\n const $button = document.createElement('button')\n $button.type = 'button'\n\n $button.classList.add(\n 'govuk-button',\n 'govuk-button--secondary',\n 'moj-add-another__remove-button'\n )\n\n $button.textContent = 'Remove'\n\n $item.append($button)\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n */\n resetItem($item) {\n $item.querySelectorAll('[data-name], [data-id]').forEach(($input) => {\n if (!($input instanceof HTMLInputElement)) {\n return\n }\n\n if ($input.type === 'checkbox' || $input.type === 'radio') {\n $input.checked = false\n } else {\n $input.value = ''\n }\n })\n }\n\n /**\n * @param {MouseEvent} event - Click event\n */\n onRemoveButtonClick(event) {\n const $button = event.target\n\n if (\n !$button ||\n !($button instanceof HTMLButtonElement) ||\n !$button.classList.contains('moj-add-another__remove-button')\n ) {\n return\n }\n\n $button.closest('.moj-add-another__item').remove()\n\n const $items = this.getItems()\n\n if ($items.length === 1) {\n $items[0].querySelector('.moj-add-another__remove-button').remove()\n }\n\n $items.forEach(($item, index) => {\n this.updateAttributes($item, index)\n })\n\n this.focusHeading()\n }\n\n focusHeading() {\n const $heading = this.$root.querySelector('.moj-add-another__heading')\n\n if ($heading && $heading instanceof HTMLElement) {\n $heading.focus()\n }\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'moj-add-another'\n}\n"],"names":["isInitialised","$root","moduleName","HTMLElement","hasAttribute","isSupported","$scope","document","body","classList","contains","formatErrorMessage","Component","message","GOVUKFrontendError","Error","constructor","args","name","SupportError","supportMessage","HTMLScriptElement","prototype","ElementError","messageOrOptions","component","identifier","element","expectedType","InitError","componentOrMessage","_$root","childConstructor","elementType","checkSupport","checkInitialised","setAttribute","AddAnother","addEventListener","onRemoveButtonClick","bind","onAddButtonClick","$buttons","querySelectorAll","forEach","$button","HTMLButtonElement","type","event","target","$items","getItems","$item","getNewItem","updateAttributes","length","resetItem","$firstItem","hasRemoveButton","createRemoveButton","after","$input","querySelector","HTMLInputElement","focus","Array","from","filter","item","cloneNode","index","getAttribute","id","originalId","replace","$label","parentElement","closest","HTMLLabelElement","htmlFor","createElement","add","textContent","append","checked","value","remove","focusHeading","$heading"],"mappings":"AAqGO,SAASA,aAAaA,CAACC,KAAK,EAAEC,UAAU,EAAE;EAC/C,OACED,KAAK,YAAYE,WAAW,IAC5BF,KAAK,CAACG,YAAY,CAAC,CAAA,KAAA,EAAQF,UAAU,CAAA,KAAA,CAAO,CAAC;AAEjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,WAAWA,CAACC,MAAM,GAAGC,QAAQ,CAACC,IAAI,EAAE;EAClD,IAAI,CAACF,MAAM,EAAE;AACX,IAAA,OAAO,KAAK;AACd;AAEA,EAAA,OAAOA,MAAM,CAACG,SAAS,CAACC,QAAQ,CAAC,0BAA0B,CAAC;AAC9D;AAiCO,SAASC,kBAAkBA,CAACC,SAAS,EAAEC,OAAO,EAAE;AACrD,EAAA,OAAO,GAAGD,SAAS,CAACV,UAAU,CAAA,EAAA,EAAKW,OAAO,CAAE,CAAA;AAC9C;;ACxIO,MAAMC,kBAAkB,SAASC,KAAK,CAAC;AAAAC,EAAAA,WAAAA,CAAA,GAAAC,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAAA,IAAA,CA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pC,MAAM,GAAG,IAAI,CAACC,QAAQ,EAAE;AAE9B,IAAA,IAAID,MAAM,CAACK,MAAM,KAAK,CAAC,EAAE;MACvBL,MAAM,CAAC,CAAC,CAAC,CAACY,aAAa,CAAC,iCAAiC,CAAC,CAACwB,MAAM,EAAE;AACrE;AAEApC,IAAAA,MAAM,CAACN,OAAO,CAAC,CAACQ,KAAK,EAAEkB,KAAK,KAAK;AAC/B,MAAA,IAAI,CAAChB,gBAAgB,CAACF,KAAK,EAAEkB,KAAK,CAAC;AACrC,KAAC,CAAC;IAEF,IAAI,CAACiB,YAAY,EAAE;AACrB;AAEAA,EAAAA,YAAYA,GAAG;IACb,MAAMC,QAAQ,GAAG,IAAI,CAACvF,KAAK,CAAC6D,aAAa,CAAC,2BAA2B,CAAC;AAEtE,IAAA,IAAI0B,QAAQ,IAAIA,QAAQ,YAAYrF,WAAW,EAAE;MAC/CqF,QAAQ,CAACxB,KAAK,EAAE;AAClB;AACF;;AAEA;AACF;AACA;AAEA;AAtMa3B,UAAU,CAqMdnC,UAAU,GAAG,iBAAiB;;;;","x_google_ignoreList":[0,1,2]}
@@ -1,107 +1,151 @@
1
- function AddAnother(container) {
2
- this.container = $(container);
1
+ import { Component } from 'govuk-frontend';
3
2
 
4
- if (this.container.data('moj-add-another-initialised')) {
5
- return
3
+ class AddAnother extends Component {
4
+ /**
5
+ * @param {Element | null} $root - HTML element to use for add another
6
+ */
7
+ constructor($root) {
8
+ super($root);
9
+ this.$root.addEventListener('click', this.onRemoveButtonClick.bind(this));
10
+ this.$root.addEventListener('click', this.onAddButtonClick.bind(this));
11
+ const $buttons = this.$root.querySelectorAll('.moj-add-another__add-button, moj-add-another__remove-button');
12
+ $buttons.forEach($button => {
13
+ if (!($button instanceof HTMLButtonElement)) {
14
+ return;
15
+ }
16
+ $button.type = 'button';
17
+ });
6
18
  }
7
19
 
8
- this.container.data('moj-add-another-initialised', true);
9
-
10
- this.container.on(
11
- 'click',
12
- '.moj-add-another__remove-button',
13
- $.proxy(this, 'onRemoveButtonClick')
14
- );
15
- this.container.on(
16
- 'click',
17
- '.moj-add-another__add-button',
18
- $.proxy(this, 'onAddButtonClick')
19
- );
20
- this.container
21
- .find('.moj-add-another__add-button, moj-add-another__remove-button')
22
- .prop('type', 'button');
23
- }
24
-
25
- AddAnother.prototype.onAddButtonClick = function (e) {
26
- const item = this.getNewItem();
27
- this.updateAttributes(this.getItems().length, item);
28
- this.resetItem(item);
29
- const firstItem = this.getItems().first();
30
- if (!this.hasRemoveButton(firstItem)) {
31
- this.createRemoveButton(firstItem);
20
+ /**
21
+ * @param {MouseEvent} event - Click event
22
+ */
23
+ onAddButtonClick(event) {
24
+ const $button = event.target;
25
+ if (!$button || !($button instanceof HTMLButtonElement) || !$button.classList.contains('moj-add-another__add-button')) {
26
+ return;
27
+ }
28
+ const $items = this.getItems();
29
+ const $item = this.getNewItem();
30
+ if (!$item || !($item instanceof HTMLElement)) {
31
+ return;
32
+ }
33
+ this.updateAttributes($item, $items.length);
34
+ this.resetItem($item);
35
+ const $firstItem = $items[0];
36
+ if (!this.hasRemoveButton($firstItem)) {
37
+ this.createRemoveButton($firstItem);
38
+ }
39
+ $items[$items.length - 1].after($item);
40
+ const $input = $item.querySelector('input, textarea, select');
41
+ if ($input && $input instanceof HTMLInputElement) {
42
+ $input.focus();
43
+ }
32
44
  }
33
- this.getItems().last().after(item);
34
- item.find('input, textarea, select').first().focus();
35
- };
36
-
37
- AddAnother.prototype.hasRemoveButton = function (item) {
38
- return item.find('.moj-add-another__remove-button').length
39
- };
40
-
41
- AddAnother.prototype.getItems = function () {
42
- return this.container.find('.moj-add-another__item')
43
- };
44
45
 
45
- AddAnother.prototype.getNewItem = function () {
46
- const item = this.getItems().first().clone();
47
- if (!this.hasRemoveButton(item)) {
48
- this.createRemoveButton(item);
46
+ /**
47
+ * @param {HTMLElement} $item - Add another item
48
+ */
49
+ hasRemoveButton($item) {
50
+ return $item.querySelectorAll('.moj-add-another__remove-button').length;
51
+ }
52
+ getItems() {
53
+ if (!this.$root) {
54
+ return [];
55
+ }
56
+ const $items = Array.from(this.$root.querySelectorAll('.moj-add-another__item'));
57
+ return $items.filter(item => item instanceof HTMLElement);
58
+ }
59
+ getNewItem() {
60
+ const $items = this.getItems();
61
+ const $item = $items[0].cloneNode(true);
62
+ if (!$item || !($item instanceof HTMLElement)) {
63
+ return;
64
+ }
65
+ if (!this.hasRemoveButton($item)) {
66
+ this.createRemoveButton($item);
67
+ }
68
+ return $item;
49
69
  }
50
- return item
51
- };
52
-
53
- AddAnother.prototype.updateAttributes = function (index, item) {
54
- item.find('[data-name]').each(function (i, el) {
55
- const originalId = el.id;
56
70
 
57
- el.name = $(el)
58
- .attr('data-name')
59
- .replace(/%index%/, index);
60
- el.id = $(el)
61
- .attr('data-id')
62
- .replace(/%index%/, index);
71
+ /**
72
+ * @param {HTMLElement} $item - Add another item
73
+ * @param {number} index - Add another item index
74
+ */
75
+ updateAttributes($item, index) {
76
+ $item.querySelectorAll('[data-name]').forEach($input => {
77
+ if (!($input instanceof HTMLInputElement)) {
78
+ return;
79
+ }
80
+ const name = $input.getAttribute('data-name') || '';
81
+ const id = $input.getAttribute('data-id') || '';
82
+ const originalId = $input.id;
83
+ $input.name = name.replace(/%index%/, `${index}`);
84
+ $input.id = id.replace(/%index%/, `${index}`);
85
+ const $label = $input.parentElement.querySelector('label') || $input.closest('label') || $item.querySelector(`[for="${originalId}"]`);
86
+ if ($label && $label instanceof HTMLLabelElement) {
87
+ $label.htmlFor = $input.id;
88
+ }
89
+ });
90
+ }
63
91
 
64
- const label =
65
- $(el).siblings('label')[0] ||
66
- $(el).parents('label')[0] ||
67
- item.find(`[for="${originalId}"]`)[0];
68
- label.htmlFor = el.id;
69
- });
70
- };
92
+ /**
93
+ * @param {HTMLElement} $item - Add another item
94
+ */
95
+ createRemoveButton($item) {
96
+ const $button = document.createElement('button');
97
+ $button.type = 'button';
98
+ $button.classList.add('govuk-button', 'govuk-button--secondary', 'moj-add-another__remove-button');
99
+ $button.textContent = 'Remove';
100
+ $item.append($button);
101
+ }
71
102
 
72
- AddAnother.prototype.createRemoveButton = function (item) {
73
- item.append(
74
- '<button type="button" class="govuk-button govuk-button--secondary moj-add-another__remove-button">Remove</button>'
75
- );
76
- };
103
+ /**
104
+ * @param {HTMLElement} $item - Add another item
105
+ */
106
+ resetItem($item) {
107
+ $item.querySelectorAll('[data-name], [data-id]').forEach($input => {
108
+ if (!($input instanceof HTMLInputElement)) {
109
+ return;
110
+ }
111
+ if ($input.type === 'checkbox' || $input.type === 'radio') {
112
+ $input.checked = false;
113
+ } else {
114
+ $input.value = '';
115
+ }
116
+ });
117
+ }
77
118
 
78
- AddAnother.prototype.resetItem = function (item) {
79
- item.find('[data-name], [data-id]').each(function (index, el) {
80
- if (el.type === 'checkbox' || el.type === 'radio') {
81
- el.checked = false;
82
- } else {
83
- el.value = '';
119
+ /**
120
+ * @param {MouseEvent} event - Click event
121
+ */
122
+ onRemoveButtonClick(event) {
123
+ const $button = event.target;
124
+ if (!$button || !($button instanceof HTMLButtonElement) || !$button.classList.contains('moj-add-another__remove-button')) {
125
+ return;
126
+ }
127
+ $button.closest('.moj-add-another__item').remove();
128
+ const $items = this.getItems();
129
+ if ($items.length === 1) {
130
+ $items[0].querySelector('.moj-add-another__remove-button').remove();
131
+ }
132
+ $items.forEach(($item, index) => {
133
+ this.updateAttributes($item, index);
134
+ });
135
+ this.focusHeading();
136
+ }
137
+ focusHeading() {
138
+ const $heading = this.$root.querySelector('.moj-add-another__heading');
139
+ if ($heading && $heading instanceof HTMLElement) {
140
+ $heading.focus();
84
141
  }
85
- });
86
- };
87
-
88
- AddAnother.prototype.onRemoveButtonClick = function (e) {
89
- $(e.currentTarget).parents('.moj-add-another__item').remove();
90
- const items = this.getItems();
91
- if (items.length === 1) {
92
- items.find('.moj-add-another__remove-button').remove();
93
142
  }
94
- items.each(
95
- $.proxy(function (index, el) {
96
- this.updateAttributes(index, $(el));
97
- }, this)
98
- );
99
- this.focusHeading();
100
- };
101
143
 
102
- AddAnother.prototype.focusHeading = function () {
103
- this.container.find('.moj-add-another__heading').get(0).focus();
104
- };
144
+ /**
145
+ * Name for the component used when initialising using data-module attributes.
146
+ */
147
+ }
148
+ AddAnother.moduleName = 'moj-add-another';
105
149
 
106
150
  export { AddAnother };
107
151
  //# sourceMappingURL=add-another.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"add-another.mjs","sources":["../../../../src/moj/components/add-another/add-another.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function AddAnother(container) {\n this.container = $(container)\n\n if (this.container.data('moj-add-another-initialised')) {\n return\n }\n\n this.container.data('moj-add-another-initialised', true)\n\n this.container.on(\n 'click',\n '.moj-add-another__remove-button',\n $.proxy(this, 'onRemoveButtonClick')\n )\n this.container.on(\n 'click',\n '.moj-add-another__add-button',\n $.proxy(this, 'onAddButtonClick')\n )\n this.container\n .find('.moj-add-another__add-button, moj-add-another__remove-button')\n .prop('type', 'button')\n}\n\nAddAnother.prototype.onAddButtonClick = function (e) {\n const item = this.getNewItem()\n this.updateAttributes(this.getItems().length, item)\n this.resetItem(item)\n const firstItem = this.getItems().first()\n if (!this.hasRemoveButton(firstItem)) {\n this.createRemoveButton(firstItem)\n }\n this.getItems().last().after(item)\n item.find('input, textarea, select').first().focus()\n}\n\nAddAnother.prototype.hasRemoveButton = function (item) {\n return item.find('.moj-add-another__remove-button').length\n}\n\nAddAnother.prototype.getItems = function () {\n return this.container.find('.moj-add-another__item')\n}\n\nAddAnother.prototype.getNewItem = function () {\n const item = this.getItems().first().clone()\n if (!this.hasRemoveButton(item)) {\n this.createRemoveButton(item)\n }\n return item\n}\n\nAddAnother.prototype.updateAttributes = function (index, item) {\n item.find('[data-name]').each(function (i, el) {\n const originalId = el.id\n\n el.name = $(el)\n .attr('data-name')\n .replace(/%index%/, index)\n el.id = $(el)\n .attr('data-id')\n .replace(/%index%/, index)\n\n const label =\n $(el).siblings('label')[0] ||\n $(el).parents('label')[0] ||\n item.find(`[for=\"${originalId}\"]`)[0]\n label.htmlFor = el.id\n })\n}\n\nAddAnother.prototype.createRemoveButton = function (item) {\n item.append(\n '<button type=\"button\" class=\"govuk-button govuk-button--secondary moj-add-another__remove-button\">Remove</button>'\n )\n}\n\nAddAnother.prototype.resetItem = function (item) {\n item.find('[data-name], [data-id]').each(function (index, el) {\n if (el.type === 'checkbox' || el.type === 'radio') {\n el.checked = false\n } else {\n el.value = ''\n }\n })\n}\n\nAddAnother.prototype.onRemoveButtonClick = function (e) {\n $(e.currentTarget).parents('.moj-add-another__item').remove()\n const items = this.getItems()\n if (items.length === 1) {\n items.find('.moj-add-another__remove-button').remove()\n }\n items.each(\n $.proxy(function (index, el) {\n this.updateAttributes(index, $(el))\n }, this)\n )\n this.focusHeading()\n}\n\nAddAnother.prototype.focusHeading = function () {\n this.container.find('.moj-add-another__heading').get(0).focus()\n}\n"],"names":[],"mappings":"AAEA,SAAA,UAAA,CAAA,SAAA,EAAA;AACA,EAAA,IAAA,CAAA,SAAA,GAAA,CAAA,CAAA,SAAA;;AAEA,EAAA,IAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,6BAAA,CAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,6BAAA,EAAA,IAAA;;AAEA,EAAA,IAAA,CAAA,SAAA,CAAA,EAAA;AACA,IAAA,OAAA;AACA,IAAA,iCAAA;AACA,IAAA,CAAA,CAAA,KAAA,CAAA,IAAA,EAAA,qBAAA;AACA;AACA,EAAA,IAAA,CAAA,SAAA,CAAA,EAAA;AACA,IAAA,OAAA;AACA,IAAA,8BAAA;AACA,IAAA,CAAA,CAAA,KAAA,CAAA,IAAA,EAAA,kBAAA;AACA;AACA,EAAA,IAAA,CAAA;AACA,KAAA,IAAA,CAAA,8DAAA;AACA,KAAA,IAAA,CAAA,MAAA,EAAA,QAAA;AACA;;AAEA,UAAA,CAAA,SAAA,CAAA,gBAAA,GAAA,UAAA,CAA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A,KAAA,GAAA,IAAA,CAAA,QAAA;AACA,EAAA,IAAA,KAAA,CAAA,MAAA,KAAA,CAAA,EAAA;AACA,IAAA,KAAA,CAAA,IAAA,CAAA,iCAAA,CAAA,CAAA,MAAA;AACA;AACA,EAAA,KAAA,CAAA,IAAA;AACA,IAAA,CAAA,CAAA,KAAA,CAAA,UAAA,KAAA,EAAA,EAAA,EAAA;AACA,MAAA,IAAA,CAAA,gBAAA,CAAA,KAAA,EAAA,CAAA,CAAA,EAAA,CAAA;AACA,KAAA,EAAA,IAAA;AACA;AACA,EAAA,IAAA,CAAA,YAAA;AACA;;AAEA,UAAA,CAAA,SAAA,CAAA,YAAA,GAAA,YAAA;AACA,EAAA,IAAA,CAAA,SAAA,CAAA,IAAA,CAAA,2BAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,KAAA;AACA;;;;"}
1
+ {"version":3,"file":"add-another.mjs","sources":["../../../../src/moj/components/add-another/add-another.mjs"],"sourcesContent":["import { Component } from 'govuk-frontend'\n\nexport class AddAnother extends Component {\n /**\n * @param {Element | null} $root - HTML element to use for add another\n */\n constructor($root) {\n super($root)\n\n this.$root.addEventListener('click', this.onRemoveButtonClick.bind(this))\n this.$root.addEventListener('click', this.onAddButtonClick.bind(this))\n\n const $buttons = this.$root.querySelectorAll(\n '.moj-add-another__add-button, moj-add-another__remove-button'\n )\n\n $buttons.forEach(($button) => {\n if (!($button instanceof HTMLButtonElement)) {\n return\n }\n\n $button.type = 'button'\n })\n }\n\n /**\n * @param {MouseEvent} event - Click event\n */\n onAddButtonClick(event) {\n const $button = event.target\n\n if (\n !$button ||\n !($button instanceof HTMLButtonElement) ||\n !$button.classList.contains('moj-add-another__add-button')\n ) {\n return\n }\n\n const $items = this.getItems()\n const $item = this.getNewItem()\n\n if (!$item || !($item instanceof HTMLElement)) {\n return\n }\n\n this.updateAttributes($item, $items.length)\n this.resetItem($item)\n\n const $firstItem = $items[0]\n if (!this.hasRemoveButton($firstItem)) {\n this.createRemoveButton($firstItem)\n }\n\n $items[$items.length - 1].after($item)\n\n const $input = $item.querySelector('input, textarea, select')\n if ($input && $input instanceof HTMLInputElement) {\n $input.focus()\n }\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n */\n hasRemoveButton($item) {\n return $item.querySelectorAll('.moj-add-another__remove-button').length\n }\n\n getItems() {\n if (!this.$root) {\n return []\n }\n\n const $items = Array.from(\n this.$root.querySelectorAll('.moj-add-another__item')\n )\n\n return $items.filter((item) => item instanceof HTMLElement)\n }\n\n getNewItem() {\n const $items = this.getItems()\n const $item = $items[0].cloneNode(true)\n\n if (!$item || !($item instanceof HTMLElement)) {\n return\n }\n\n if (!this.hasRemoveButton($item)) {\n this.createRemoveButton($item)\n }\n\n return $item\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n * @param {number} index - Add another item index\n */\n updateAttributes($item, index) {\n $item.querySelectorAll('[data-name]').forEach(($input) => {\n if (!($input instanceof HTMLInputElement)) {\n return\n }\n\n const name = $input.getAttribute('data-name') || ''\n const id = $input.getAttribute('data-id') || ''\n const originalId = $input.id\n\n $input.name = name.replace(/%index%/, `${index}`)\n $input.id = id.replace(/%index%/, `${index}`)\n\n const $label =\n $input.parentElement.querySelector('label') ||\n $input.closest('label') ||\n $item.querySelector(`[for=\"${originalId}\"]`)\n\n if ($label && $label instanceof HTMLLabelElement) {\n $label.htmlFor = $input.id\n }\n })\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n */\n createRemoveButton($item) {\n const $button = document.createElement('button')\n $button.type = 'button'\n\n $button.classList.add(\n 'govuk-button',\n 'govuk-button--secondary',\n 'moj-add-another__remove-button'\n )\n\n $button.textContent = 'Remove'\n\n $item.append($button)\n }\n\n /**\n * @param {HTMLElement} $item - Add another item\n */\n resetItem($item) {\n $item.querySelectorAll('[data-name], [data-id]').forEach(($input) => {\n if (!($input instanceof HTMLInputElement)) {\n return\n }\n\n if ($input.type === 'checkbox' || $input.type === 'radio') {\n $input.checked = false\n } else {\n $input.value = ''\n }\n })\n }\n\n /**\n * @param {MouseEvent} event - Click event\n */\n onRemoveButtonClick(event) {\n const $button = event.target\n\n if (\n !$button ||\n !($button instanceof HTMLButtonElement) ||\n !$button.classList.contains('moj-add-another__remove-button')\n ) {\n return\n }\n\n $button.closest('.moj-add-another__item').remove()\n\n const $items = this.getItems()\n\n if ($items.length === 1) {\n $items[0].querySelector('.moj-add-another__remove-button').remove()\n }\n\n $items.forEach(($item, index) => {\n this.updateAttributes($item, index)\n })\n\n this.focusHeading()\n }\n\n focusHeading() {\n const $heading = this.$root.querySelector('.moj-add-another__heading')\n\n if ($heading && $heading instanceof HTMLElement) {\n $heading.focus()\n }\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'moj-add-another'\n}\n"],"names":["AddAnother","Component","constructor","$root","addEventListener","onRemoveButtonClick","bind","onAddButtonClick","$buttons","querySelectorAll","forEach","$button","HTMLButtonElement","type","event","target","classList","contains","$items","getItems","$item","getNewItem","HTMLElement","updateAttributes","length","resetItem","$firstItem","hasRemoveButton","createRemoveButton","after","$input","querySelector","HTMLInputElement","focus","Array","from","filter","item","cloneNode","index","name","getAttribute","id","originalId","replace","$label","parentElement","closest","HTMLLabelElement","htmlFor","document","createElement","add","textContent","append","checked","value","remove","focusHeading","$heading","moduleName"],"mappings":";;AAEO,MAAMA,UAAU,SAASC,SAAS,CAAC;AACxC;AACF;AACA;EACEC,WAAWA,CAACC,KAAK,EAAE;IACjB,KAAK,CAACA,KAAK,CAAC;AAEZ,IAAA,IAAI,CAACA,KAAK,CAACC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAACC,mBAAmB,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzE,IAAA,IAAI,CAACH,KAAK,CAACC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAACG,gBAAgB,CAACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEtE,MAAME,QAAQ,GAAG,IAAI,CAACL,KAAK,CAACM,gBAAg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k-colour("white");
13
13
  -ms-grid-columns: min-content fit-content(960px);
14
+ grid-template-columns: -webkit-min-content fit-content(960px);
14
15
  grid-template-columns: min-content fit-content(960px);
15
16
  gap: govuk-spacing(2);
16
17
  @include govuk-font($size: false);
@@ -22,6 +23,7 @@
22
23
 
23
24
  .moj-alert[data-dismissible] {
24
25
  @include govuk-media-query($from: tablet) {
26
+ grid-template-columns: -webkit-min-content fit-content(920px) auto;
25
27
  grid-template-columns: min-content fit-content(920px) auto;
26
28
  }
27
29
  }
@@ -143,3 +145,5 @@
143
145
  @include govuk-link-style-error;
144
146
  }
145
147
  }
148
+
149
+ /*# sourceMappingURL=_alert.scss.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/moj/components/alert/_alert.scss"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,yCAAyC;AACzC,kCAAkC;AAClC,uCAAuC;;AAEvC;EACE,iBAAiB;EACjB,aAAa;EACb,+BAA+B;EAC/B,yBAAyB;EACzB,6BAA6B;EAC7B,iCAAiC;EACjC,gDAAgD;EAChD,6DAAqD;EAArD,qDAAqD;EACrD,qBAAqB;EACrB,iCAAiC;;EAEjC;IACE,qDAAqD;EACvD;AACF;;AAEA;EACE;IACE,kEAA0D;IAA1D,0DAA0D;EAC5D;AACF;;AAEA;EACE,cAAc;EACd,4BAA4B;EAC5B,6BAA6B;EAC7B,kBAAkB;AACpB;;AAEA;EACE,cAAc;EACd,iCAAiC;EACjC,iCAAiC;EACjC,gBAAgB;EAChB,4BAA4B;EAC5B,mCAAmC;;EAEnC;IACE,iCAAiC;EACnC;AACF;;AAEA;EACE,oBAAoB;EACpB,mBAAmB;;EAEnB;IACE,oBAAoB;IACpB,mBAAmB;EACrB;AACF;;AAEA;EACE,8BAA8B;EAC9B,gBAAgB;EAChB,UAAU;EACV,YAAY;EACZ,YAAY;EACZ,6BAA6B;EAC7B,wBAAwB;EACxB,eAAe;EACf,gBAAgB;EAChB,mCAAmC;EACnC,0BAA0B;EAC1B,iCAAiC;EACjC,kCAAkC;AACpC;;AAEA;EACE,cAAc;EACd,aAAa;EACb,mCAAmC;EACnC,0BAA0B;EAC1B,mCAAmC;EACnC,qCAAqC;;EAErC;IACE,mCAAmC;EACrC;AACF;;AAEA;;;EAGE,gBAAgB;AAClB;;AAEA;+EAC+E;AAC/E;EACE,iCAAiC;EACjC,0BAA0B;;EAE1B;;IAEE,0BAA0B;IAC1B,iCAAiC;EACnC;AACF;;AAEA;EACE,mCAAmC;EACnC,4BAA4B;;EAE5B;;;IAGE,0BAA0B;IAC1B,iCAAiC;EACnC;AACF;;AAEA;EACE,iCAAiC;EACjC,0BAA0B;;EAE1B;IACE,+BAA+B;EACjC;;EAEA;;;IAGE,0BAA0B;IAC1B,+BAA+B;EACjC;AACF;;AAEA;EACE,iCAAiC;EACjC,0BAA0B;;EAE1B;;;IAGE,0BAA0B;IAC1B,+BAA+B;EACjC;AACF","file":"_alert.scss","sourcesContent":["@use \"../../helpers/links\" as *;\n@use \"../../objects/width-container\" as *;\n@use \"../../settings/colours\" as *;\n@use \"../../vendor/govuk-frontend\" as *;\n\n.moj-alert {\n display: -ms-grid;\n display: grid;\n margin-bottom: govuk-spacing(6);\n padding: govuk-spacing(2);\n border: 5px solid transparent;\n background: govuk-colour(\"white\");\n -ms-grid-columns: min-content fit-content(960px);\n grid-template-columns: min-content fit-content(960px);\n gap: govuk-spacing(2);\n @include govuk-font($size: false);\n\n &:focus {\n outline: $govuk-focus-width solid $govuk-focus-colour;\n }\n}\n\n.moj-alert[data-dismissible] {\n @include govuk-media-query($from: tablet) {\n grid-template-columns: min-content fit-content(920px) auto;\n }\n}\n\n.moj-alert__icon {\n display: block;\n width: govuk-px-to-rem(30px);\n height: govuk-px-to-rem(30px);\n fill: currentcolor;\n}\n\n.moj-alert__content {\n display: block;\n // Padding to align text with icon\n padding-top: govuk-px-to-rem(5px);\n overflow: hidden;\n color: govuk-colour(\"black\");\n @include govuk-font-size($size: 19);\n\n @include govuk-media-query($from: tablet) {\n padding-top: govuk-px-to-rem(2px);\n }\n}\n\n.moj-alert__action {\n grid-column-start: 2;\n grid-column-end: -1;\n\n @include govuk-media-query($from: tablet) {\n grid-column-start: 3;\n justify-self: right;\n }\n}\n\n.moj-alert__dismiss {\n // Give the button link styling\n margin-bottom: 0;\n padding: 0;\n border: none;\n color: unset;\n background-color: transparent;\n -webkit-appearance: none;\n cursor: pointer;\n appearance: none;\n @include govuk-font-size($size: 19);\n @include govuk-link-common;\n @include govuk-link-style-default;\n @include govuk-link-print-friendly;\n}\n\n.moj-alert__heading {\n display: block;\n margin-top: 0;\n margin-bottom: govuk-px-to-rem(5px);\n @include govuk-text-colour;\n @include govuk-font-size($size: 24);\n @include govuk-typography-weight-bold;\n\n @include govuk-media-query($from: tablet) {\n margin-bottom: govuk-px-to-rem(3px);\n }\n}\n\n.moj-alert__content p:last-child,\n.moj-alert__content a:last-child,\n.moj-alert__content ul:last-child {\n margin-bottom: 0;\n}\n\n/* Style variants\n ========================================================================== */\n.moj-alert--information {\n border-color: $govuk-brand-colour;\n color: $govuk-brand-colour;\n\n .moj-alert__dismiss,\n .moj-alert__content a {\n @include govuk-link-common;\n @include govuk-link-style-default;\n }\n}\n\n.moj-alert--success {\n border-color: govuk-colour(\"green\");\n color: govuk-colour(\"green\");\n\n .moj-alert__dismiss,\n .moj-alert__content a,\n .moj-alert__content .govuk-link {\n @include govuk-link-common;\n @include govuk-link-style-success;\n }\n}\n\n.moj-alert--warning {\n border-color: $moj-warning-colour;\n color: $moj-warning-colour;\n\n .moj-alert__dismiss {\n color: $moj-warning-link-colour;\n }\n\n .moj-alert__dismiss,\n .moj-alert__content a,\n .moj-alert__content .govuk-link {\n @include govuk-link-common;\n @include moj-link-style-warning;\n }\n}\n\n.moj-alert--error {\n border-color: govuk-colour(\"red\");\n color: govuk-colour(\"red\");\n\n .moj-alert__dismiss,\n .moj-alert__content a,\n .moj-alert__content .govuk-link {\n @include govuk-link-common;\n @include govuk-link-style-error;\n }\n}\n"]}