@ons/design-system 74.0.0-next.5 → 74.0.0-next.7
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/README.md +2 -0
- package/components/chart/_chart.scss +0 -9
- package/components/chart/_macro.njk +96 -128
- package/components/chart/_macro.spec.js +43 -28
- package/components/chart/example-area-chart-with-axis-min-and-max-values.njk +6 -3
- package/components/chart/example-area-chart.njk +6 -3
- package/components/chart/example-bar-chart-with-annotations.njk +6 -3
- package/components/chart/example-bar-chart-with-axis-min-and-max-values.njk +6 -3
- package/components/chart/example-bar-chart-with-point-range-and-reference-line-annotations.njk +6 -3
- package/components/chart/example-bar-chart.njk +6 -3
- package/components/chart/example-bar-with-confidence-levels.njk +6 -3
- package/components/chart/example-clustered-bar-chart.njk +6 -3
- package/components/chart/example-clustered-column-chart.njk +6 -3
- package/components/chart/example-column-chart-with-annotations.njk +6 -3
- package/components/chart/example-column-chart-with-axis-min-and-max-values.njk +6 -3
- package/components/chart/example-column-chart-with-custom-reference-line-value.njk +6 -3
- package/components/chart/example-column-chart-with-range-annotations.njk +6 -3
- package/components/chart/example-column-chart-with-reference-line-annotations.njk +6 -3
- package/components/chart/example-column-chart.njk +6 -3
- package/components/chart/example-column-with-confidence-levels.njk +6 -3
- package/components/chart/example-column-with-line-chart.njk +6 -3
- package/components/chart/example-iframe-chart.njk +6 -3
- package/components/chart/example-line-chart-with-annotations.njk +6 -3
- package/components/chart/example-line-chart-with-axis-min-and-max-values.njk +6 -3
- package/components/chart/example-line-chart-with-custom-reference-line-value.njk +6 -3
- package/components/chart/example-line-chart-with-label-format.njk +6 -3
- package/components/chart/example-line-chart-with-markers.njk +6 -3
- package/components/chart/example-line-chart-with-range-annotations-inside.njk +6 -3
- package/components/chart/example-line-chart-with-range-annotations-outside-left-right.njk +6 -3
- package/components/chart/example-line-chart-with-range-annotations-outside-top-bottom.njk +6 -3
- package/components/chart/example-line-chart-with-reference-line-annotations.njk +6 -3
- package/components/chart/example-line-chart.njk +6 -3
- package/components/chart/example-scatter-chart-with-axis-min-and-max-values.njk +6 -3
- package/components/chart/example-scatter-chart.njk +6 -3
- package/components/chart/example-stacked-bar-chart.njk +6 -3
- package/components/chart/example-stacked-column-chart.njk +6 -3
- package/components/document-list/_macro.njk +2 -2
- package/components/document-list/_macro.spec.js +55 -0
- package/components/featured-article/_macro.njk +3 -37
- package/components/featured-article/example-featured-article-with-chart.njk +19 -14
- package/components/featured-article/example-featured-article-with-image.njk +12 -7
- package/components/featured-article/featured-article.scss +1 -1
- package/components/featured-article/macro.spec.js +44 -67
- package/components/figure/_figure.scss +31 -0
- package/components/figure/_macro.njk +98 -0
- package/components/figure/_macro.spec.js +520 -0
- package/components/figure/example-figure-heading-level-2.njk +34 -0
- package/components/figure/example-figure-with-div.njk +29 -0
- package/components/figure/example-figure-without-footer.njk +12 -0
- package/components/figure/example-figure-without-header.njk +24 -0
- package/components/figure/example-figure.njk +34 -0
- package/components/header/_header.scss +1 -3
- package/components/header/_macro.njk +1 -1
- package/components/image/_image.scss +0 -7
- package/components/image/_macro.njk +25 -14
- package/components/image/_macro.spec.js +122 -7
- package/components/image/example-image-with-figure-fields.njk +25 -0
- package/components/list/_macro.njk +1 -0
- package/components/list/_macro.spec.js +16 -0
- package/components/table/_macro.njk +138 -111
- package/components/table/_macro.spec.js +175 -16
- package/components/table/_table.scss +6 -1
- package/components/table/example-table-basic-no-caption.njk +46 -0
- package/components/table/example-table-basic-visually-hidden-caption.njk +47 -0
- package/components/table/example-table-with-figure-fields.njk +86 -0
- package/components/table/table.spec.js +2 -0
- package/components/table-of-contents/_macro.njk +6 -4
- package/components/table-of-contents/_macro.spec.js +43 -3
- package/components/table-of-contents/example-table-of-contents-ordered.njk +64 -0
- package/components/table-of-contents/example-table-of-contents-sticky-full-page-ordered.njk +156 -0
- package/css/main.css +1 -1
- package/favicons/android-chrome-192x192.png +0 -0
- package/favicons/android-chrome-512x512.png +0 -0
- package/favicons/apple-touch-icon.png +0 -0
- package/favicons/favicon-16x16.png +0 -0
- package/favicons/favicon-32x32.png +0 -0
- package/favicons/favicon.ico +0 -0
- package/favicons/maskable_icon.png +0 -0
- package/favicons/opengraph.png +0 -0
- package/favicons/x.png +0 -0
- package/img/large/alison-pritchard-featured.jpg +0 -0
- package/img/large/alison-pritchard.jpg +0 -0
- package/img/large/census-monuments-lights-featured.jpg +0 -0
- package/img/large/census-monuments-lights.jpg +0 -0
- package/img/large/mother-and-daughter-in-ireland.jpg +0 -0
- package/img/large/mum-and-child-healthcare-belfast.jpg +0 -0
- package/img/large/ons-award-winners.jpg +0 -0
- package/img/large/placeholder-card.png +0 -0
- package/img/large/placeholder-news-medium.png +0 -0
- package/img/large/placeholder-news.png +0 -0
- package/img/large/placeholder-portrait.png +0 -0
- package/img/large/students.jpg +0 -0
- package/img/large/woman-in-purple-dress-shirt.jpg +0 -0
- package/img/small/alison-pritchard-featured.jpg +0 -0
- package/img/small/alison-pritchard.jpg +0 -0
- package/img/small/area-chart-screenshot.png +0 -0
- package/img/small/census-monuments-lights-featured.jpg +0 -0
- package/img/small/census-monuments-lights.jpg +0 -0
- package/img/small/line-chart-screenshot.png +0 -0
- package/img/small/mother-and-daughter-in-ireland.jpg +0 -0
- package/img/small/mum-and-child-healthcare-belfast.jpg +0 -0
- package/img/small/ons-award-winners.jpg +0 -0
- package/img/small/placeholder-card.png +0 -0
- package/img/small/placeholder-news-medium.png +0 -0
- package/img/small/placeholder-news.png +0 -0
- package/img/small/placeholder-portrait.png +0 -0
- package/img/small/students.jpg +0 -0
- package/img/small/woman-in-purple-dress-shirt.jpg +0 -0
- package/layout/_template.njk +12 -6
- package/package.json +23 -18
- package/scripts/main.es5.js +3 -3
- package/scripts/main.js +2 -2
- package/scss/base/_global.scss +8 -0
- package/scss/main.scss +1 -0
|
@@ -7,6 +7,7 @@ import { mapAll } from '../../tests/helpers/cheerio';
|
|
|
7
7
|
import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
|
|
8
8
|
|
|
9
9
|
const EXAMPLE_TABLE_MINIMAL = {
|
|
10
|
+
ariaLabel: 'Example table',
|
|
10
11
|
ths: [],
|
|
11
12
|
trs: [],
|
|
12
13
|
};
|
|
@@ -32,7 +33,7 @@ describe('macro: table', () => {
|
|
|
32
33
|
expect(results).toHaveNoViolations();
|
|
33
34
|
});
|
|
34
35
|
|
|
35
|
-
it('has the provided `id`
|
|
36
|
+
it('has the provided `id` on the wrapping element', () => {
|
|
36
37
|
const $ = cheerio.load(
|
|
37
38
|
renderComponent('table', {
|
|
38
39
|
...EXAMPLE_TABLE,
|
|
@@ -40,7 +41,7 @@ describe('macro: table', () => {
|
|
|
40
41
|
}),
|
|
41
42
|
);
|
|
42
43
|
|
|
43
|
-
expect($('.ons-
|
|
44
|
+
expect($('.ons-figure').attr('id')).toBe('example-table');
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
it('has additionally provided style classes', () => {
|
|
@@ -67,27 +68,15 @@ describe('macro: table', () => {
|
|
|
67
68
|
expect($('.ons-table-scrollable__content').length).toBe(1);
|
|
68
69
|
});
|
|
69
70
|
|
|
70
|
-
it('renders
|
|
71
|
+
it('renders the `aria-label` attribute on the "content" container element', () => {
|
|
71
72
|
const $ = cheerio.load(
|
|
72
73
|
renderComponent('table', {
|
|
73
74
|
...EXAMPLE_TABLE,
|
|
74
|
-
caption: 'Example table caption',
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect($('.ons-table-scrollable__content').attr('aria-label')).toBe('Example table caption. Scrollable table');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('renders a custom `aria-label` attribute on the "content" container element', () => {
|
|
82
|
-
const $ = cheerio.load(
|
|
83
|
-
renderComponent('table', {
|
|
84
|
-
...EXAMPLE_TABLE,
|
|
85
|
-
caption: 'Example table caption',
|
|
86
75
|
ariaLabel: 'Special table',
|
|
87
76
|
}),
|
|
88
77
|
);
|
|
89
78
|
|
|
90
|
-
expect($('.ons-table-scrollable__content').attr('aria-label')).toBe('
|
|
79
|
+
expect($('.ons-table-scrollable__content').attr('aria-label')).toBe('Special table');
|
|
91
80
|
});
|
|
92
81
|
|
|
93
82
|
describe('Vertical Alignment', () => {
|
|
@@ -680,4 +669,174 @@ describe('macro: table', () => {
|
|
|
680
669
|
expect($('.ons-table__caption').hasClass('ons-u-vh')).toBe(true);
|
|
681
670
|
});
|
|
682
671
|
});
|
|
672
|
+
|
|
673
|
+
describe('bottom spacing', () => {
|
|
674
|
+
it('adds "ons-table--bottom-space" class when there are no footnotes, download or sourceNote', () => {
|
|
675
|
+
const $ = cheerio.load(renderComponent('table', EXAMPLE_TABLE));
|
|
676
|
+
|
|
677
|
+
expect($('.ons-table').hasClass('ons-table--bottom-space')).toBe(true);
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
it('does not add "ons-table--bottom-space" class when `sourceNote` is provided', () => {
|
|
681
|
+
const $ = cheerio.load(
|
|
682
|
+
renderComponent('table', {
|
|
683
|
+
...EXAMPLE_TABLE,
|
|
684
|
+
sourceNote: 'Source: Office for National Statistics',
|
|
685
|
+
}),
|
|
686
|
+
);
|
|
687
|
+
|
|
688
|
+
expect($('.ons-table').hasClass('ons-table--bottom-space')).toBe(false);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it('does not add "ons-table--bottom-space" class when `footnotes` is provided', () => {
|
|
692
|
+
const $ = cheerio.load(
|
|
693
|
+
renderComponent('table', {
|
|
694
|
+
...EXAMPLE_TABLE,
|
|
695
|
+
footnotes: {
|
|
696
|
+
title: 'Footnotes',
|
|
697
|
+
content: 'Data is seasonally adjusted.',
|
|
698
|
+
},
|
|
699
|
+
}),
|
|
700
|
+
);
|
|
701
|
+
|
|
702
|
+
expect($('.ons-table').hasClass('ons-table--bottom-space')).toBe(false);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it('does not add "ons-table--bottom-space" class when `download` is provided', () => {
|
|
706
|
+
const $ = cheerio.load(
|
|
707
|
+
renderComponent('table', {
|
|
708
|
+
...EXAMPLE_TABLE,
|
|
709
|
+
download: {
|
|
710
|
+
title: 'Download this table',
|
|
711
|
+
itemsList: [
|
|
712
|
+
{
|
|
713
|
+
text: 'Table data (CSV, 2KB)',
|
|
714
|
+
url: '/data/table.csv',
|
|
715
|
+
download: 'file',
|
|
716
|
+
},
|
|
717
|
+
],
|
|
718
|
+
},
|
|
719
|
+
}),
|
|
720
|
+
);
|
|
721
|
+
|
|
722
|
+
expect($('.ons-table').hasClass('ons-table--bottom-space')).toBe(false);
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
describe('figure wrapper', () => {
|
|
727
|
+
it('renders with a <div> root element instead of <figure>', () => {
|
|
728
|
+
const $ = cheerio.load(renderComponent('table', EXAMPLE_TABLE));
|
|
729
|
+
|
|
730
|
+
expect($('.ons-figure')[0].tagName).toBe('div');
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it('passes `title` to the figure component', () => {
|
|
734
|
+
const faker = templateFaker();
|
|
735
|
+
const figureSpy = faker.spy('figure');
|
|
736
|
+
|
|
737
|
+
faker.renderComponent('table', {
|
|
738
|
+
...EXAMPLE_TABLE,
|
|
739
|
+
title: 'Population by region',
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
expect(figureSpy.occurrences[0].title).toBe('Population by region');
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
it('passes `subtitle` to the figure component', () => {
|
|
746
|
+
const faker = templateFaker();
|
|
747
|
+
const figureSpy = faker.spy('figure');
|
|
748
|
+
|
|
749
|
+
faker.renderComponent('table', {
|
|
750
|
+
...EXAMPLE_TABLE,
|
|
751
|
+
subtitle: 'Mid-year estimates, 2023',
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
expect(figureSpy.occurrences[0].subtitle).toBe('Mid-year estimates, 2023');
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
it('passes `headingLevel` to the figure component', () => {
|
|
758
|
+
const faker = templateFaker();
|
|
759
|
+
const figureSpy = faker.spy('figure');
|
|
760
|
+
|
|
761
|
+
faker.renderComponent('table', {
|
|
762
|
+
...EXAMPLE_TABLE,
|
|
763
|
+
headingLevel: 3,
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
expect(figureSpy.occurrences[0].headingLevel).toBe(3);
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
it('passes `figureNumber` to the figure component', () => {
|
|
770
|
+
const faker = templateFaker();
|
|
771
|
+
const figureSpy = faker.spy('figure');
|
|
772
|
+
|
|
773
|
+
faker.renderComponent('table', {
|
|
774
|
+
...EXAMPLE_TABLE,
|
|
775
|
+
figureNumber: 'Table 1',
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
expect(figureSpy.occurrences[0].figureNumber).toBe('Table 1');
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
it('passes `footnotes` to the figure component', () => {
|
|
782
|
+
const faker = templateFaker();
|
|
783
|
+
const figureSpy = faker.spy('figure');
|
|
784
|
+
|
|
785
|
+
const footnotes = {
|
|
786
|
+
title: 'Footnotes',
|
|
787
|
+
content: 'Data is seasonally adjusted.',
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
faker.renderComponent('table', {
|
|
791
|
+
...EXAMPLE_TABLE,
|
|
792
|
+
footnotes,
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
expect(figureSpy.occurrences[0].footnotes).toEqual(footnotes);
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
it('passes `download` to the figure component', () => {
|
|
799
|
+
const faker = templateFaker();
|
|
800
|
+
const figureSpy = faker.spy('figure');
|
|
801
|
+
|
|
802
|
+
const download = {
|
|
803
|
+
title: 'Download this table',
|
|
804
|
+
itemsList: [
|
|
805
|
+
{
|
|
806
|
+
text: 'Table data (CSV, 2KB)',
|
|
807
|
+
url: '/data/table.csv',
|
|
808
|
+
download: 'file',
|
|
809
|
+
},
|
|
810
|
+
],
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
faker.renderComponent('table', {
|
|
814
|
+
...EXAMPLE_TABLE,
|
|
815
|
+
download,
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
expect(figureSpy.occurrences[0].download).toEqual(download);
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
it('passes `sourceNote` to the figure component', () => {
|
|
822
|
+
const faker = templateFaker();
|
|
823
|
+
const figureSpy = faker.spy('figure');
|
|
824
|
+
|
|
825
|
+
faker.renderComponent('table', {
|
|
826
|
+
...EXAMPLE_TABLE,
|
|
827
|
+
sourceNote: 'Source: Office for National Statistics',
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
expect(figureSpy.occurrences[0].caption).toBe('Source: Office for National Statistics');
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it('sets `useDivForRootElement` on the figure component', () => {
|
|
834
|
+
const faker = templateFaker();
|
|
835
|
+
const figureSpy = faker.spy('figure');
|
|
836
|
+
|
|
837
|
+
faker.renderComponent('table', EXAMPLE_TABLE);
|
|
838
|
+
|
|
839
|
+
expect(figureSpy.occurrences[0].useDivForRootElement).toBe(true);
|
|
840
|
+
});
|
|
841
|
+
});
|
|
683
842
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
.ons-table {
|
|
2
2
|
border-collapse: collapse;
|
|
3
3
|
border-spacing: 0;
|
|
4
|
-
margin-bottom: 1rem;
|
|
5
4
|
width: 100%;
|
|
6
5
|
|
|
7
6
|
&__head {
|
|
@@ -241,4 +240,10 @@
|
|
|
241
240
|
}
|
|
242
241
|
}
|
|
243
242
|
}
|
|
243
|
+
|
|
244
|
+
// Used when there is no source note, footnotes or downloads after the table, to match the previous bottom spacing
|
|
245
|
+
// If there source note, footnotes or downloads after the table, the figure component handles the extra spacing
|
|
246
|
+
&--bottom-space {
|
|
247
|
+
margin-bottom: 1rem;
|
|
248
|
+
}
|
|
244
249
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{% from "components/table/_macro.njk" import onsTable %}
|
|
2
|
+
{{
|
|
3
|
+
onsTable({
|
|
4
|
+
"ariaLabel": "Basic table example",
|
|
5
|
+
"id": "basic-table",
|
|
6
|
+
"ths": [
|
|
7
|
+
{
|
|
8
|
+
"value": "Column A"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"value": "Column B"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"value": "Column C"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"trs": [
|
|
18
|
+
{
|
|
19
|
+
"tds": [
|
|
20
|
+
{
|
|
21
|
+
"value": "Cell A1"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"value": "Cell B1"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"value": "Cell C1"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"tds": [
|
|
33
|
+
{
|
|
34
|
+
"value": "Cell A2"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"value": "Cell B2"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"value": "Cell C2"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
}}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{% from "components/table/_macro.njk" import onsTable %}
|
|
2
|
+
{{
|
|
3
|
+
onsTable({
|
|
4
|
+
"caption": "A basic table with a visually hidden caption",
|
|
5
|
+
"hideCaption": true,
|
|
6
|
+
"id": "basic-table",
|
|
7
|
+
"ths": [
|
|
8
|
+
{
|
|
9
|
+
"value": "Column A"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"value": "Column B"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"value": "Column C"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"trs": [
|
|
19
|
+
{
|
|
20
|
+
"tds": [
|
|
21
|
+
{
|
|
22
|
+
"value": "Cell A1"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"value": "Cell B1"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"value": "Cell C1"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"tds": [
|
|
34
|
+
{
|
|
35
|
+
"value": "Cell A2"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"value": "Cell B2"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"value": "Cell C2"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
})
|
|
47
|
+
}}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{% from "components/table/_macro.njk" import onsTable %}
|
|
2
|
+
{{
|
|
3
|
+
onsTable({
|
|
4
|
+
"id": "table-with-figure-fields",
|
|
5
|
+
"headingLevel": 3,
|
|
6
|
+
"figureNumber": "Table 1",
|
|
7
|
+
"title": "Population by region, mid-2023",
|
|
8
|
+
"subtitle": "Estimates for England and Wales",
|
|
9
|
+
"caption": "Population estimates by region",
|
|
10
|
+
"sourceNote": "Source: Office for National Statistics – Population estimates for the UK, England and Wales, Scotland and Northern Ireland",
|
|
11
|
+
"ths": [
|
|
12
|
+
{
|
|
13
|
+
"value": "Region"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"value": "Population",
|
|
17
|
+
"numeric": true
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"value": "Change (%)",
|
|
21
|
+
"numeric": true
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"trs": [
|
|
25
|
+
{
|
|
26
|
+
"tds": [
|
|
27
|
+
{
|
|
28
|
+
"value": "North East"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"value": "2,647,000",
|
|
32
|
+
"numeric": true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"value": "0.3",
|
|
36
|
+
"numeric": true
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"tds": [
|
|
42
|
+
{
|
|
43
|
+
"value": "North West"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"value": "7,417,000",
|
|
47
|
+
"numeric": true
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"value": "0.5",
|
|
51
|
+
"numeric": true
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"tds": [
|
|
57
|
+
{
|
|
58
|
+
"value": "South East"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"value": "9,294,000",
|
|
62
|
+
"numeric": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"value": "0.7",
|
|
66
|
+
"numeric": true
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"footnotes": {
|
|
72
|
+
"title": "Footnotes",
|
|
73
|
+
"content": "Figures are rounded to the nearest thousand. Percentage change is compared with mid-2022 estimates."
|
|
74
|
+
},
|
|
75
|
+
"download": {
|
|
76
|
+
"title": "Download this table",
|
|
77
|
+
"itemsList": [
|
|
78
|
+
{
|
|
79
|
+
"text": "Population by region (CSV format, 1KB)",
|
|
80
|
+
"url": "/data/population-by-region.csv",
|
|
81
|
+
"download": "file"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
}}
|
|
@@ -5,6 +5,7 @@ describe('script: table', () => {
|
|
|
5
5
|
// Construct a table with 15 columns and 15 rows with long labels.
|
|
6
6
|
const params = {
|
|
7
7
|
variants: ['scrollable'],
|
|
8
|
+
ariaLabel: 'Example table',
|
|
8
9
|
ths: Array.from({ length: 15 }, (_, i) => ({ value: `Column ${i + 1}` })),
|
|
9
10
|
trs: [
|
|
10
11
|
{
|
|
@@ -44,6 +45,7 @@ describe('script: table', () => {
|
|
|
44
45
|
describe('variant: sortable', () => {
|
|
45
46
|
const params = {
|
|
46
47
|
variants: ['sortable'],
|
|
48
|
+
ariaLabel: 'Example table',
|
|
47
49
|
sortBy: 'Sort by',
|
|
48
50
|
ariaAsc: 'ascending',
|
|
49
51
|
ariaDesc: 'descending',
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
<nav class="ons-table-of-contents" aria-label="{{ params.ariaLabel | default('Table of contents') }}">
|
|
17
17
|
<h2 class="ons-table-of-contents__title ons-u-fs-r--b ons-u-mb-s">{{ params.title }}</h2>
|
|
18
|
+
{% set element = 'ol' if params.ordered else 'ul' %}
|
|
19
|
+
{% set variant = null if params.ordered else 'dashed' %}
|
|
18
20
|
{% if params.lists %}
|
|
19
21
|
{% for list in params.lists %}
|
|
20
22
|
{% if list.listHeading %}
|
|
@@ -24,9 +26,9 @@
|
|
|
24
26
|
{% endif %}
|
|
25
27
|
{{
|
|
26
28
|
onsList({
|
|
27
|
-
"element":
|
|
29
|
+
"element": element,
|
|
28
30
|
"classes": 'ons-u-mb-l',
|
|
29
|
-
"variants":
|
|
31
|
+
"variants": variant,
|
|
30
32
|
"itemsList": list.itemsList
|
|
31
33
|
})
|
|
32
34
|
}}
|
|
@@ -34,9 +36,9 @@
|
|
|
34
36
|
{% elif params.itemsList %}
|
|
35
37
|
{{
|
|
36
38
|
onsList({
|
|
37
|
-
"element":
|
|
39
|
+
"element": element,
|
|
38
40
|
"classes": 'ons-u-mb-l',
|
|
39
|
-
"variants":
|
|
41
|
+
"variants": variant,
|
|
40
42
|
"itemsList": params.itemsList
|
|
41
43
|
})
|
|
42
44
|
}}
|
|
@@ -160,12 +160,29 @@ describe('macro: table-of-contents', () => {
|
|
|
160
160
|
faker.renderComponent('table-of-contents', EXAMPLE_TABLE_OF_CONTENTS_SINGLE);
|
|
161
161
|
|
|
162
162
|
expect(listsSpy.occurrences[0]).toEqual({
|
|
163
|
-
element: '
|
|
163
|
+
element: 'ul',
|
|
164
164
|
classes: 'ons-u-mb-l',
|
|
165
165
|
variants: 'dashed',
|
|
166
166
|
itemsList: EXAMPLE_TABLE_OF_CONTENTS_SINGLE.itemsList,
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
|
+
|
|
170
|
+
it('outputs `lists` component as an ordered list when `ordered` is `true`', () => {
|
|
171
|
+
const faker = templateFaker();
|
|
172
|
+
const listsSpy = faker.spy('list');
|
|
173
|
+
|
|
174
|
+
faker.renderComponent('table-of-contents', {
|
|
175
|
+
...EXAMPLE_TABLE_OF_CONTENTS_SINGLE,
|
|
176
|
+
ordered: true,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(listsSpy.occurrences[0]).toEqual({
|
|
180
|
+
element: 'ol',
|
|
181
|
+
classes: 'ons-u-mb-l',
|
|
182
|
+
variants: null,
|
|
183
|
+
itemsList: EXAMPLE_TABLE_OF_CONTENTS_SINGLE.itemsList,
|
|
184
|
+
});
|
|
185
|
+
});
|
|
169
186
|
});
|
|
170
187
|
|
|
171
188
|
describe('multiple lists', () => {
|
|
@@ -199,18 +216,41 @@ describe('macro: table-of-contents', () => {
|
|
|
199
216
|
faker.renderComponent('table-of-contents', EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE);
|
|
200
217
|
|
|
201
218
|
expect(listsSpy.occurrences[0]).toEqual({
|
|
202
|
-
element: '
|
|
219
|
+
element: 'ul',
|
|
203
220
|
classes: 'ons-u-mb-l',
|
|
204
221
|
variants: 'dashed',
|
|
205
222
|
itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[0].itemsList,
|
|
206
223
|
});
|
|
207
224
|
expect(listsSpy.occurrences[1]).toEqual({
|
|
208
|
-
element: '
|
|
225
|
+
element: 'ul',
|
|
209
226
|
classes: 'ons-u-mb-l',
|
|
210
227
|
variants: 'dashed',
|
|
211
228
|
itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[1].itemsList,
|
|
212
229
|
});
|
|
213
230
|
});
|
|
231
|
+
|
|
232
|
+
it('outputs `lists` component for each list as ordered lists when `ordered` is `true`', () => {
|
|
233
|
+
const faker = templateFaker();
|
|
234
|
+
const listsSpy = faker.spy('list');
|
|
235
|
+
|
|
236
|
+
faker.renderComponent('table-of-contents', {
|
|
237
|
+
...EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE,
|
|
238
|
+
ordered: true,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(listsSpy.occurrences[0]).toEqual({
|
|
242
|
+
element: 'ol',
|
|
243
|
+
classes: 'ons-u-mb-l',
|
|
244
|
+
variants: null,
|
|
245
|
+
itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[0].itemsList,
|
|
246
|
+
});
|
|
247
|
+
expect(listsSpy.occurrences[1]).toEqual({
|
|
248
|
+
element: 'ol',
|
|
249
|
+
classes: 'ons-u-mb-l',
|
|
250
|
+
variants: null,
|
|
251
|
+
itemsList: EXAMPLE_TABLE_OF_CONTENTS_MULTIPLE.lists[1].itemsList,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
214
254
|
});
|
|
215
255
|
|
|
216
256
|
describe('related links and button', () => {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{% from "components/table-of-contents/_macro.njk" import onsTableOfContents %}
|
|
2
|
+
|
|
3
|
+
{{-
|
|
4
|
+
onsTableOfContents({
|
|
5
|
+
"title": 'Contents',
|
|
6
|
+
"ariaLabel": 'Pages in this guide',
|
|
7
|
+
"skipLink": {
|
|
8
|
+
"url": "#0",
|
|
9
|
+
"text": 'Skip to guide content'
|
|
10
|
+
},
|
|
11
|
+
"ordered": true,
|
|
12
|
+
"lists": [
|
|
13
|
+
{
|
|
14
|
+
"itemsList": [
|
|
15
|
+
{
|
|
16
|
+
"url": '#0',
|
|
17
|
+
"text": 'Overview',
|
|
18
|
+
"current": true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"url": '#0',
|
|
22
|
+
"text": 'Who should take part and why'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"url": '#0',
|
|
26
|
+
"text": 'How your information is used'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"url": '#0',
|
|
30
|
+
"text": 'The 2019 Census Rehearsal'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"url": '#0',
|
|
34
|
+
"text": 'Further information'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"url": '#0',
|
|
38
|
+
"text": 'Online census'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"url": '#0',
|
|
42
|
+
"text": 'Who should take part and why'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"url": '#0',
|
|
46
|
+
"text": 'How your information is used'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"url": '#0',
|
|
50
|
+
"text": 'The 2019 Census Rehearsal'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"url": '#0',
|
|
54
|
+
"text": 'Further information'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"url": '#0',
|
|
58
|
+
"text": 'Online census'
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
-}}
|