@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.
- package/govuk-prototype-kit.config.json +19 -4
- package/moj/_base.scss +2 -0
- package/moj/_base.scss.map +1 -0
- package/moj/all.bundle.js +3010 -0
- package/moj/all.bundle.js.map +1 -0
- package/moj/all.bundle.mjs +3293 -0
- package/moj/all.bundle.mjs.map +1 -0
- package/moj/all.mjs +17 -110
- package/moj/all.mjs.map +1 -1
- package/moj/all.scss +3 -0
- package/moj/all.scss.map +1 -0
- package/moj/common/index.mjs +57 -0
- package/moj/common/index.mjs.map +1 -0
- package/moj/common/moj-frontend-version.mjs +14 -0
- package/moj/common/moj-frontend-version.mjs.map +1 -0
- package/moj/components/_all.scss +2 -0
- package/moj/components/_all.scss.map +1 -0
- package/moj/components/action-bar/_action-bar.scss +2 -0
- package/moj/components/action-bar/_action-bar.scss.map +1 -0
- package/moj/components/add-another/_add-another.scss +2 -0
- package/moj/components/add-another/_add-another.scss.map +1 -0
- package/moj/components/add-another/add-another.bundle.js +157 -0
- package/moj/components/add-another/add-another.bundle.js.map +1 -0
- package/moj/components/add-another/add-another.bundle.mjs +271 -0
- package/moj/components/add-another/add-another.bundle.mjs.map +1 -0
- package/moj/components/add-another/add-another.mjs +135 -91
- package/moj/components/add-another/add-another.mjs.map +1 -1
- package/moj/components/alert/_alert.scss +4 -0
- package/moj/components/alert/_alert.scss.map +1 -0
- package/moj/components/alert/alert.bundle.js +254 -0
- package/moj/components/alert/alert.bundle.js.map +1 -0
- package/moj/components/alert/alert.bundle.mjs +490 -0
- package/moj/components/alert/alert.bundle.mjs.map +1 -0
- package/moj/components/alert/alert.mjs +97 -218
- package/moj/components/alert/alert.mjs.map +1 -1
- package/moj/components/alert/{alert.spec.helper.js → alert.spec.helper.bundle.js} +1 -1
- package/moj/components/alert/alert.spec.helper.bundle.js.map +1 -0
- package/moj/components/alert/alert.spec.helper.bundle.mjs +67 -0
- package/moj/components/alert/alert.spec.helper.bundle.mjs.map +1 -0
- package/moj/components/alert/alert.spec.helper.mjs.map +1 -1
- package/moj/components/badge/_badge.scss +2 -0
- package/moj/components/badge/_badge.scss.map +1 -0
- package/moj/components/banner/_banner.scss +2 -0
- package/moj/components/banner/_banner.scss.map +1 -0
- package/moj/components/button-menu/README.md +12 -6
- package/moj/components/button-menu/_button-menu.scss +4 -1
- package/moj/components/button-menu/_button-menu.scss.map +1 -0
- package/moj/components/button-menu/button-menu.bundle.js +270 -0
- package/moj/components/button-menu/button-menu.bundle.js.map +1 -0
- package/moj/components/button-menu/button-menu.bundle.mjs +506 -0
- package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -0
- package/moj/components/button-menu/button-menu.mjs +214 -280
- package/moj/components/button-menu/button-menu.mjs.map +1 -1
- package/moj/components/cookie-banner/_cookie-banner.scss +2 -0
- package/moj/components/cookie-banner/_cookie-banner.scss.map +1 -0
- package/moj/components/currency-input/_currency-input.scss +2 -0
- package/moj/components/currency-input/_currency-input.scss.map +1 -0
- package/moj/components/date-picker/_date-picker.scss +2 -0
- package/moj/components/date-picker/_date-picker.scss.map +1 -0
- package/moj/components/date-picker/date-picker.bundle.js +804 -0
- package/moj/components/date-picker/date-picker.bundle.js.map +1 -0
- package/moj/components/date-picker/date-picker.bundle.mjs +1040 -0
- package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -0
- package/moj/components/date-picker/date-picker.mjs +663 -827
- package/moj/components/date-picker/date-picker.mjs.map +1 -1
- package/moj/components/filter/_filter.scss +2 -0
- package/moj/components/filter/_filter.scss.map +1 -0
- package/moj/components/filter/template.njk +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +185 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +421 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +166 -81
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
- package/moj/components/form-validator/form-validator.bundle.js +288 -0
- package/moj/components/form-validator/form-validator.bundle.js.map +1 -0
- package/moj/components/form-validator/form-validator.bundle.mjs +524 -0
- package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -0
- package/moj/components/form-validator/form-validator.mjs +226 -149
- package/moj/components/form-validator/form-validator.mjs.map +1 -1
- package/moj/components/header/_header.scss +2 -0
- package/moj/components/header/_header.scss.map +1 -0
- package/moj/components/identity-bar/_identity-bar.scss +2 -0
- package/moj/components/identity-bar/_identity-bar.scss.map +1 -0
- package/moj/components/interruption-card/_interruption-card.scss +2 -0
- package/moj/components/interruption-card/_interruption-card.scss.map +1 -0
- package/moj/components/messages/_messages.scss +2 -0
- package/moj/components/messages/_messages.scss.map +1 -0
- package/moj/components/multi-file-upload/_multi-file-upload.scss +2 -0
- package/moj/components/multi-file-upload/_multi-file-upload.scss.map +1 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js +397 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +633 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -0
- package/moj/components/multi-file-upload/multi-file-upload.mjs +384 -213
- package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
- package/moj/components/multi-file-upload/template.njk +1 -1
- package/moj/components/multi-select/_multi-select.scss +2 -0
- package/moj/components/multi-select/_multi-select.scss.map +1 -0
- package/moj/components/multi-select/multi-select.bundle.js +143 -0
- package/moj/components/multi-select/multi-select.bundle.js.map +1 -0
- package/moj/components/multi-select/multi-select.bundle.mjs +379 -0
- package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -0
- package/moj/components/multi-select/multi-select.mjs +123 -64
- package/moj/components/multi-select/multi-select.mjs.map +1 -1
- package/moj/components/notification-badge/_notification-badge.scss +2 -0
- package/moj/components/notification-badge/_notification-badge.scss.map +1 -0
- package/moj/components/organisation-switcher/_organisation-switcher.scss +2 -0
- package/moj/components/organisation-switcher/_organisation-switcher.scss.map +1 -0
- package/moj/components/page-header-actions/_page-header-actions.scss +2 -0
- package/moj/components/page-header-actions/_page-header-actions.scss.map +1 -0
- package/moj/components/pagination/_pagination.scss +2 -2
- package/moj/components/pagination/_pagination.scss.map +1 -0
- package/moj/components/password-reveal/_password-reveal.scss +5 -1
- package/moj/components/password-reveal/_password-reveal.scss.map +1 -0
- package/moj/components/password-reveal/password-reveal.bundle.js +52 -0
- package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -0
- package/moj/components/password-reveal/password-reveal.bundle.mjs +166 -0
- package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -0
- package/moj/components/password-reveal/password-reveal.mjs +39 -29
- package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
- package/moj/components/primary-navigation/_primary-navigation.scss +2 -0
- package/moj/components/primary-navigation/_primary-navigation.scss.map +1 -0
- package/moj/components/progress-bar/_progress-bar.scss +2 -0
- package/moj/components/progress-bar/_progress-bar.scss.map +1 -0
- package/moj/components/rich-text-editor/README.md +16 -9
- package/moj/components/rich-text-editor/_rich-text-editor.scss +2 -0
- package/moj/components/rich-text-editor/_rich-text-editor.scss.map +1 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js +210 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +446 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -0
- package/moj/components/rich-text-editor/rich-text-editor.mjs +186 -140
- package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
- package/moj/components/search/_search.scss +2 -0
- package/moj/components/search/_search.scss.map +1 -0
- package/moj/components/search-toggle/{search-toggle.scss → _search-toggle.scss} +2 -0
- package/moj/components/search-toggle/_search-toggle.scss.map +1 -0
- package/moj/components/search-toggle/search-toggle.bundle.js +122 -0
- package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -0
- package/moj/components/search-toggle/search-toggle.bundle.mjs +358 -0
- package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -0
- package/moj/components/search-toggle/search-toggle.mjs +104 -43
- package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
- package/moj/components/side-navigation/_side-navigation.scss +2 -0
- package/moj/components/side-navigation/_side-navigation.scss.map +1 -0
- package/moj/components/sortable-table/_sortable-table.scss +2 -2
- package/moj/components/sortable-table/_sortable-table.scss.map +1 -0
- package/moj/components/sortable-table/sortable-table.bundle.js +202 -0
- package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -0
- package/moj/components/sortable-table/sortable-table.bundle.mjs +438 -0
- package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -0
- package/moj/components/sortable-table/sortable-table.mjs +179 -122
- package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
- package/moj/components/sub-navigation/_sub-navigation.scss +2 -0
- package/moj/components/sub-navigation/_sub-navigation.scss.map +1 -0
- package/moj/components/tag/_tag.scss +2 -0
- package/moj/components/tag/_tag.scss.map +1 -0
- package/moj/components/task-list/_task-list.scss +2 -0
- package/moj/components/task-list/_task-list.scss.map +1 -0
- package/moj/components/ticket-panel/_ticket-panel.scss +2 -0
- package/moj/components/ticket-panel/_ticket-panel.scss.map +1 -0
- package/moj/components/timeline/_timeline.scss +2 -0
- package/moj/components/timeline/_timeline.scss.map +1 -0
- package/moj/core/_all.scss +3 -0
- package/moj/core/_all.scss.map +1 -0
- package/moj/core/_moj-frontend-properties.scss +7 -0
- package/moj/core/_moj-frontend-properties.scss.map +1 -0
- package/moj/filters/all.js +44 -22
- package/moj/filters/prototype-kit-13-filters.js +4 -3
- package/moj/helpers/_all.scss +2 -0
- package/moj/helpers/_all.scss.map +1 -0
- package/moj/helpers/_hidden.scss +2 -0
- package/moj/helpers/_hidden.scss.map +1 -0
- package/moj/helpers/_links.scss +2 -0
- package/moj/helpers/_links.scss.map +1 -0
- package/moj/helpers.bundle.js +140 -0
- package/moj/helpers.bundle.js.map +1 -0
- package/moj/helpers.bundle.mjs +128 -0
- package/moj/helpers.bundle.mjs.map +1 -0
- package/moj/helpers.mjs +50 -77
- package/moj/helpers.mjs.map +1 -1
- package/moj/init.js +11 -2
- package/moj/moj-frontend.min.css +1 -1
- package/moj/moj-frontend.min.css.map +1 -1
- package/moj/moj-frontend.min.js +1 -1
- package/moj/moj-frontend.min.js.map +1 -1
- package/moj/objects/_all.scss +2 -0
- package/moj/objects/_all.scss.map +1 -0
- package/moj/objects/_button-group.scss +2 -0
- package/moj/objects/_button-group.scss.map +1 -0
- package/moj/objects/_filter-layout.scss +2 -0
- package/moj/objects/_filter-layout.scss.map +1 -0
- package/moj/objects/_scrollable-pane.scss +2 -0
- package/moj/objects/_scrollable-pane.scss.map +1 -0
- package/moj/objects/_width-container.scss +2 -0
- package/moj/objects/_width-container.scss.map +1 -0
- package/moj/settings/_all.scss +2 -0
- package/moj/settings/_all.scss.map +1 -0
- package/moj/settings/_assets.scss +2 -0
- package/moj/settings/_assets.scss.map +1 -0
- package/moj/settings/_colours.scss +2 -0
- package/moj/settings/_colours.scss.map +1 -0
- package/moj/settings/_measurements.scss +2 -0
- package/moj/settings/_measurements.scss.map +1 -0
- package/moj/settings/_typography.scss +2 -0
- package/moj/settings/_typography.scss.map +1 -0
- package/moj/template.njk +13 -0
- package/moj/utilities/_all.scss +2 -0
- package/moj/utilities/_all.scss.map +1 -0
- package/moj/utilities/_hidden.scss +2 -0
- package/moj/utilities/_hidden.scss.map +1 -0
- package/moj/utilities/_width-container.scss +2 -0
- package/moj/utilities/_width-container.scss.map +1 -0
- package/moj/vendor/govuk-frontend/_base.scss +2 -0
- package/moj/vendor/govuk-frontend/_base.scss.map +1 -0
- package/moj/vendor/govuk-frontend/_index.scss +2 -0
- package/moj/vendor/govuk-frontend/_index.scss.map +1 -0
- package/package.json +5 -6
- package/moj/all.jquery.min.js +0 -1
- package/moj/all.jquery.min.js.map +0 -1
- package/moj/all.js +0 -2662
- package/moj/all.js.map +0 -1
- package/moj/components/add-another/add-another.js +0 -115
- package/moj/components/add-another/add-another.js.map +0 -1
- package/moj/components/alert/alert.js +0 -356
- package/moj/components/alert/alert.js.map +0 -1
- package/moj/components/alert/alert.spec.helper.js.map +0 -1
- package/moj/components/button-menu/button-menu.js +0 -338
- package/moj/components/button-menu/button-menu.js.map +0 -1
- package/moj/components/date-picker/date-picker.js +0 -970
- package/moj/components/date-picker/date-picker.js.map +0 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.js +0 -102
- package/moj/components/filter-toggle-button/filter-toggle-button.js.map +0 -1
- package/moj/components/form-validator/form-validator.js +0 -205
- package/moj/components/form-validator/form-validator.js.map +0 -1
- package/moj/components/multi-file-upload/multi-file-upload.js +0 -241
- package/moj/components/multi-file-upload/multi-file-upload.js.map +0 -1
- package/moj/components/multi-select/multi-select.js +0 -86
- package/moj/components/multi-select/multi-select.js.map +0 -1
- package/moj/components/password-reveal/password-reveal.js +0 -44
- package/moj/components/password-reveal/password-reveal.js.map +0 -1
- package/moj/components/rich-text-editor/rich-text-editor.js +0 -166
- package/moj/components/rich-text-editor/rich-text-editor.js.map +0 -1
- package/moj/components/search-toggle/search-toggle.js +0 -63
- package/moj/components/search-toggle/search-toggle.js.map +0 -1
- package/moj/components/sortable-table/sortable-table.js +0 -147
- package/moj/components/sortable-table/sortable-table.js.map +0 -1
- package/moj/helpers.js +0 -200
- package/moj/helpers.js.map +0 -1
- package/moj/vendor/html5shiv.js +0 -326
- package/moj/vendor/jquery.js +0 -9300
- package/moj/version.js +0 -12
- package/moj/version.js.map +0 -1
- package/moj/version.mjs +0 -4
- package/moj/version.mjs.map +0 -1
|
@@ -1,139 +1,196 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ConfigurableComponent } from 'govuk-frontend';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @augments {ConfigurableComponent<SortableTableConfig>}
|
|
5
|
+
*/
|
|
6
|
+
class SortableTable extends ConfigurableComponent {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Element | null} $root - HTML element to use for sortable table
|
|
9
|
+
* @param {SortableTableConfig} [config] - Sortable table config
|
|
10
|
+
*/
|
|
11
|
+
constructor($root, config = {}) {
|
|
12
|
+
super($root, config);
|
|
13
|
+
const $head = $root == null ? void 0 : $root.querySelector('thead');
|
|
14
|
+
const $body = $root == null ? void 0 : $root.querySelector('tbody');
|
|
15
|
+
if (!$head || !$body) {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
this.$head = $head;
|
|
19
|
+
this.$body = $body;
|
|
20
|
+
this.$headings = this.$head ? Array.from(this.$head.querySelectorAll('th')) : [];
|
|
21
|
+
this.createHeadingButtons();
|
|
22
|
+
this.createStatusBox();
|
|
23
|
+
this.initialiseSortedColumn();
|
|
24
|
+
this.$head.addEventListener('click', this.onSortButtonClick.bind(this));
|
|
6
25
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.createHeadingButtons();
|
|
13
|
-
this.createStatusBox();
|
|
14
|
-
this.initialiseSortedColumn();
|
|
15
|
-
this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
SortableTable.prototype.setupOptions = function (params) {
|
|
19
|
-
params = params || {};
|
|
20
|
-
this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)';
|
|
21
|
-
this.ascendingText = params.ascendingText || 'ascending';
|
|
22
|
-
this.descendingText = params.descendingText || 'descending';
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
SortableTable.prototype.createHeadingButtons = function () {
|
|
26
|
-
const headings = this.table.find('thead th');
|
|
27
|
-
let heading;
|
|
28
|
-
for (let i = 0; i < headings.length; i++) {
|
|
29
|
-
heading = $(headings[i]);
|
|
30
|
-
if (heading.attr('aria-sort')) {
|
|
31
|
-
this.createHeadingButton(heading, i);
|
|
26
|
+
createHeadingButtons() {
|
|
27
|
+
for (const $heading of this.$headings) {
|
|
28
|
+
if ($heading.hasAttribute('aria-sort')) {
|
|
29
|
+
this.createHeadingButton($heading);
|
|
30
|
+
}
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
SortableTable.prototype.createHeadingButton = function (heading, i) {
|
|
37
|
-
const text = heading.text();
|
|
38
|
-
const button = $(`<button type="button" data-index="${i}">${text}</button>`);
|
|
39
|
-
heading.text('');
|
|
40
|
-
heading.append(button);
|
|
41
|
-
};
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
34
|
+
/**
|
|
35
|
+
* @param {HTMLTableCellElement} $heading
|
|
36
|
+
*/
|
|
37
|
+
createHeadingButton($heading) {
|
|
38
|
+
const index = this.$headings.indexOf($heading);
|
|
39
|
+
const $button = document.createElement('button');
|
|
40
|
+
$button.setAttribute('type', 'button');
|
|
41
|
+
$button.setAttribute('data-index', `${index}`);
|
|
42
|
+
$button.textContent = $heading.textContent;
|
|
43
|
+
$heading.textContent = '';
|
|
44
|
+
$heading.appendChild($button);
|
|
45
|
+
}
|
|
46
|
+
createStatusBox() {
|
|
47
|
+
this.$status = document.createElement('div');
|
|
48
|
+
this.$status.setAttribute('aria-atomic', 'true');
|
|
49
|
+
this.$status.setAttribute('aria-live', 'polite');
|
|
50
|
+
this.$status.setAttribute('class', 'govuk-visually-hidden');
|
|
51
|
+
this.$status.setAttribute('role', 'status');
|
|
52
|
+
this.$root.insertAdjacentElement('afterend', this.$status);
|
|
53
|
+
}
|
|
54
|
+
initialiseSortedColumn() {
|
|
55
|
+
var _$sortButton$getAttri;
|
|
56
|
+
const $rows = this.getTableRowsArray();
|
|
57
|
+
const $heading = this.$root.querySelector('th[aria-sort]');
|
|
58
|
+
const $sortButton = $heading == null ? void 0 : $heading.querySelector('button');
|
|
59
|
+
const sortDirection = $heading == null ? void 0 : $heading.getAttribute('aria-sort');
|
|
60
|
+
const columnNumber = Number.parseInt((_$sortButton$getAttri = $sortButton == null ? void 0 : $sortButton.getAttribute('data-index')) != null ? _$sortButton$getAttri : '0', 10);
|
|
61
|
+
if (!$heading || !$sortButton || !(sortDirection === 'ascending' || sortDirection === 'descending')) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const $sortedRows = this.sort($rows, columnNumber, sortDirection);
|
|
65
|
+
this.addRows($sortedRows);
|
|
73
66
|
}
|
|
74
|
-
const rows = this.getTableRowsArray();
|
|
75
|
-
const sortedRows = this.sort(rows, columnNumber, newSortDirection);
|
|
76
|
-
this.addRows(sortedRows);
|
|
77
|
-
this.removeButtonStates();
|
|
78
|
-
this.updateButtonState($(e.currentTarget), newSortDirection);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
SortableTable.prototype.updateButtonState = function (button, direction) {
|
|
82
|
-
button.parent().attr('aria-sort', direction);
|
|
83
|
-
let message = this.statusMessage;
|
|
84
|
-
message = message.replace(/%heading%/, button.text());
|
|
85
|
-
message = message.replace(/%direction%/, this[`${direction}Text`]);
|
|
86
|
-
this.status.text(message);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
SortableTable.prototype.removeButtonStates = function () {
|
|
90
|
-
this.table.find('thead th').attr('aria-sort', 'none');
|
|
91
|
-
};
|
|
92
67
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @param {MouseEvent} event - Click event
|
|
70
|
+
*/
|
|
71
|
+
onSortButtonClick(event) {
|
|
72
|
+
var _$button$getAttribute;
|
|
73
|
+
const $button = event.target;
|
|
74
|
+
if (!$button || !($button instanceof HTMLButtonElement) || !$button.parentElement) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const $heading = $button.parentElement;
|
|
78
|
+
const sortDirection = $heading.getAttribute('aria-sort');
|
|
79
|
+
const columnNumber = Number.parseInt((_$button$getAttribute = $button == null ? void 0 : $button.getAttribute('data-index')) != null ? _$button$getAttribute : '0', 10);
|
|
80
|
+
const newSortDirection = sortDirection === 'none' || sortDirection === 'descending' ? 'ascending' : 'descending';
|
|
81
|
+
const $rows = this.getTableRowsArray();
|
|
82
|
+
const $sortedRows = this.sort($rows, columnNumber, newSortDirection);
|
|
83
|
+
this.addRows($sortedRows);
|
|
84
|
+
this.removeButtonStates();
|
|
85
|
+
this.updateButtonState($button, newSortDirection);
|
|
96
86
|
}
|
|
97
|
-
};
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
/**
|
|
89
|
+
* @param {HTMLButtonElement} $button
|
|
90
|
+
* @param {string} direction
|
|
91
|
+
*/
|
|
92
|
+
updateButtonState($button, direction) {
|
|
93
|
+
if (!(direction === 'ascending' || direction === 'descending')) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
$button.parentElement.setAttribute('aria-sort', direction);
|
|
97
|
+
let message = this.config.statusMessage;
|
|
98
|
+
message = message.replace(/%heading%/, $button.textContent);
|
|
99
|
+
message = message.replace(/%direction%/, this.config[`${direction}Text`]);
|
|
100
|
+
this.$status.textContent = message;
|
|
101
|
+
}
|
|
102
|
+
removeButtonStates() {
|
|
103
|
+
for (const $heading of this.$headings) {
|
|
104
|
+
$heading.setAttribute('aria-sort', 'none');
|
|
105
|
+
}
|
|
104
106
|
}
|
|
105
|
-
return rows
|
|
106
|
-
};
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
/**
|
|
109
|
+
* @param {HTMLTableRowElement[]} $rows
|
|
110
|
+
*/
|
|
111
|
+
addRows($rows) {
|
|
112
|
+
for (const $row of $rows) {
|
|
113
|
+
this.$body.append($row);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getTableRowsArray() {
|
|
117
|
+
return Array.from(this.$body.querySelectorAll('tr'));
|
|
118
|
+
}
|
|
113
119
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
/**
|
|
121
|
+
* @param {HTMLTableRowElement[]} $rows
|
|
122
|
+
* @param {number} columnNumber
|
|
123
|
+
* @param {string} sortDirection
|
|
124
|
+
*/
|
|
125
|
+
sort($rows, columnNumber, sortDirection) {
|
|
126
|
+
return $rows.sort(($rowA, $rowB) => {
|
|
127
|
+
const $tdA = $rowA.querySelectorAll('td, th')[columnNumber];
|
|
128
|
+
const $tdB = $rowB.querySelectorAll('td, th')[columnNumber];
|
|
129
|
+
if (!$tdA || !$tdB || !($tdA instanceof HTMLElement) || !($tdB instanceof HTMLElement)) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
const valueA = sortDirection === 'ascending' ? this.getCellValue($tdA) : this.getCellValue($tdB);
|
|
133
|
+
const valueB = sortDirection === 'ascending' ? this.getCellValue($tdB) : this.getCellValue($tdA);
|
|
134
|
+
return !(typeof valueA === 'number' && typeof valueB === 'number') ? valueA.toString().localeCompare(valueB.toString()) : valueA - valueB;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
122
137
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
/**
|
|
139
|
+
* @param {HTMLElement} $cell
|
|
140
|
+
*/
|
|
141
|
+
getCellValue($cell) {
|
|
142
|
+
const val = $cell.getAttribute('data-sort-value') || $cell.innerHTML;
|
|
143
|
+
const valAsNumber = Number(val);
|
|
144
|
+
return Number.isFinite(valAsNumber) ? valAsNumber // Exclude invalid numbers, infinity etc
|
|
145
|
+
: val;
|
|
146
|
+
}
|
|
130
147
|
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Name for the component used when initialising using data-module attributes.
|
|
150
|
+
*/
|
|
151
|
+
}
|
|
133
152
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Sortable table config
|
|
155
|
+
*
|
|
156
|
+
* @typedef {object} SortableTableConfig
|
|
157
|
+
* @property {string} [statusMessage] - Status message
|
|
158
|
+
* @property {string} [ascendingText] - Ascending text
|
|
159
|
+
* @property {string} [descendingText] - Descending text
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'
|
|
164
|
+
*/
|
|
165
|
+
SortableTable.moduleName = 'moj-sortable-table';
|
|
166
|
+
/**
|
|
167
|
+
* Sortable table config
|
|
168
|
+
*
|
|
169
|
+
* @type {SortableTableConfig}
|
|
170
|
+
*/
|
|
171
|
+
SortableTable.defaults = Object.freeze({
|
|
172
|
+
statusMessage: 'Sort by %heading% (%direction%)',
|
|
173
|
+
ascendingText: 'ascending',
|
|
174
|
+
descendingText: 'descending'
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* Sortable table config schema
|
|
178
|
+
*
|
|
179
|
+
* @satisfies {Schema<SortableTableConfig>}
|
|
180
|
+
*/
|
|
181
|
+
SortableTable.schema = Object.freeze(/** @type {const} */{
|
|
182
|
+
properties: {
|
|
183
|
+
statusMessage: {
|
|
184
|
+
type: 'string'
|
|
185
|
+
},
|
|
186
|
+
ascendingText: {
|
|
187
|
+
type: 'string'
|
|
188
|
+
},
|
|
189
|
+
descendingText: {
|
|
190
|
+
type: 'string'
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
137
194
|
|
|
138
195
|
export { SortableTable };
|
|
139
196
|
//# sourceMappingURL=sortable-table.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortable-table.mjs","sources":["../../../../src/moj/components/sortable-table/sortable-table.mjs"],"sourcesContent":["import $ from 'jquery'\n\nexport function SortableTable(params) {\n this.table = $(params.table)\n\n if (this.table.data('moj-search-toggle-initialised')) {\n return\n }\n\n this.table.data('moj-search-toggle-initialised', true)\n\n this.setupOptions(params)\n this.body = this.table.find('tbody')\n this.createHeadingButtons()\n this.createStatusBox()\n this.initialiseSortedColumn()\n this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'))\n}\n\nSortableTable.prototype.setupOptions = function (params) {\n params = params || {}\n this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)'\n this.ascendingText = params.ascendingText || 'ascending'\n this.descendingText = params.descendingText || 'descending'\n}\n\nSortableTable.prototype.createHeadingButtons = function () {\n const headings = this.table.find('thead th')\n let heading\n for (let i = 0; i < headings.length; i++) {\n heading = $(headings[i])\n if (heading.attr('aria-sort')) {\n this.createHeadingButton(heading, i)\n }\n }\n}\n\nSortableTable.prototype.createHeadingButton = function (heading, i) {\n const text = heading.text()\n const button = $(`<button type=\"button\" data-index=\"${i}\">${text}</button>`)\n heading.text('')\n heading.append(button)\n}\n\nSortableTable.prototype.createStatusBox = function () {\n this.status = $(\n '<div aria-live=\"polite\" role=\"status\" aria-atomic=\"true\" class=\"govuk-visually-hidden\" />'\n )\n this.table.parent().append(this.status)\n}\n\nSortableTable.prototype.initialiseSortedColumn = function () {\n const rows = this.getTableRowsArray()\n\n this.table\n .find('th')\n .filter('[aria-sort=\"ascending\"], [aria-sort=\"descending\"]')\n .first()\n .each((index, el) => {\n const sortDirection = $(el).attr('aria-sort')\n const columnNumber = $(el).find('button').attr('data-index')\n const sortedRows = this.sort(rows, columnNumber, sortDirection)\n this.addRows(sortedRows)\n })\n}\n\nSortableTable.prototype.onSortButtonClick = function (e) {\n const columnNumber = e.currentTarget.getAttribute('data-index')\n const sortDirection = $(e.currentTarget).parent().attr('aria-sort')\n let newSortDirection\n if (sortDirection === 'none' || sortDirection === 'descending') {\n newSortDirection = 'ascending'\n } else {\n newSortDirection = 'descending'\n }\n const rows = this.getTableRowsArray()\n const sortedRows = this.sort(rows, columnNumber, newSortDirection)\n this.addRows(sortedRows)\n this.removeButtonStates()\n this.updateButtonState($(e.currentTarget), newSortDirection)\n}\n\nSortableTable.prototype.updateButtonState = function (button, direction) {\n button.parent().attr('aria-sort', direction)\n let message = this.statusMessage\n message = message.replace(/%heading%/, button.text())\n message = message.replace(/%direction%/, this[`${direction}Text`])\n this.status.text(message)\n}\n\nSortableTable.prototype.removeButtonStates = function () {\n this.table.find('thead th').attr('aria-sort', 'none')\n}\n\nSortableTable.prototype.addRows = function (rows) {\n for (let i = 0; i < rows.length; i++) {\n this.body.append(rows[i])\n }\n}\n\nSortableTable.prototype.getTableRowsArray = function () {\n const rows = []\n const trs = this.body.find('tr')\n for (let i = 0; i < trs.length; i++) {\n rows.push(trs[i])\n }\n return rows\n}\n\nSortableTable.prototype.sort = function (rows, columnNumber, sortDirection) {\n const newRows = rows.sort(\n function (rowA, rowB) {\n const tdA = $(rowA).find('td,th').eq(columnNumber)\n const tdB = $(rowB).find('td,th').eq(columnNumber)\n\n const valueA =\n sortDirection === 'ascending'\n ? this.getCellValue(tdA)\n : this.getCellValue(tdB)\n const valueB =\n sortDirection === 'ascending'\n ? this.getCellValue(tdB)\n : this.getCellValue(tdA)\n\n if (typeof valueA === 'string' || typeof valueB === 'string')\n return valueA.toString().localeCompare(valueB.toString())\n return valueA - valueB\n }.bind(this)\n )\n return newRows\n}\n\nSortableTable.prototype.getCellValue = function (cell) {\n const val = cell.attr('data-sort-value') || cell.html()\n\n const valAsNumber = Number(val)\n return isNaN(valAsNumber) ? val : valAsNumber\n}\n"],"names":[],"mappings":"AAEA,SAAA,aAAA,CAAA,MAAA,EAAA;AACA,EAAA,IAAA,CAAA,KAAA,GAAA,CAAA,CAAA,MAAA,CAAA,KAAA;;AAEA,EAAA,IAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,+BAAA,CAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,+BAAA,EAAA,IAAA;;AAEA,EAAA,IAAA,CAAA,YAAA,CAAA,MAAA;AACA,EAAA,IAAA,CAAA,IAAA,GAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,OAAA;AACA,EAAA,IAAA,CAAA,oBAAA;AACA,EAAA,IAAA,CAAA,eAAA;AACA,EAAA,IAAA,CAAA,sBAAA;AACA,EAAA,IAAA,CAAA,KAAA,CAAA,EAAA,CAAA,OAAA,EAAA,WAAA,EAAA,CAAA,CAAA,KAAA,CAAA,IAAA,EAAA,mBAAA,CAAA;AACA;;AAEA,aAAA,CAAA,SAAA,CAAA,YAAA,GAAA,UAAA,MAAA,EAAA;AACA,EAAA,MAAA,GAAA,MAAA,IAAA;AACA,EAAA,IAAA,CAAA,aAAA,GAAA,MAAA,CAAA,aAAA,IAAA;AACA,EAAA,IAAA,CAAA,aAAA,GAAA,MAAA,CAAA,aAAA,IAAA;AACA,EAAA,IAAA,CAAA,cAAA,GAAA,MAAA,CAAA,cAAA,IAAA;AACA;;AAEA,aAAA,CAAA,SAAA,CAAA,oBAAA,GAAA,YAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,CAAA,KAAA,CAAA,IAAA,CAAA,UAAA;AACA,EAAA,IAAA;AACA,EAAA,KAAA,IAAA,CAAA,GAAA,CAAA,EAAA,CAAA,GAAA,QAAA,CAAA,MAAA,EAAA,CAAA,EAAA,EAAA;AACA,I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,IAAA,CAAA,YAAA,CAAA,GAAA;AACA,YAAA,IAAA,CAAA,YAAA,CAAA,GAAA;;AAEA,MAAA,IAAA,OAAA,MAAA,KAAA,QAAA,IAAA,OAAA,MAAA,KAAA,QAAA;AACA,QAAA,OAAA,MAAA,CAAA,QAAA,EAAA,CAAA,aAAA,CAAA,MAAA,CAAA,QAAA,EAAA;AACA,MAAA,OAAA,MAAA,GAAA;AACA,KAAA,CAAA,IAAA,CAAA,IAAA;AACA;AACA,EAAA,OAAA;AACA;;AAEA,aAAA,CAAA,SAAA,CAAA,YAAA,GAAA,UAAA,IAAA,EAAA;AACA,EAAA,MAAA,GAAA,GAAA,IAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,IAAA,IAAA,CAAA,IAAA;;AAEA,EAAA,MAAA,WAAA,GAAA,MAAA,CAAA,GAAA;AACA,EAAA,OAAA,KAAA,CAAA,WAAA,CAAA,GAAA,GAAA,GAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"sortable-table.mjs","sources":["../../../../src/moj/components/sortable-table/sortable-table.mjs"],"sourcesContent":["import { ConfigurableComponent } from 'govuk-frontend'\n\n/**\n * @augments {ConfigurableComponent<SortableTableConfig>}\n */\nexport class SortableTable extends ConfigurableComponent {\n /**\n * @param {Element | null} $root - HTML element to use for sortable table\n * @param {SortableTableConfig} [config] - Sortable table config\n */\n constructor($root, config = {}) {\n super($root, config)\n\n const $head = $root?.querySelector('thead')\n const $body = $root?.querySelector('tbody')\n\n if (!$head || !$body) {\n return this\n }\n\n this.$head = $head\n this.$body = $body\n\n this.$headings = this.$head\n ? Array.from(this.$head.querySelectorAll('th'))\n : []\n\n this.createHeadingButtons()\n this.createStatusBox()\n this.initialiseSortedColumn()\n\n this.$head.addEventListener('click', this.onSortButtonClick.bind(this))\n }\n\n createHeadingButtons() {\n for (const $heading of this.$headings) {\n if ($heading.hasAttribute('aria-sort')) {\n this.createHeadingButton($heading)\n }\n }\n }\n\n /**\n * @param {HTMLTableCellElement} $heading\n */\n createHeadingButton($heading) {\n const index = this.$headings.indexOf($heading)\n const $button = document.createElement('button')\n\n $button.setAttribute('type', 'button')\n $button.setAttribute('data-index', `${index}`)\n $button.textContent = $heading.textContent\n\n $heading.textContent = ''\n $heading.appendChild($button)\n }\n\n createStatusBox() {\n this.$status = document.createElement('div')\n\n this.$status.setAttribute('aria-atomic', 'true')\n this.$status.setAttribute('aria-live', 'polite')\n this.$status.setAttribute('class', 'govuk-visually-hidden')\n this.$status.setAttribute('role', 'status')\n\n this.$root.insertAdjacentElement('afterend', this.$status)\n }\n\n initialiseSortedColumn() {\n const $rows = this.getTableRowsArray()\n\n const $heading = this.$root.querySelector('th[aria-sort]')\n const $sortButton = $heading?.querySelector('button')\n const sortDirection = $heading?.getAttribute('aria-sort')\n\n const columnNumber = Number.parseInt(\n $sortButton?.getAttribute('data-index') ?? '0',\n 10\n )\n\n if (\n !$heading ||\n !$sortButton ||\n !(sortDirection === 'ascending' || sortDirection === 'descending')\n ) {\n return\n }\n\n const $sortedRows = this.sort($rows, columnNumber, sortDirection)\n this.addRows($sortedRows)\n }\n\n /**\n * @param {MouseEvent} event - Click event\n */\n onSortButtonClick(event) {\n const $button = event.target\n\n if (\n !$button ||\n !($button instanceof HTMLButtonElement) ||\n !$button.parentElement\n ) {\n return\n }\n\n const $heading = $button.parentElement\n const sortDirection = $heading.getAttribute('aria-sort')\n\n const columnNumber = Number.parseInt(\n $button?.getAttribute('data-index') ?? '0',\n 10\n )\n\n const newSortDirection =\n sortDirection === 'none' || sortDirection === 'descending'\n ? 'ascending'\n : 'descending'\n\n const $rows = this.getTableRowsArray()\n const $sortedRows = this.sort($rows, columnNumber, newSortDirection)\n\n this.addRows($sortedRows)\n this.removeButtonStates()\n this.updateButtonState($button, newSortDirection)\n }\n\n /**\n * @param {HTMLButtonElement} $button\n * @param {string} direction\n */\n updateButtonState($button, direction) {\n if (!(direction === 'ascending' || direction === 'descending')) {\n return\n }\n\n $button.parentElement.setAttribute('aria-sort', direction)\n let message = this.config.statusMessage\n message = message.replace(/%heading%/, $button.textContent)\n message = message.replace(/%direction%/, this.config[`${direction}Text`])\n this.$status.textContent = message\n }\n\n removeButtonStates() {\n for (const $heading of this.$headings) {\n $heading.setAttribute('aria-sort', 'none')\n }\n }\n\n /**\n * @param {HTMLTableRowElement[]} $rows\n */\n addRows($rows) {\n for (const $row of $rows) {\n this.$body.append($row)\n }\n }\n\n getTableRowsArray() {\n return Array.from(this.$body.querySelectorAll('tr'))\n }\n\n /**\n * @param {HTMLTableRowElement[]} $rows\n * @param {number} columnNumber\n * @param {string} sortDirection\n */\n sort($rows, columnNumber, sortDirection) {\n return $rows.sort(($rowA, $rowB) => {\n const $tdA = $rowA.querySelectorAll('td, th')[columnNumber]\n const $tdB = $rowB.querySelectorAll('td, th')[columnNumber]\n\n if (\n !$tdA ||\n !$tdB ||\n !($tdA instanceof HTMLElement) ||\n !($tdB instanceof HTMLElement)\n ) {\n return 0\n }\n\n const valueA =\n sortDirection === 'ascending'\n ? this.getCellValue($tdA)\n : this.getCellValue($tdB)\n\n const valueB =\n sortDirection === 'ascending'\n ? this.getCellValue($tdB)\n : this.getCellValue($tdA)\n\n return !(typeof valueA === 'number' && typeof valueB === 'number')\n ? valueA.toString().localeCompare(valueB.toString())\n : valueA - valueB\n })\n }\n\n /**\n * @param {HTMLElement} $cell\n */\n getCellValue($cell) {\n const val = $cell.getAttribute('data-sort-value') || $cell.innerHTML\n const valAsNumber = Number(val)\n\n return Number.isFinite(valAsNumber)\n ? valAsNumber // Exclude invalid numbers, infinity etc\n : val\n }\n\n /**\n * Name for the component used when initialising using data-module attributes.\n */\n static moduleName = 'moj-sortable-table'\n\n /**\n * Sortable table config\n *\n * @type {SortableTableConfig}\n */\n static defaults = Object.freeze({\n statusMessage: 'Sort by %heading% (%direction%)',\n ascendingText: 'ascending',\n descendingText: 'descending'\n })\n\n /**\n * Sortable table config schema\n *\n * @satisfies {Schema<SortableTableConfig>}\n */\n static schema = Object.freeze(\n /** @type {const} */ ({\n properties: {\n statusMessage: { type: 'string' },\n ascendingText: { type: 'string' },\n descendingText: { type: 'string' }\n }\n })\n )\n}\n\n/**\n * Sortable table config\n *\n * @typedef {object} SortableTableConfig\n * @property {string} [statusMessage] - Status message\n * @property {string} [ascendingText] - Ascending text\n * @property {string} [descendingText] - Descending text\n */\n\n/**\n * @import { Schema } from 'govuk-frontend/dist/govuk/common/configuration.mjs'\n */\n"],"names":["SortableTable","ConfigurableComponent","constructor","$root","config","$head","querySelector","$body","$headings","Array","from","querySelectorAll","createHeadingButtons","createStatusBox","initialiseSortedColumn","addEventListener","onSortButtonClick","bind","$heading","hasAttribute","createHeadingButton","index","indexOf","$button","document","createElement","setAttribute","textContent","appendChild","$status","insertAdjacentElement","_$sortButton$getAttri","$rows","getTableRowsArray","$sortButton","sortDirection","getAttribute","columnNumber","Number","parseInt","$sortedRows","sort","addRows","event","_$button$getAttribute","target","HTMLButtonElement","parentElement","newSortDirection","removeButtonStates","updateButtonState","direction","message","statusMessage","replace","$row","append","$rowA","$rowB","$tdA","$tdB","HTMLElement","valueA","getCellValue","valueB","toString","localeCompare","$cell","val","innerHTML","valAsNumber","isFinite","moduleName","defaults","Object","freeze","ascendingText","descendingText","schema","properties","type"],"mappings":";;AAEA;AACA;AACA;AACO,MAAMA,aAAa,SAASC,qBAAqB,CAAC;AACvD;AACF;AACA;AACA;AACEC,EAAAA,WAAWA,CAACC,KAAK,EAAEC,MAAM,GAAG,EAAE,EAAE;AAC9B,IAAA,KAAK,CAACD,KAAK,EAAEC,MAAM,CAAC;IAEpB,MAAMC,KAAK,GAAGF,KAAK,IAAA,IAAA,GAAA,MAAA,GAALA,KAAK,CAAEG,aAAa,CAAC,OAAO,CAAC;IAC3C,MAAMC,KAAK,GAAGJ,KAAK,IAAA,IAAA,GAAA,MAAA,GAALA,KAAK,CAAEG,aAAa,CAAC,OAAO,CAAC;AAE3C,IAAA,IAAI,CAACD,KAAK,IAAI,CAACE,KAAK,EAAE;AACpB,MA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Aa,EAAE,iCAAiC;AAChDuB,EAAAA,aAAa,EAAE,WAAW;AAC1BC,EAAAA,cAAc,EAAE;AAClB,CAAC,CAAC;AAEF;AACF;AACA;AACA;AACA;AAhOa7E,aAAa,CAiOjB8E,MAAM,GAAGJ,MAAM,CAACC,MAAM,qBACL;AACpBI,EAAAA,UAAU,EAAE;AACV1B,IAAAA,aAAa,EAAE;AAAE2B,MAAAA,IAAI,EAAE;KAAU;AACjCJ,IAAAA,aAAa,EAAE;AAAEI,MAAAA,IAAI,EAAE;KAAU;AACjCH,IAAAA,cAAc,EAAE;AAAEG,MAAAA,IAAI,EAAE;AAAS;AACnC;AACF,CACF,CAAC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/moj/components/sub-navigation/_sub-navigation.scss"],"names":[],"mappings":"AAAA,uCAAuC;;AAEvC;;+EAE+E;;AAE/E;EACE,+BAA+B;AACjC;;AAEA;EACE,SAAS;EACT,UAAU;EACV,YAAY,EAAE,+DAA+D;EAC7E,gBAAgB;;EAEhB;IACE,WAAW;IACX,+CAA+C;EACjD;AACF;;AAEA;EACE,cAAc;EACd,gBAAgB;EAChB,+CAA+C;EAC/C,uBAAuB;;EAEvB;IACE,gBAAgB;EAClB;;EAEA;IACE,qBAAqB;IACrB,aAAa;IACb,8BAA8B;IAC9B,gBAAgB;EAClB;AACF;;AAEA;EACE,cAAc;EACd,kBAAkB;EAClB,iBAAiB;EACjB,oBAAoB;EACpB,8BAA8B;EAC9B,0BAA0B;EAC1B,iCAAiC;;EAEjC;IACE,eAAe;EACjB;;EAEA;;;;IAIE,qBAAqB;EACvB;;EAEA;;IAEE,yBAAyB;EAC3B;;EAEA;IACE,+BAA+B;EACjC;;EAEA;IACE,kBAAkB,EAAE,0CAA0C;IAC9D,4BAA4B,EAAE,gDAAgD;IAC9E,gBAAgB;EAClB;;EAEA;IACE,WAAW;IACX,cAAc;IACd,kBAAkB;IAClB,SAAS;IACT,OAAO;IACP,UAAU;IACV,YAAY;IACZ,uCAAuC;;IAEvC;MACE,WAAW;MACX,WAAW;IACb;EACF;AACF;;AAEA;EACE,kBAAkB;EAClB,gCAAgC;EAChC,qBAAqB;;EAErB;IACE,WAAW;IACX,cAAc;IACd,kBAAkB;IAClB,SAAS;IACT,OAAO;IACP,UAAU;IACV,YAAY;IACZ,oCAAoC;;IAEpC;MACE,WAAW;MACX,WAAW;IACb;EACF;;EAEA;IACE,+BAA+B;EACjC;;EAEA;IACE,uCAAuC;EACzC;AACF","file":"_sub-navigation.scss","sourcesContent":["@use \"../../vendor/govuk-frontend\" as *;\n\n/* ==========================================================================\n #SECONDARY NAV\n ========================================================================== */\n\n.moj-sub-navigation {\n margin-bottom: govuk-spacing(7);\n}\n\n.moj-sub-navigation__list {\n margin: 0;\n padding: 0;\n font-size: 0; // Removes white space when using inline-block on child element.\n list-style: none;\n\n @include govuk-media-query($from: tablet) {\n width: 100%;\n box-shadow: inset 0 -1px 0 $govuk-border-colour;\n }\n}\n\n.moj-sub-navigation__item {\n display: block;\n margin-top: -1px;\n box-shadow: inset 0 -1px 0 $govuk-border-colour;\n @include govuk-font(19);\n\n &:last-child {\n box-shadow: none;\n }\n\n @include govuk-media-query($from: tablet) {\n display: inline-block;\n margin-top: 0;\n margin-right: govuk-spacing(4);\n box-shadow: none;\n }\n}\n\n.moj-sub-navigation__link {\n display: block;\n position: relative;\n padding-top: 12px;\n padding-bottom: 12px;\n padding-left: govuk-spacing(3);\n @include govuk-link-common;\n @include govuk-link-style-default;\n\n @include govuk-media-query($from: tablet) {\n padding-left: 0;\n }\n\n &:link,\n &:visited,\n &:hover,\n &:active {\n text-decoration: none;\n }\n\n &:link,\n &:visited {\n color: $govuk-link-colour;\n }\n\n &:hover {\n color: $govuk-link-hover-colour;\n }\n\n &:focus {\n position: relative; // Ensure focus sits above everything else.\n color: govuk-colour(\"black\"); // Focus colour on yellow should really be black.\n box-shadow: none;\n }\n\n &:focus::before {\n content: \"\";\n display: block;\n position: absolute;\n bottom: 0;\n left: 0;\n width: 5px;\n height: 100%;\n background-color: govuk-colour(\"black\");\n\n @include govuk-media-query($from: tablet) {\n width: 100%;\n height: 5px;\n }\n }\n}\n\n.moj-sub-navigation__link[aria-current=\"page\"] {\n position: relative;\n color: $govuk-link-active-colour;\n text-decoration: none;\n\n &::before {\n content: \"\";\n display: block;\n position: absolute;\n bottom: 0;\n left: 0;\n width: 5px;\n height: 100%;\n background-color: $govuk-link-colour;\n\n @include govuk-media-query($from: tablet) {\n width: 100%;\n height: 5px;\n }\n }\n\n &:hover {\n color: $govuk-link-hover-colour;\n }\n\n &:focus::before {\n background-color: govuk-colour(\"black\");\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/moj/components/tag/_tag.scss"],"names":[],"mappings":"AAAA,uCAAuC;;AAEvC;;+EAE+E;;AAE/E;EACE,qCAAqC;EACrC,4BAA4B;EAC5B,qCAAqC;;EAErC;IACE,wCAAwC;IACxC,4BAA4B;IAC5B,wCAAwC;EAC1C;;EAEA;IACE,+CAA+C;IAC/C,4BAA4B;IAC5B,+CAA+C;EACjD;;EAEA;;IAEE,qCAAqC;IACrC,4BAA4B;IAC5B,qCAAqC;EACvC;;EAEA;;IAEE,uCAAuC;IACvC,4BAA4B;IAC5B,uCAAuC;EACzC;;EAEA;;IAEE,sCAAsC;IACtC,4BAA4B;IAC5B,sCAAsC;EACxC;;EAEA;IACE,uCAAuC;IACvC,4BAA4B;IAC5B,uCAAuC;EACzC;;EAEA;IACE,2CAA2C;IAC3C,4BAA4B;IAC5B,2CAA2C;EAC7C;AACF","file":"_tag.scss","sourcesContent":["@use \"../../vendor/govuk-frontend\" as *;\n\n/* ==========================================================================\n #TAG\n ========================================================================== */\n\n.moj-tag {\n border: 2px solid $govuk-brand-colour;\n color: govuk-colour(\"white\");\n background-color: $govuk-brand-colour;\n\n &--purple {\n border: 2px solid govuk-colour(\"purple\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"purple\");\n }\n\n &--bright-purple {\n border: 2px solid govuk-colour(\"bright-purple\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"bright-purple\");\n }\n\n &--red,\n &--error {\n border: 2px solid govuk-colour(\"red\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"red\");\n }\n\n &--green,\n &--success {\n border: 2px solid govuk-colour(\"green\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"green\");\n }\n\n &--blue,\n &--information {\n border: 2px solid govuk-colour(\"blue\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"blue\");\n }\n\n &--black {\n border: 2px solid govuk-colour(\"black\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"black\");\n }\n\n &--grey {\n border: 2px solid govuk-colour(\"dark-grey\");\n color: govuk-colour(\"white\");\n background-color: govuk-colour(\"dark-grey\");\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/moj/components/task-list/_task-list.scss"],"names":[],"mappings":"AAAA,uCAAuC;;AAEvC;;+EAE+E;;AAE/E;EACE,aAAa;EACb,gBAAgB;EAChB,eAAe;EACf,qBAAqB;EACrB;IACE,gBAAgB;EAClB;AACF;;AAEA;EACE,cAAc;EACd,6CAA6C;AAC/C;;AAEA;EACE,mBAAmB;;EAEnB;IACE,2BAA2B;IAC3B,gBAAgB;EAClB;AACF;;AAEA;EACE,eAAe;EACf,gBAAgB;EAChB,8BAA8B;EAC9B,6CAA6C;EAC7C;IACE,8BAA8B;EAChC;AACF;;AAEA;EACE,sDAAsD;EACtD,2BAA2B;EAC3B,6BAA6B;EAC7B,gCAAgC;EAChC,6CAA6C;EAC7C,uBAAuB;AACzB;;AAEA;EACE,0CAA0C;AAC5C;;AAEA;EACE,cAAc;EACd;IACE,UAAU;IACV,WAAW;EACb;AACF;;AAEA;EACE,4BAA4B;EAC5B,+BAA+B;;EAE/B;IACE,aAAa;IACb,gBAAgB;IAChB,YAAY;EACd;AACF","file":"_task-list.scss","sourcesContent":["@use \"../../vendor/govuk-frontend\" as *;\n\n/* ==========================================================================\n #TASK LIST\n ========================================================================== */\n\n.moj-task-list {\n margin-top: 0;\n margin-bottom: 0;\n padding-left: 0;\n list-style-type: none;\n @include govuk-media-query($from: tablet) {\n min-width: 550px;\n }\n}\n\n.moj-task-list__section {\n display: table;\n @include govuk-font($size: 24, $weight: bold);\n}\n\n.moj-task-list__section-number {\n display: table-cell;\n\n @include govuk-media-query($from: tablet) {\n min-width: govuk-spacing(6);\n padding-right: 0;\n }\n}\n\n.moj-task-list__items {\n padding-left: 0;\n list-style: none;\n @include govuk-font($size: 19);\n @include govuk-responsive-margin(9, \"bottom\");\n @include govuk-media-query($from: tablet) {\n padding-left: govuk-spacing(6);\n }\n}\n\n.moj-task-list__item {\n // stylelint-disable-next-line declaration-no-important\n margin-bottom: 0 !important;\n padding-top: govuk-spacing(2);\n padding-bottom: govuk-spacing(2);\n border-bottom: 1px solid $govuk-border-colour;\n @include govuk-clearfix;\n}\n\n.moj-task-list__item:first-child {\n border-top: 1px solid $govuk-border-colour;\n}\n\n.moj-task-list__task-name {\n display: block;\n @include govuk-media-query($from: 450px) {\n width: 75%;\n float: left;\n }\n}\n\n.moj-task-list__task-completed {\n margin-top: govuk-spacing(2);\n margin-bottom: govuk-spacing(1);\n\n @include govuk-media-query($from: 450px) {\n margin-top: 0;\n margin-bottom: 0;\n float: right;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/moj/components/ticket-panel/_ticket-panel.scss"],"names":[],"mappings":"AAAA,uCAAuC;;AAEvC;;+EAE+E;;AAE/E;EACE,cAAc;EACd,8BAA8B;EAC9B,eAAe;;EAEf;IACE;MACE,aAAa;MACb,iBAAiB;IACnB;EACF;;EAEA;IACE;MACE,6BAA6B;IAC/B;EACF;;EAEA;IACE,+BAA+B;EACjC;;EAEA;IACE,cAAc;IACd,kBAAkB;IAClB,+BAA+B;IAC/B,yBAAyB;IACzB,kCAAkC;IAClC,4CAA4C;IAC5C,YAAY;;IAEZ;MACE,uCAAuC;IACzC;;IAEA;MACE,uCAAuC;IACzC;;IAEA;MACE,sCAAsC;IACxC;;IAEA;MACE,yCAAyC;IAC3C;;IAEA;MACE,wCAAwC;IAC1C;;IAEA;MACE,yCAAyC;IAC3C;;IAEA;MACE,yCAAyC;IAC3C;EACF;AACF","file":"_ticket-panel.scss","sourcesContent":["@use \"../../vendor/govuk-frontend\" as *;\n\n/* ==========================================================================\n #TICKET PANEL\n ========================================================================== */\n\n.moj-ticket-panel {\n display: block;\n margin-right: govuk-spacing(0);\n flex-wrap: wrap;\n\n &--inline {\n @include govuk-media-query($from: desktop) {\n display: flex;\n flex-wrap: nowrap;\n }\n }\n\n &--inline > * + * {\n @include govuk-media-query($from: desktop) {\n margin-left: govuk-spacing(3);\n }\n }\n\n &__content *:last-child {\n margin-bottom: govuk-spacing(0);\n }\n\n &__content {\n display: block;\n position: relative;\n margin-bottom: govuk-spacing(3);\n padding: govuk-spacing(4);\n border-left: 4px solid transparent;\n background-color: govuk-colour(\"light-grey\");\n flex-grow: 1;\n\n &--grey {\n border-left-color: $govuk-border-colour;\n }\n\n &--blue {\n border-left-color: govuk-colour(\"blue\");\n }\n\n &--red {\n border-left-color: govuk-colour(\"red\");\n }\n\n &--yellow {\n border-left-color: govuk-colour(\"yellow\");\n }\n\n &--green {\n border-left-color: govuk-colour(\"green\");\n }\n\n &--purple {\n border-left-color: govuk-colour(\"purple\");\n }\n\n &--orange {\n border-left-color: govuk-colour(\"orange\");\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/moj/components/timeline/_timeline.scss"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,uCAAuC;;AAEvC;;+EAE+E;;AAE/E;EACE,kBAAkB;EAClB,+BAA+B;EAC/B,gBAAgB;;EAEhB;IACE,WAAW;IACX,kBAAkB;IAClB,qBAAqB;IACrB,OAAO;IACP,UAAU;IACV,YAAY;IACZ,qCAAqC;EACvC;AACF;;AAEA;EACE,gBAAgB;;EAEhB;IACE,yBAAyB;EAC3B;AACF;;AAEA;EACE,kBAAkB;EAClB,gCAAgC;EAChC,8BAA8B;;EAE9B;IACE,WAAW;IACX,kBAAkB;IAClB,qBAAqB;IACrB,OAAO;IACP,WAAW;IACX,WAAW;IACX,qCAAqC;EACvC;AACF;;AAEA;EACE,eAAe;EACf,6CAA6C;AAC/C;;AAEA;EACE,eAAe;EACf,SAAS;EACT,mCAAmC;EACnC,8BAA8B;AAChC;;AAEA;EACE,4BAA4B;EAC5B,gBAAgB;EAChB,8BAA8B;AAChC;;AAEA;EACE,4BAA4B;EAC5B,8BAA8B;AAChC;;AAEA;;+EAE+E;;AAE/E;EACE,gBAAgB;EAChB,eAAe;EACf,gBAAgB;AAClB;;AAEA;EACE,+BAA+B;;EAE/B;IACE,gBAAgB;EAClB;AACF;;AAEA;EACE,eAAe;EACf,iBAAiB;EACjB,WAAW;EACX,kBAAkB;;EAElB;IACE,cAAc;EAChB;AACF;;AAEA;EACE,8BAA8B;EAC9B,2DAA2D;EAC3D,4BAA4B;EAC5B,0BAA0B;EAC1B,0BAA0B;;EAE1B;IACE,4BAA4B,EAAE,gDAAgD;EAChF;AACF","file":"_timeline.scss","sourcesContent":["@use \"../../settings/assets\" as *;\n@use \"../../vendor/govuk-frontend\" as *;\n\n/* ==========================================================================\n #TIMELINE\n ========================================================================== */\n\n.moj-timeline {\n position: relative;\n margin-bottom: govuk-spacing(4);\n overflow: hidden;\n\n &::before {\n content: \"\";\n position: absolute;\n top: govuk-spacing(2);\n left: 0;\n width: 5px;\n height: 100%;\n background-color: $govuk-brand-colour;\n }\n}\n\n.moj-timeline--full {\n margin-bottom: 0;\n\n &::before {\n height: calc(100% - 75px);\n }\n}\n\n.moj-timeline__item {\n position: relative;\n padding-bottom: govuk-spacing(6);\n padding-left: govuk-spacing(4);\n\n &::before {\n content: \"\";\n position: absolute;\n top: govuk-spacing(2);\n left: 0;\n width: 15px;\n height: 5px;\n background-color: $govuk-brand-colour;\n }\n}\n\n.moj-timeline__title {\n display: inline;\n @include govuk-font($size: 19, $weight: bold);\n}\n\n.moj-timeline__byline {\n display: inline;\n margin: 0;\n color: $govuk-secondary-text-colour;\n @include govuk-font($size: 19);\n}\n\n.moj-timeline__date {\n margin-top: govuk-spacing(1);\n margin-bottom: 0;\n @include govuk-font($size: 16);\n}\n\n.moj-timeline__description {\n margin-top: govuk-spacing(4);\n @include govuk-font($size: 19);\n}\n\n/* ==========================================================================\n #TIMELINE DOCUMENT STYLES – FOR BACKWARDS COMPATIBILITY\n ========================================================================== */\n\n.moj-timeline__documents {\n margin-bottom: 0;\n padding-left: 0;\n list-style: none;\n}\n\n.moj-timeline__document-item {\n margin-bottom: govuk-spacing(1);\n\n &:last-child {\n margin-bottom: 0;\n }\n}\n\n.moj-timeline__document-icon {\n margin-top: 4px;\n margin-right: 4px;\n float: left;\n fill: currentcolor;\n\n @media screen and (forced-colors: active) {\n fill: linkText;\n }\n}\n\n.moj-timeline__document-link {\n padding-left: govuk-spacing(5);\n background-image: url(#{$moj-images-path}icon-document.svg);\n background-repeat: no-repeat;\n background-position: 0 50%;\n background-size: 20px 16px;\n\n &:focus {\n color: govuk-colour(\"black\"); // Focus colour on yellow should really be black.\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/moj/core/_all.scss"],"names":[],"mappings":"AAAA,kCAAkC","file":"_all.scss","sourcesContent":["@forward \"moj-frontend-properties\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/moj/core/_moj-frontend-properties.scss"],"names":[],"mappings":"AAAA;EACE,wEAAwE;EACxE,yCAAyC;EACzC,+BAAqC;AACvC","file":"_moj-frontend-properties.scss","sourcesContent":[":root {\n // This variable is automatically overwritten during builds and releases.\n // It doesn't need to be updated manually.\n --moj-frontend-version: \"development\";\n}\n"]}
|
package/moj/filters/all.js
CHANGED
|
@@ -2,34 +2,41 @@ const moment = require('moment')
|
|
|
2
2
|
|
|
3
3
|
module.exports = function () {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* gov.uk core filters by creating filter methods of the same name.
|
|
5
|
+
* Date filter for use in Nunjucks
|
|
6
|
+
* Outputs: 01/01/1970
|
|
8
7
|
*
|
|
9
|
-
* @
|
|
8
|
+
* @example
|
|
9
|
+
* ```njk
|
|
10
|
+
* {{ params.date | date("DD/MM/YYYY") }}
|
|
11
|
+
* ```
|
|
12
|
+
* @param {MomentInput} timestamp
|
|
13
|
+
* @param {string} format
|
|
10
14
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/* ------------------------------------------------------------------
|
|
14
|
-
date filter for use in Nunjucks
|
|
15
|
-
example: {{ params.date | date("DD/MM/YYYY") }}
|
|
16
|
-
outputs: 01/01/1970
|
|
17
|
-
------------------------------------------------------------------ */
|
|
18
|
-
filters.date = function (timestamp, format) {
|
|
15
|
+
function date(timestamp, format) {
|
|
19
16
|
return moment(timestamp).format(format)
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
/* ------------------------------------------------------------------
|
|
23
20
|
utility functions for use in mojDate function/filter
|
|
24
21
|
------------------------------------------------------------------ */
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {MomentInput} timestamp
|
|
25
|
+
*/
|
|
25
26
|
function govDate(timestamp) {
|
|
26
27
|
return moment(timestamp).format('D MMMM YYYY')
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @param {MomentInput} timestamp
|
|
32
|
+
*/
|
|
29
33
|
function govShortDate(timestamp) {
|
|
30
34
|
return moment(timestamp).format('D MMM YYYY')
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @param {MomentInput} timestamp
|
|
39
|
+
*/
|
|
33
40
|
function govTime(timestamp) {
|
|
34
41
|
const t = moment(timestamp)
|
|
35
42
|
if (t.minutes() > 0) {
|
|
@@ -38,12 +45,18 @@ module.exports = function () {
|
|
|
38
45
|
return t.format('ha')
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Standard dates for use in Nunjucks
|
|
50
|
+
* Outputs: 1 Jan 1970 at 1:32pm
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```njk
|
|
54
|
+
* {{ params.date | mojDate("datetime") }}
|
|
55
|
+
* ```
|
|
56
|
+
* @param {MomentInput} timestamp
|
|
57
|
+
* @param {'datetime' | 'shortdatetime' | 'date' | 'shortdate' | 'time'} [type]
|
|
58
|
+
*/
|
|
59
|
+
function mojDate(timestamp, type) {
|
|
47
60
|
switch (type) {
|
|
48
61
|
case 'datetime':
|
|
49
62
|
return `${govDate(timestamp)} at ${govTime(timestamp)}`
|
|
@@ -60,8 +73,17 @@ module.exports = function () {
|
|
|
60
73
|
}
|
|
61
74
|
}
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Returns an object used to store the methods registered as a
|
|
78
|
+
* 'filter' (of the same name) within nunjucks. You can override
|
|
79
|
+
* gov.uk core filters by creating filter methods of the same name.
|
|
80
|
+
*/
|
|
81
|
+
return {
|
|
82
|
+
date,
|
|
83
|
+
mojDate
|
|
84
|
+
}
|
|
67
85
|
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @import { MomentInput } from 'moment'
|
|
89
|
+
*/
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
// @ts-expect-error - No types available
|
|
1
2
|
const { addFilter } = require('govuk-prototype-kit').views
|
|
2
3
|
|
|
3
4
|
const getAllFilters = require('./all')
|
|
4
5
|
|
|
5
6
|
const allFilters = getAllFilters()
|
|
6
7
|
|
|
7
|
-
Object.
|
|
8
|
-
addFilter(name,
|
|
9
|
-
}
|
|
8
|
+
for (const [name, filter] of Object.entries(allFilters)) {
|
|
9
|
+
addFilter(name, filter)
|
|
10
|
+
}
|
package/moj/helpers/_all.scss
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/moj/helpers/_all.scss"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,gBAAgB","file":"_all.scss","sourcesContent":["@forward \"hidden\";\n@forward \"links\";\n"]}
|
package/moj/helpers/_hidden.scss
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/moj/helpers/_hidden.scss"],"names":[],"mappings":"AAAA;EACE,aAAa;AACf","file":"_hidden.scss","sourcesContent":["@mixin moj-hidden() {\n display: none;\n}\n"]}
|
package/moj/helpers/_links.scss
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/moj/helpers/_links.scss"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,+BAA+B;AAC/B,oCAAoC;;AAEpC;EACE;;IAEE,+BAA+B;EACjC;;EAEA;IACE,8DAA8D;EAChE;;EAEA;IACE,0BAA0B;EAC5B;;EAEA;IACE,+BAA+B;EACjC;AACF","file":"_links.scss","sourcesContent":["@use \"sass:color\";\n@use \"../settings/colours\" as *;\n@use \"../vendor/govuk-frontend\" as *;\n\n@mixin moj-link-style-warning {\n &:link,\n &:visited {\n color: $moj-warning-link-colour;\n }\n\n &:hover {\n color: color.scale($moj-warning-link-colour, $lightness: -30%);\n }\n\n &:active {\n color: $moj-warning-colour;\n }\n\n &:focus {\n color: $govuk-focus-text-colour;\n }\n}\n"]}
|