@nationalarchives/frontend 1.5.0 → 1.6.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 (42) hide show
  1. package/nationalarchives/all+analytics.js +1 -1
  2. package/nationalarchives/all+analytics.js.map +1 -1
  3. package/nationalarchives/all.css +1 -1
  4. package/nationalarchives/all.css.map +1 -1
  5. package/nationalarchives/all.js +1 -1
  6. package/nationalarchives/all.js.map +1 -1
  7. package/nationalarchives/all.mjs +11 -1
  8. package/nationalarchives/assets/images/favicon.ico +0 -0
  9. package/nationalarchives/assets/images/favicon.svg +7 -0
  10. package/nationalarchives/assets/images/mstile-150x150.png +0 -0
  11. package/nationalarchives/assets/images/nationalarchives-opengraph-image.png +0 -0
  12. package/nationalarchives/components/TextAreaCharacterCount/TextAreaCharacterCount.js +2 -0
  13. package/nationalarchives/components/TextAreaCharacterCount/TextAreaCharacterCount.js.map +1 -0
  14. package/nationalarchives/components/TextAreaItemisedRows/TextAreaItemisedRows.js +2 -0
  15. package/nationalarchives/components/TextAreaItemisedRows/TextAreaItemisedRows.js.map +1 -0
  16. package/nationalarchives/components/button/fixtures.json +1 -1
  17. package/nationalarchives/components/button/template.njk +1 -1
  18. package/nationalarchives/components/card/fixtures.json +1 -1
  19. package/nationalarchives/components/card/template.njk +1 -1
  20. package/nationalarchives/components/code-block/fixtures.json +1 -1
  21. package/nationalarchives/components/date-input/macro-options.json +2 -1
  22. package/nationalarchives/components/footer/fixtures.json +1 -1
  23. package/nationalarchives/components/hero/fixtures.json +1 -1
  24. package/nationalarchives/components/pagination/fixtures.json +4 -4
  25. package/nationalarchives/components/textarea/TextAreaCharacterCount.mjs +160 -0
  26. package/nationalarchives/components/textarea/TextAreaItemisedRows.mjs +202 -0
  27. package/nationalarchives/components/textarea/fixtures.json +43 -2
  28. package/nationalarchives/components/textarea/macro-options.json +36 -1
  29. package/nationalarchives/components/textarea/template.njk +15 -2
  30. package/nationalarchives/components/textarea/textarea.css +1 -1
  31. package/nationalarchives/components/textarea/textarea.css.map +1 -1
  32. package/nationalarchives/components/textarea/textarea.js +1 -1
  33. package/nationalarchives/components/textarea/textarea.js.map +1 -1
  34. package/nationalarchives/components/textarea/textarea.mjs +3 -197
  35. package/nationalarchives/components/textarea/textarea.scss +12 -1
  36. package/nationalarchives/prototype-kit.css +1 -1
  37. package/nationalarchives/prototype-kit.css.map +1 -1
  38. package/nationalarchives/templates/fixtures.json +3 -3
  39. package/nationalarchives/templates/layouts/_generic.njk +2 -14
  40. package/nationalarchives/templates/macros/title.njk +63 -0
  41. package/package.json +4 -4
  42. package/nationalarchives/assets/images/nationalarchives-opengraph-image-dark.png +0 -0
@@ -1,198 +1,4 @@
1
- export class TextAreaItemisedRows {
2
- constructor($module, options = {}) {
3
- this.$module = $module;
4
- this.$formFieldInput =
5
- this.$module && this.$module.querySelector(".tna-textarea");
6
- this.$formFieldInputHint =
7
- this.$module && this.$module.querySelector(".tna-form-item__hint");
8
- this.$formFieldBody =
9
- this.$module && this.$module.querySelector(".tna-form-item__body");
1
+ import TextAreaCharacterCount from "./TextAreaCharacterCount.mjs";
2
+ import TextAreaItemisedRows from "./TextAreaItemisedRows.mjs";
10
3
 
11
- if (
12
- !this.$module ||
13
- !this.$formFieldInput ||
14
- !this.$formFieldBody ||
15
- this.$formFieldInput.getAttribute("hidden") !== null
16
- ) {
17
- return;
18
- }
19
-
20
- const { enhancedHint } = options;
21
- this.enhancedHint = enhancedHint || "Enter an item and press enter";
22
-
23
- this.init();
24
- }
25
-
26
- init() {
27
- this.values = this.$formFieldInput.value
28
- .split("\n")
29
- .map((value) => value.trim())
30
- .filter((value) => value);
31
-
32
- this.id = this.$formFieldInput.id;
33
-
34
- this.$formFieldNewInput = document.createElement("input");
35
- this.$formFieldNewInput.classList.add("tna-text-input");
36
- ["id", "aria-describedby"].forEach((attribute) => {
37
- this.$formFieldNewInput.setAttribute(
38
- attribute,
39
- this.$formFieldInput.getAttribute(attribute),
40
- );
41
- this.$formFieldInput.removeAttribute(attribute);
42
- });
43
- this.$formFieldBody.appendChild(this.$formFieldNewInput);
44
- this.$formFieldInput.setAttribute("hidden", "");
45
- this.$formFieldInput.addEventListener("keyup", () => this.updateList());
46
- this.$formFieldNewInput.addEventListener("keypress", (event) => {
47
- if (event.key === "Enter") {
48
- this.appendValue(event.target.value);
49
- }
50
- });
51
-
52
- this.$formFieldNewInputAddButton = document.createElement("button");
53
- this.$formFieldNewInputAddButton.setAttribute("type", "button");
54
- this.$formFieldNewInputAddButton.classList.add(
55
- "tna-button",
56
- "tna-button--small",
57
- );
58
- this.$formFieldNewInputAddButtonInner = document.createElement("span");
59
- this.$formFieldNewInputAddButtonInner.innerText = "Add";
60
- this.$formFieldNewInputAddButtonInnerExtra = document.createElement("span");
61
- this.$formFieldNewInputAddButtonInnerExtra.classList.add(
62
- "tna-visually-hidden",
63
- );
64
- this.$formFieldNewInputAddButtonInnerExtra.innerText = " to list";
65
- this.$formFieldNewInputAddButtonInner.appendChild(
66
- this.$formFieldNewInputAddButtonInnerExtra,
67
- );
68
- this.$formFieldNewInputAddButton.appendChild(
69
- this.$formFieldNewInputAddButtonInner,
70
- );
71
- this.$formFieldBody.appendChild(this.$formFieldNewInputAddButton);
72
- this.$formFieldNewInputAddButton.addEventListener("click", () => {
73
- this.appendValue(this.$formFieldNewInput.value);
74
- });
75
-
76
- this.$formFieldLiveAria = document.createElement("div");
77
- this.$formFieldLiveAria.setAttribute("aria-live", "assertive");
78
- this.$formFieldLiveAria.classList.add("tna-visually-hidden");
79
- this.$module.appendChild(this.$formFieldLiveAria);
80
-
81
- this.$formFieldCounter = document.createElement("p");
82
- this.$formFieldCounter.id = `${this.id}-list-helper`;
83
- this.$formFieldCounter.classList.add("tna-!--margin-top-xs");
84
- this.$module.appendChild(this.$formFieldCounter);
85
-
86
- this.$formFieldNewInput.setAttribute(
87
- "aria-describedby",
88
- `${this.$formFieldNewInput.getAttribute("aria-describedby")} ${
89
- this.$formFieldCounter.id
90
- }`,
91
- );
92
-
93
- this.$valuesList = document.createElement("ul");
94
- this.$valuesList.classList.add(
95
- "tna-compound-filters",
96
- "tna-!--margin-top-xs",
97
- );
98
- this.$valuesList.addEventListener("blur", () => {
99
- this.$valuesList.removeAttribute("tabindex");
100
- this.updateAriaText("");
101
- });
102
- this.$module.appendChild(this.$valuesList);
103
-
104
- if (!this.$formFieldInputHint) {
105
- this.$formFieldInputHint = document.createElement("p");
106
- this.$formFieldInputHint.classList.add("tna-form-item__hint");
107
- this.$formFieldBody.parentNode.insertBefore(
108
- this.$formFieldInputHint,
109
- this.$formFieldBody,
110
- );
111
- }
112
- this.$formFieldInputHint.innerText = this.enhancedHint;
113
-
114
- this.updateList();
115
- }
116
-
117
- updateAriaText(content) {
118
- this.$formFieldLiveAria.innerText = content;
119
- }
120
-
121
- /* eslint-disable-next-line class-methods-use-this */
122
- normaliseValue(value) {
123
- return value.replace(/\s{2,}/u, " ").trim();
124
- }
125
-
126
- isValueInList(value) {
127
- return this.values
128
- .map((eachValue) => this.normaliseValue(eachValue).toLowerCase())
129
- .includes(value.toLowerCase().trim());
130
- }
131
-
132
- appendValue(value) {
133
- const newValue = this.normaliseValue(value);
134
- if (newValue) {
135
- if (this.isValueInList(newValue)) {
136
- this.updateAriaText(`'${newValue}' already added`);
137
- } else {
138
- this.values.push(newValue);
139
- this.$formFieldInput.value = this.values.join("\n");
140
- this.updateList();
141
- this.updateAriaText(`'${newValue}' added`);
142
- }
143
- } else {
144
- this.updateAriaText("Enter an item to add");
145
- }
146
- this.$formFieldNewInput.value = "";
147
- this.$formFieldNewInput.focus();
148
- }
149
-
150
- removeValue(value) {
151
- const removeValue = this.normaliseValue(value);
152
- if (removeValue && this.isValueInList(removeValue)) {
153
- this.values = this.values.filter(
154
- (existingValue) => existingValue !== removeValue,
155
- );
156
- this.$formFieldInput.value = this.values.join("\n");
157
- this.updateList();
158
- this.updateAriaText(`'${removeValue}' removed`);
159
- }
160
- if (this.values.length) {
161
- this.$valuesList.setAttribute("tabindex", "0");
162
- this.$valuesList.focus();
163
- } else {
164
- this.$formFieldNewInput.focus();
165
- }
166
- }
167
-
168
- updateList() {
169
- this.$valuesList.innerHTML = "";
170
- this.values
171
- .map((value) => {
172
- const $item = document.createElement("li");
173
- $item.classList.add("tna-compound-filters__item");
174
- const $itemLabel = document.createElement("span");
175
- $itemLabel.innerText = value;
176
- $item.appendChild($itemLabel);
177
-
178
- const $removeItemButton = document.createElement("button");
179
- $removeItemButton.innerText = `Remove '${value}'`;
180
- $removeItemButton.setAttribute("type", "button");
181
- $removeItemButton.classList.add("tna-compound-filters__link");
182
- $removeItemButton.addEventListener("click", () => {
183
- this.removeValue(value);
184
- });
185
- $item.appendChild($removeItemButton);
186
- return $item;
187
- })
188
- .forEach(($item) => this.$valuesList.appendChild($item));
189
-
190
- let innerTextItemValue = "item";
191
- /* eslint-disable-next-line no-magic-numbers */
192
- if (this.values.length !== 1) {
193
- innerTextItemValue += "s";
194
- }
195
- const innerTextValue = `${this.values.length} ${innerTextItemValue} added`;
196
- this.$formFieldCounter.innerText = innerTextValue;
197
- }
198
- }
4
+ export { TextAreaItemisedRows, TextAreaCharacterCount };
@@ -2,6 +2,7 @@
2
2
  @use "../../tools/borders";
3
3
  @use "../../tools/colour";
4
4
  @use "../../tools/spacing";
5
+ @use "../../tools/typography";
5
6
 
6
7
  $textarea-minimum-lines-visible: 5 !default;
7
8
  $textarea-line-height: 1.5rem !default;
@@ -26,7 +27,8 @@ $textarea-vertical-padding: 0.25 !default;
26
27
 
27
28
  @include borders.rounded-border;
28
29
 
29
- .tna-form-item--error & {
30
+ .tna-form-item--error &,
31
+ &--error {
30
32
  @include colour.colour-border("form-error-border");
31
33
  }
32
34
 
@@ -58,3 +60,12 @@ $textarea-vertical-padding: 0.25 !default;
58
60
  }
59
61
  }
60
62
  }
63
+
64
+ .tna-textarea-count {
65
+ margin-top: spacing.space(0.5);
66
+
67
+ &--error {
68
+ @include colour.colour-font("form-error-text");
69
+ @include typography.main-font-weight-bold;
70
+ }
71
+ }