govuk_tech_docs 6.5.2.1 → 6.6.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/publish-gem.yaml +1 -1
- data/lib/govuk_tech_docs/version.rb +1 -1
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.js +202 -137
- data/node_modules/govuk-frontend/dist/govuk/all.bundle.mjs +202 -137
- data/node_modules/govuk-frontend/dist/govuk/common/configuration.mjs +5 -1
- data/node_modules/govuk-frontend/dist/govuk/common/create-element.mjs +13 -0
- data/node_modules/govuk-frontend/dist/govuk/common/govuk-frontend-version.mjs +1 -1
- data/node_modules/govuk-frontend/dist/govuk/component.mjs +2 -1
- data/node_modules/govuk-frontend/dist/govuk/components/_index.import.scss +2 -0
- data/node_modules/govuk-frontend/dist/govuk/components/_index.scss +2 -0
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js +87 -62
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs +87 -62
- data/node_modules/govuk-frontend/dist/govuk/components/accordion/accordion.mjs +60 -56
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.js +17 -6
- data/node_modules/govuk-frontend/dist/govuk/components/button/button.bundle.mjs +17 -6
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js +90 -32
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs +90 -32
- data/node_modules/govuk-frontend/dist/govuk/components/character-count/character-count.mjs +64 -27
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/cookie-banner/_mixin.scss +6 -0
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js +17 -6
- data/node_modules/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs +17 -6
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js +43 -18
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs +43 -18
- data/node_modules/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.mjs +16 -12
- data/node_modules/govuk-frontend/dist/govuk/components/feedback/_feedback.import.scss +6 -0
- data/node_modules/govuk-frontend/dist/govuk/components/feedback/_index.import.scss +8 -0
- data/node_modules/govuk-frontend/dist/govuk/components/feedback/_index.scss +5 -0
- data/node_modules/govuk-frontend/dist/govuk/components/feedback/_mixin.scss +48 -0
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js +54 -30
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs +54 -30
- data/node_modules/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs +27 -24
- data/node_modules/govuk-frontend/dist/govuk/components/footer/_mixin.scss +6 -0
- data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_index.import.scss +8 -0
- data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_index.scss +6 -0
- data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_language-navigation.import.scss +6 -0
- data/node_modules/govuk-frontend/dist/govuk/components/language-navigation/_mixin.scss +68 -0
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js +17 -6
- data/node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs +17 -6
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js +32 -9
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs +32 -9
- data/node_modules/govuk-frontend/dist/govuk/components/password-input/password-input.mjs +5 -3
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.js +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/_mixin.scss +48 -3
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js +14 -6
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs +14 -6
- data/node_modules/govuk-frontend/dist/govuk/components/skip-link/skip-link.mjs +2 -1
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js +12 -5
- data/node_modules/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs +12 -5
- data/node_modules/govuk-frontend/dist/govuk/custom-properties/_frontend-version.mixin.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/custom-properties/_functional-colours.mixin.scss +1 -0
- data/node_modules/govuk-frontend/dist/govuk/errors/index.mjs +8 -5
- data/node_modules/govuk-frontend/dist/govuk/govuk-frontend.min.js +1 -1
- data/node_modules/govuk-frontend/dist/govuk/helpers/_colour.scss +1 -1
- data/node_modules/govuk-frontend/dist/govuk/init.mjs +8 -8
- data/node_modules/govuk-frontend/dist/govuk/settings/_colours-organisations.scss +16 -2
- data/package-lock.json +4 -4
- data/package.json +1 -1
- metadata +10 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isInitialised, isSupported } from './common/index.mjs';
|
|
2
2
|
import { InitError, ElementError, SupportError } from './errors/index.mjs';
|
|
3
3
|
|
|
4
|
+
const _self = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
4
5
|
class Component {
|
|
5
6
|
/**
|
|
6
7
|
* Returns the root element of the component
|
|
@@ -54,7 +55,7 @@ class Component {
|
|
|
54
55
|
/**
|
|
55
56
|
* @typedef {typeof Component & ChildClass} ChildClassConstructor
|
|
56
57
|
*/
|
|
57
|
-
Component.elementType = HTMLElement;
|
|
58
|
+
Component.elementType = _self.HTMLElement;
|
|
58
59
|
|
|
59
60
|
export { Component };
|
|
60
61
|
//# sourceMappingURL=component.mjs.map
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@import "error-message";
|
|
11
11
|
@import "error-summary";
|
|
12
12
|
@import "exit-this-page";
|
|
13
|
+
@import "feedback";
|
|
13
14
|
@import "fieldset";
|
|
14
15
|
@import "file-upload";
|
|
15
16
|
@import "footer";
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
@import "input";
|
|
20
21
|
@import "inset-text";
|
|
21
22
|
@import "label";
|
|
23
|
+
@import "language-navigation";
|
|
22
24
|
@import "notification-banner";
|
|
23
25
|
@import "pagination";
|
|
24
26
|
@import "panel";
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@use "error-message";
|
|
11
11
|
@use "error-summary";
|
|
12
12
|
@use "exit-this-page";
|
|
13
|
+
@use "feedback";
|
|
13
14
|
@use "fieldset";
|
|
14
15
|
@use "file-upload";
|
|
15
16
|
@use "footer";
|
|
@@ -19,6 +20,7 @@
|
|
|
19
20
|
@use "input";
|
|
20
21
|
@use "inset-text";
|
|
21
22
|
@use "label";
|
|
23
|
+
@use "language-navigation";
|
|
22
24
|
@use "notification-banner";
|
|
23
25
|
@use "pagination";
|
|
24
26
|
@use "panel";
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
function isObject(option) {
|
|
30
30
|
return !!option && typeof option === 'object' && !isArray(option);
|
|
31
31
|
}
|
|
32
|
+
function isScope($scope) {
|
|
33
|
+
return !!$scope && ($scope instanceof Element || $scope instanceof Document);
|
|
34
|
+
}
|
|
32
35
|
function formatErrorMessage(Component, message) {
|
|
33
36
|
return `${Component.moduleName}: ${message}`;
|
|
34
37
|
}
|
|
@@ -47,11 +50,14 @@
|
|
|
47
50
|
/**
|
|
48
51
|
* Checks if GOV.UK Frontend is supported on this page
|
|
49
52
|
*
|
|
50
|
-
* @param {
|
|
53
|
+
* @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message
|
|
51
54
|
*/
|
|
52
|
-
constructor(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
constructor(scopeOrMessage = document.body) {
|
|
56
|
+
let 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';
|
|
57
|
+
if (!isScope(scopeOrMessage)) {
|
|
58
|
+
supportMessage = 'GOV.UK Frontend initialised without `<script type="module">`';
|
|
59
|
+
}
|
|
60
|
+
super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage);
|
|
55
61
|
this.name = 'SupportError';
|
|
56
62
|
}
|
|
57
63
|
}
|
|
@@ -92,6 +98,7 @@
|
|
|
92
98
|
* @import { ComponentWithModuleName } from '../common/index.mjs'
|
|
93
99
|
*/
|
|
94
100
|
|
|
101
|
+
const _self = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
95
102
|
class Component {
|
|
96
103
|
/**
|
|
97
104
|
* Returns the root element of the component
|
|
@@ -145,7 +152,7 @@
|
|
|
145
152
|
/**
|
|
146
153
|
* @typedef {typeof Component & ChildClass} ChildClassConstructor
|
|
147
154
|
*/
|
|
148
|
-
Component.elementType = HTMLElement;
|
|
155
|
+
Component.elementType = _self.HTMLElement;
|
|
149
156
|
|
|
150
157
|
const configOverride = Symbol.for('configOverride');
|
|
151
158
|
class ConfigurableComponent extends Component {
|
|
@@ -170,10 +177,14 @@
|
|
|
170
177
|
throw new ConfigError(formatErrorMessage(childConstructor, 'Config passed as parameter into constructor but no defaults defined'));
|
|
171
178
|
}
|
|
172
179
|
const datasetConfig = normaliseDataset(childConstructor, this._$root.dataset);
|
|
173
|
-
this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {}
|
|
180
|
+
this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {});
|
|
181
|
+
this._config = mergeConfigs(this._config, this[configOverride](datasetConfig), datasetConfig);
|
|
174
182
|
}
|
|
175
183
|
}
|
|
176
184
|
function normaliseString(value, property) {
|
|
185
|
+
if (property != null && property.type && !['string', 'number', 'boolean'].includes(property.type)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
177
188
|
const trimmedValue = value ? value.trim() : '';
|
|
178
189
|
let output;
|
|
179
190
|
let outputType = property == null ? void 0 : property.type;
|
|
@@ -293,6 +304,17 @@
|
|
|
293
304
|
* @import { CompatibleClass, Config, CreateAllOptions, OnErrorCallback } from '../init.mjs'
|
|
294
305
|
*/
|
|
295
306
|
|
|
307
|
+
function createElement(tagName, attributes = {}, children = []) {
|
|
308
|
+
const $element = document.createElement(tagName);
|
|
309
|
+
Object.entries(attributes).forEach(([name, value]) => {
|
|
310
|
+
$element.setAttribute(name, value);
|
|
311
|
+
});
|
|
312
|
+
for (const child of children) {
|
|
313
|
+
$element.append(child);
|
|
314
|
+
}
|
|
315
|
+
return $element;
|
|
316
|
+
}
|
|
317
|
+
|
|
296
318
|
class I18n {
|
|
297
319
|
constructor(translations = {}, config = {}) {
|
|
298
320
|
var _config$locale;
|
|
@@ -384,24 +406,16 @@
|
|
|
384
406
|
constructor($root, config = {}) {
|
|
385
407
|
super($root, config);
|
|
386
408
|
this.i18n = void 0;
|
|
387
|
-
this.controlsClass = 'govuk-accordion__controls';
|
|
388
|
-
this.showAllClass = 'govuk-accordion__show-all';
|
|
389
|
-
this.showAllTextClass = 'govuk-accordion__show-all-text';
|
|
390
409
|
this.sectionClass = 'govuk-accordion__section';
|
|
391
|
-
this.
|
|
410
|
+
this.sectionExpandedModifier = 'govuk-accordion__section--expanded';
|
|
392
411
|
this.sectionButtonClass = 'govuk-accordion__section-button';
|
|
393
412
|
this.sectionHeaderClass = 'govuk-accordion__section-header';
|
|
394
413
|
this.sectionHeadingClass = 'govuk-accordion__section-heading';
|
|
395
|
-
this.sectionHeadingDividerClass = 'govuk-accordion__section-heading-divider';
|
|
396
414
|
this.sectionHeadingTextClass = 'govuk-accordion__section-heading-text';
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
399
|
-
this.
|
|
400
|
-
this.sectionShowHideTextClass = 'govuk-accordion__section-toggle-text';
|
|
401
|
-
this.upChevronIconClass = 'govuk-accordion-nav__chevron';
|
|
402
|
-
this.downChevronIconClass = 'govuk-accordion-nav__chevron--down';
|
|
415
|
+
this.sectionToggleTextClass = 'govuk-accordion__section-toggle-text';
|
|
416
|
+
this.iconClass = 'govuk-accordion-nav__chevron';
|
|
417
|
+
this.iconOpenModifier = 'govuk-accordion-nav__chevron--down';
|
|
403
418
|
this.sectionSummaryClass = 'govuk-accordion__section-summary';
|
|
404
|
-
this.sectionSummaryFocusClass = 'govuk-accordion__section-summary-focus';
|
|
405
419
|
this.sectionContentClass = 'govuk-accordion__section-content';
|
|
406
420
|
this.$sections = void 0;
|
|
407
421
|
this.$showAllButton = null;
|
|
@@ -421,19 +435,23 @@
|
|
|
421
435
|
this.updateShowAllButton(this.areAllSectionsOpen());
|
|
422
436
|
}
|
|
423
437
|
initControls() {
|
|
424
|
-
this.$showAllButton =
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
this.$showAllIcon
|
|
438
|
+
this.$showAllButton = createElement('button', {
|
|
439
|
+
type: 'button',
|
|
440
|
+
class: 'govuk-accordion__show-all',
|
|
441
|
+
'aria-expanded': 'false'
|
|
442
|
+
});
|
|
443
|
+
this.$showAllIcon = createElement('span', {
|
|
444
|
+
class: this.iconClass
|
|
445
|
+
});
|
|
430
446
|
this.$showAllButton.appendChild(this.$showAllIcon);
|
|
431
|
-
const $accordionControls =
|
|
432
|
-
|
|
447
|
+
const $accordionControls = createElement('div', {
|
|
448
|
+
class: 'govuk-accordion__controls'
|
|
449
|
+
});
|
|
433
450
|
$accordionControls.appendChild(this.$showAllButton);
|
|
434
451
|
this.$root.insertBefore($accordionControls, this.$root.firstChild);
|
|
435
|
-
this.$showAllText =
|
|
436
|
-
|
|
452
|
+
this.$showAllText = createElement('span', {
|
|
453
|
+
class: 'govuk-accordion__show-all-text'
|
|
454
|
+
});
|
|
437
455
|
this.$showAllButton.appendChild(this.$showAllText);
|
|
438
456
|
this.$showAllButton.addEventListener('click', () => this.onShowOrHideAllToggle());
|
|
439
457
|
if ('onbeforematch' in document) {
|
|
@@ -471,39 +489,45 @@
|
|
|
471
489
|
identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)`
|
|
472
490
|
});
|
|
473
491
|
}
|
|
474
|
-
const $button =
|
|
475
|
-
|
|
476
|
-
|
|
492
|
+
const $button = createElement('button', {
|
|
493
|
+
type: 'button',
|
|
494
|
+
'aria-controls': `${this.$root.id}-content-${index + 1}`
|
|
495
|
+
});
|
|
477
496
|
for (const attr of Array.from($span.attributes)) {
|
|
478
497
|
if (attr.name !== 'id') {
|
|
479
498
|
$button.setAttribute(attr.name, attr.value);
|
|
480
499
|
}
|
|
481
500
|
}
|
|
482
|
-
const $headingText =
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
$headingTextFocus
|
|
501
|
+
const $headingText = createElement('span', {
|
|
502
|
+
class: this.sectionHeadingTextClass,
|
|
503
|
+
id: $span.id
|
|
504
|
+
});
|
|
505
|
+
const $headingTextFocus = createElement('span', {
|
|
506
|
+
class: 'govuk-accordion__section-heading-text-focus'
|
|
507
|
+
});
|
|
487
508
|
$headingText.appendChild($headingTextFocus);
|
|
488
509
|
Array.from($span.childNodes).forEach($child => $headingTextFocus.appendChild($child));
|
|
489
|
-
const $showHideToggle =
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
$showHideToggleFocus
|
|
510
|
+
const $showHideToggle = createElement('span', {
|
|
511
|
+
class: 'govuk-accordion__section-toggle',
|
|
512
|
+
'data-nosnippet': ''
|
|
513
|
+
});
|
|
514
|
+
const $showHideToggleFocus = createElement('span', {
|
|
515
|
+
class: 'govuk-accordion__section-toggle-focus'
|
|
516
|
+
});
|
|
494
517
|
$showHideToggle.appendChild($showHideToggleFocus);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
$showHideToggleFocus.appendChild(
|
|
499
|
-
|
|
500
|
-
|
|
518
|
+
$showHideToggleFocus.appendChild(createElement('span', {
|
|
519
|
+
class: this.iconClass
|
|
520
|
+
}));
|
|
521
|
+
$showHideToggleFocus.appendChild(createElement('span', {
|
|
522
|
+
class: this.sectionToggleTextClass
|
|
523
|
+
}));
|
|
501
524
|
$button.appendChild($headingText);
|
|
502
525
|
$button.appendChild(this.getButtonPunctuationEl());
|
|
503
526
|
if ($summary) {
|
|
504
|
-
const $summarySpan =
|
|
505
|
-
const $summarySpanFocus =
|
|
506
|
-
|
|
527
|
+
const $summarySpan = createElement('span');
|
|
528
|
+
const $summarySpanFocus = createElement('span', {
|
|
529
|
+
class: 'govuk-accordion__section-summary-focus'
|
|
530
|
+
});
|
|
507
531
|
$summarySpan.appendChild($summarySpanFocus);
|
|
508
532
|
for (const attr of Array.from($summary.attributes)) {
|
|
509
533
|
$summarySpan.setAttribute(attr.name, attr.value);
|
|
@@ -541,8 +565,8 @@
|
|
|
541
565
|
this.updateShowAllButton(nowExpanded);
|
|
542
566
|
}
|
|
543
567
|
setExpanded(expanded, $section) {
|
|
544
|
-
const $showHideIcon = $section.querySelector(`.${this.
|
|
545
|
-
const $showHideText = $section.querySelector(`.${this.
|
|
568
|
+
const $showHideIcon = $section.querySelector(`.${this.iconClass}`);
|
|
569
|
+
const $showHideText = $section.querySelector(`.${this.sectionToggleTextClass}`);
|
|
546
570
|
const $button = $section.querySelector(`.${this.sectionButtonClass}`);
|
|
547
571
|
const $content = $section.querySelector(`.${this.sectionContentClass}`);
|
|
548
572
|
if (!$content) {
|
|
@@ -571,17 +595,17 @@
|
|
|
571
595
|
$button.setAttribute('aria-label', ariaLabelParts.join(' , '));
|
|
572
596
|
if (expanded) {
|
|
573
597
|
$content.removeAttribute('hidden');
|
|
574
|
-
$section.classList.add(this.
|
|
575
|
-
$showHideIcon.classList.remove(this.
|
|
598
|
+
$section.classList.add(this.sectionExpandedModifier);
|
|
599
|
+
$showHideIcon.classList.remove(this.iconOpenModifier);
|
|
576
600
|
} else {
|
|
577
601
|
$content.setAttribute('hidden', 'until-found');
|
|
578
|
-
$section.classList.remove(this.
|
|
579
|
-
$showHideIcon.classList.add(this.
|
|
602
|
+
$section.classList.remove(this.sectionExpandedModifier);
|
|
603
|
+
$showHideIcon.classList.add(this.iconOpenModifier);
|
|
580
604
|
}
|
|
581
605
|
this.updateShowAllButton(this.areAllSectionsOpen());
|
|
582
606
|
}
|
|
583
607
|
isExpanded($section) {
|
|
584
|
-
return $section.classList.contains(this.
|
|
608
|
+
return $section.classList.contains(this.sectionExpandedModifier);
|
|
585
609
|
}
|
|
586
610
|
areAllSectionsOpen() {
|
|
587
611
|
return Array.from(this.$sections).every($section => this.isExpanded($section));
|
|
@@ -592,7 +616,7 @@
|
|
|
592
616
|
}
|
|
593
617
|
this.$showAllButton.setAttribute('aria-expanded', expanded.toString());
|
|
594
618
|
this.$showAllText.textContent = expanded ? this.i18n.t('hideAllSections') : this.i18n.t('showAllSections');
|
|
595
|
-
this.$showAllIcon.classList.toggle(this.
|
|
619
|
+
this.$showAllIcon.classList.toggle(this.iconOpenModifier, !expanded);
|
|
596
620
|
}
|
|
597
621
|
|
|
598
622
|
/**
|
|
@@ -635,10 +659,11 @@
|
|
|
635
659
|
}
|
|
636
660
|
}
|
|
637
661
|
getButtonPunctuationEl() {
|
|
638
|
-
const $
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
662
|
+
const $element = createElement('span', {
|
|
663
|
+
class: 'govuk-visually-hidden govuk-accordion__section-heading-divider'
|
|
664
|
+
});
|
|
665
|
+
$element.textContent = ', ';
|
|
666
|
+
return $element;
|
|
642
667
|
}
|
|
643
668
|
}
|
|
644
669
|
|
|
@@ -23,6 +23,9 @@ function isArray(option) {
|
|
|
23
23
|
function isObject(option) {
|
|
24
24
|
return !!option && typeof option === 'object' && !isArray(option);
|
|
25
25
|
}
|
|
26
|
+
function isScope($scope) {
|
|
27
|
+
return !!$scope && ($scope instanceof Element || $scope instanceof Document);
|
|
28
|
+
}
|
|
26
29
|
function formatErrorMessage(Component, message) {
|
|
27
30
|
return `${Component.moduleName}: ${message}`;
|
|
28
31
|
}
|
|
@@ -41,11 +44,14 @@ class SupportError extends GOVUKFrontendError {
|
|
|
41
44
|
/**
|
|
42
45
|
* Checks if GOV.UK Frontend is supported on this page
|
|
43
46
|
*
|
|
44
|
-
* @param {
|
|
47
|
+
* @param {Element | Document | null | string} [scopeOrMessage] - HTML element `<body>` checked for browser support or support error message
|
|
45
48
|
*/
|
|
46
|
-
constructor(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
constructor(scopeOrMessage = document.body) {
|
|
50
|
+
let 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';
|
|
51
|
+
if (!isScope(scopeOrMessage)) {
|
|
52
|
+
supportMessage = 'GOV.UK Frontend initialised without `<script type="module">`';
|
|
53
|
+
}
|
|
54
|
+
super(typeof scopeOrMessage === 'string' ? scopeOrMessage : supportMessage);
|
|
49
55
|
this.name = 'SupportError';
|
|
50
56
|
}
|
|
51
57
|
}
|
|
@@ -86,6 +92,7 @@ class InitError extends GOVUKFrontendError {
|
|
|
86
92
|
* @import { ComponentWithModuleName } from '../common/index.mjs'
|
|
87
93
|
*/
|
|
88
94
|
|
|
95
|
+
const _self = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
89
96
|
class Component {
|
|
90
97
|
/**
|
|
91
98
|
* Returns the root element of the component
|
|
@@ -139,7 +146,7 @@ class Component {
|
|
|
139
146
|
/**
|
|
140
147
|
* @typedef {typeof Component & ChildClass} ChildClassConstructor
|
|
141
148
|
*/
|
|
142
|
-
Component.elementType = HTMLElement;
|
|
149
|
+
Component.elementType = _self.HTMLElement;
|
|
143
150
|
|
|
144
151
|
const configOverride = Symbol.for('configOverride');
|
|
145
152
|
class ConfigurableComponent extends Component {
|
|
@@ -164,10 +171,14 @@ class ConfigurableComponent extends Component {
|
|
|
164
171
|
throw new ConfigError(formatErrorMessage(childConstructor, 'Config passed as parameter into constructor but no defaults defined'));
|
|
165
172
|
}
|
|
166
173
|
const datasetConfig = normaliseDataset(childConstructor, this._$root.dataset);
|
|
167
|
-
this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {}
|
|
174
|
+
this._config = mergeConfigs(childConstructor.defaults, config != null ? config : {});
|
|
175
|
+
this._config = mergeConfigs(this._config, this[configOverride](datasetConfig), datasetConfig);
|
|
168
176
|
}
|
|
169
177
|
}
|
|
170
178
|
function normaliseString(value, property) {
|
|
179
|
+
if (property != null && property.type && !['string', 'number', 'boolean'].includes(property.type)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
171
182
|
const trimmedValue = value ? value.trim() : '';
|
|
172
183
|
let output;
|
|
173
184
|
let outputType = property == null ? void 0 : property.type;
|
|
@@ -287,6 +298,17 @@ function extractConfigByNamespace(schema, dataset, namespace) {
|
|
|
287
298
|
* @import { CompatibleClass, Config, CreateAllOptions, OnErrorCallback } from '../init.mjs'
|
|
288
299
|
*/
|
|
289
300
|
|
|
301
|
+
function createElement(tagName, attributes = {}, children = []) {
|
|
302
|
+
const $element = document.createElement(tagName);
|
|
303
|
+
Object.entries(attributes).forEach(([name, value]) => {
|
|
304
|
+
$element.setAttribute(name, value);
|
|
305
|
+
});
|
|
306
|
+
for (const child of children) {
|
|
307
|
+
$element.append(child);
|
|
308
|
+
}
|
|
309
|
+
return $element;
|
|
310
|
+
}
|
|
311
|
+
|
|
290
312
|
class I18n {
|
|
291
313
|
constructor(translations = {}, config = {}) {
|
|
292
314
|
var _config$locale;
|
|
@@ -378,24 +400,16 @@ class Accordion extends ConfigurableComponent {
|
|
|
378
400
|
constructor($root, config = {}) {
|
|
379
401
|
super($root, config);
|
|
380
402
|
this.i18n = void 0;
|
|
381
|
-
this.controlsClass = 'govuk-accordion__controls';
|
|
382
|
-
this.showAllClass = 'govuk-accordion__show-all';
|
|
383
|
-
this.showAllTextClass = 'govuk-accordion__show-all-text';
|
|
384
403
|
this.sectionClass = 'govuk-accordion__section';
|
|
385
|
-
this.
|
|
404
|
+
this.sectionExpandedModifier = 'govuk-accordion__section--expanded';
|
|
386
405
|
this.sectionButtonClass = 'govuk-accordion__section-button';
|
|
387
406
|
this.sectionHeaderClass = 'govuk-accordion__section-header';
|
|
388
407
|
this.sectionHeadingClass = 'govuk-accordion__section-heading';
|
|
389
|
-
this.sectionHeadingDividerClass = 'govuk-accordion__section-heading-divider';
|
|
390
408
|
this.sectionHeadingTextClass = 'govuk-accordion__section-heading-text';
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.sectionShowHideTextClass = 'govuk-accordion__section-toggle-text';
|
|
395
|
-
this.upChevronIconClass = 'govuk-accordion-nav__chevron';
|
|
396
|
-
this.downChevronIconClass = 'govuk-accordion-nav__chevron--down';
|
|
409
|
+
this.sectionToggleTextClass = 'govuk-accordion__section-toggle-text';
|
|
410
|
+
this.iconClass = 'govuk-accordion-nav__chevron';
|
|
411
|
+
this.iconOpenModifier = 'govuk-accordion-nav__chevron--down';
|
|
397
412
|
this.sectionSummaryClass = 'govuk-accordion__section-summary';
|
|
398
|
-
this.sectionSummaryFocusClass = 'govuk-accordion__section-summary-focus';
|
|
399
413
|
this.sectionContentClass = 'govuk-accordion__section-content';
|
|
400
414
|
this.$sections = void 0;
|
|
401
415
|
this.$showAllButton = null;
|
|
@@ -415,19 +429,23 @@ class Accordion extends ConfigurableComponent {
|
|
|
415
429
|
this.updateShowAllButton(this.areAllSectionsOpen());
|
|
416
430
|
}
|
|
417
431
|
initControls() {
|
|
418
|
-
this.$showAllButton =
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this.$showAllIcon
|
|
432
|
+
this.$showAllButton = createElement('button', {
|
|
433
|
+
type: 'button',
|
|
434
|
+
class: 'govuk-accordion__show-all',
|
|
435
|
+
'aria-expanded': 'false'
|
|
436
|
+
});
|
|
437
|
+
this.$showAllIcon = createElement('span', {
|
|
438
|
+
class: this.iconClass
|
|
439
|
+
});
|
|
424
440
|
this.$showAllButton.appendChild(this.$showAllIcon);
|
|
425
|
-
const $accordionControls =
|
|
426
|
-
|
|
441
|
+
const $accordionControls = createElement('div', {
|
|
442
|
+
class: 'govuk-accordion__controls'
|
|
443
|
+
});
|
|
427
444
|
$accordionControls.appendChild(this.$showAllButton);
|
|
428
445
|
this.$root.insertBefore($accordionControls, this.$root.firstChild);
|
|
429
|
-
this.$showAllText =
|
|
430
|
-
|
|
446
|
+
this.$showAllText = createElement('span', {
|
|
447
|
+
class: 'govuk-accordion__show-all-text'
|
|
448
|
+
});
|
|
431
449
|
this.$showAllButton.appendChild(this.$showAllText);
|
|
432
450
|
this.$showAllButton.addEventListener('click', () => this.onShowOrHideAllToggle());
|
|
433
451
|
if ('onbeforematch' in document) {
|
|
@@ -465,39 +483,45 @@ class Accordion extends ConfigurableComponent {
|
|
|
465
483
|
identifier: `Section button placeholder (\`<span class="${this.sectionButtonClass}">\`)`
|
|
466
484
|
});
|
|
467
485
|
}
|
|
468
|
-
const $button =
|
|
469
|
-
|
|
470
|
-
|
|
486
|
+
const $button = createElement('button', {
|
|
487
|
+
type: 'button',
|
|
488
|
+
'aria-controls': `${this.$root.id}-content-${index + 1}`
|
|
489
|
+
});
|
|
471
490
|
for (const attr of Array.from($span.attributes)) {
|
|
472
491
|
if (attr.name !== 'id') {
|
|
473
492
|
$button.setAttribute(attr.name, attr.value);
|
|
474
493
|
}
|
|
475
494
|
}
|
|
476
|
-
const $headingText =
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
$headingTextFocus
|
|
495
|
+
const $headingText = createElement('span', {
|
|
496
|
+
class: this.sectionHeadingTextClass,
|
|
497
|
+
id: $span.id
|
|
498
|
+
});
|
|
499
|
+
const $headingTextFocus = createElement('span', {
|
|
500
|
+
class: 'govuk-accordion__section-heading-text-focus'
|
|
501
|
+
});
|
|
481
502
|
$headingText.appendChild($headingTextFocus);
|
|
482
503
|
Array.from($span.childNodes).forEach($child => $headingTextFocus.appendChild($child));
|
|
483
|
-
const $showHideToggle =
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
$showHideToggleFocus
|
|
504
|
+
const $showHideToggle = createElement('span', {
|
|
505
|
+
class: 'govuk-accordion__section-toggle',
|
|
506
|
+
'data-nosnippet': ''
|
|
507
|
+
});
|
|
508
|
+
const $showHideToggleFocus = createElement('span', {
|
|
509
|
+
class: 'govuk-accordion__section-toggle-focus'
|
|
510
|
+
});
|
|
488
511
|
$showHideToggle.appendChild($showHideToggleFocus);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
$showHideToggleFocus.appendChild(
|
|
493
|
-
|
|
494
|
-
|
|
512
|
+
$showHideToggleFocus.appendChild(createElement('span', {
|
|
513
|
+
class: this.iconClass
|
|
514
|
+
}));
|
|
515
|
+
$showHideToggleFocus.appendChild(createElement('span', {
|
|
516
|
+
class: this.sectionToggleTextClass
|
|
517
|
+
}));
|
|
495
518
|
$button.appendChild($headingText);
|
|
496
519
|
$button.appendChild(this.getButtonPunctuationEl());
|
|
497
520
|
if ($summary) {
|
|
498
|
-
const $summarySpan =
|
|
499
|
-
const $summarySpanFocus =
|
|
500
|
-
|
|
521
|
+
const $summarySpan = createElement('span');
|
|
522
|
+
const $summarySpanFocus = createElement('span', {
|
|
523
|
+
class: 'govuk-accordion__section-summary-focus'
|
|
524
|
+
});
|
|
501
525
|
$summarySpan.appendChild($summarySpanFocus);
|
|
502
526
|
for (const attr of Array.from($summary.attributes)) {
|
|
503
527
|
$summarySpan.setAttribute(attr.name, attr.value);
|
|
@@ -535,8 +559,8 @@ class Accordion extends ConfigurableComponent {
|
|
|
535
559
|
this.updateShowAllButton(nowExpanded);
|
|
536
560
|
}
|
|
537
561
|
setExpanded(expanded, $section) {
|
|
538
|
-
const $showHideIcon = $section.querySelector(`.${this.
|
|
539
|
-
const $showHideText = $section.querySelector(`.${this.
|
|
562
|
+
const $showHideIcon = $section.querySelector(`.${this.iconClass}`);
|
|
563
|
+
const $showHideText = $section.querySelector(`.${this.sectionToggleTextClass}`);
|
|
540
564
|
const $button = $section.querySelector(`.${this.sectionButtonClass}`);
|
|
541
565
|
const $content = $section.querySelector(`.${this.sectionContentClass}`);
|
|
542
566
|
if (!$content) {
|
|
@@ -565,17 +589,17 @@ class Accordion extends ConfigurableComponent {
|
|
|
565
589
|
$button.setAttribute('aria-label', ariaLabelParts.join(' , '));
|
|
566
590
|
if (expanded) {
|
|
567
591
|
$content.removeAttribute('hidden');
|
|
568
|
-
$section.classList.add(this.
|
|
569
|
-
$showHideIcon.classList.remove(this.
|
|
592
|
+
$section.classList.add(this.sectionExpandedModifier);
|
|
593
|
+
$showHideIcon.classList.remove(this.iconOpenModifier);
|
|
570
594
|
} else {
|
|
571
595
|
$content.setAttribute('hidden', 'until-found');
|
|
572
|
-
$section.classList.remove(this.
|
|
573
|
-
$showHideIcon.classList.add(this.
|
|
596
|
+
$section.classList.remove(this.sectionExpandedModifier);
|
|
597
|
+
$showHideIcon.classList.add(this.iconOpenModifier);
|
|
574
598
|
}
|
|
575
599
|
this.updateShowAllButton(this.areAllSectionsOpen());
|
|
576
600
|
}
|
|
577
601
|
isExpanded($section) {
|
|
578
|
-
return $section.classList.contains(this.
|
|
602
|
+
return $section.classList.contains(this.sectionExpandedModifier);
|
|
579
603
|
}
|
|
580
604
|
areAllSectionsOpen() {
|
|
581
605
|
return Array.from(this.$sections).every($section => this.isExpanded($section));
|
|
@@ -586,7 +610,7 @@ class Accordion extends ConfigurableComponent {
|
|
|
586
610
|
}
|
|
587
611
|
this.$showAllButton.setAttribute('aria-expanded', expanded.toString());
|
|
588
612
|
this.$showAllText.textContent = expanded ? this.i18n.t('hideAllSections') : this.i18n.t('showAllSections');
|
|
589
|
-
this.$showAllIcon.classList.toggle(this.
|
|
613
|
+
this.$showAllIcon.classList.toggle(this.iconOpenModifier, !expanded);
|
|
590
614
|
}
|
|
591
615
|
|
|
592
616
|
/**
|
|
@@ -629,10 +653,11 @@ class Accordion extends ConfigurableComponent {
|
|
|
629
653
|
}
|
|
630
654
|
}
|
|
631
655
|
getButtonPunctuationEl() {
|
|
632
|
-
const $
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
656
|
+
const $element = createElement('span', {
|
|
657
|
+
class: 'govuk-visually-hidden govuk-accordion__section-heading-divider'
|
|
658
|
+
});
|
|
659
|
+
$element.textContent = ', ';
|
|
660
|
+
return $element;
|
|
636
661
|
}
|
|
637
662
|
}
|
|
638
663
|
|