@ons/design-system 74.0.0-next.6 → 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.
Files changed (63) hide show
  1. package/components/chart/_chart.scss +0 -9
  2. package/components/chart/_macro.njk +96 -128
  3. package/components/chart/_macro.spec.js +43 -28
  4. package/components/chart/example-area-chart-with-axis-min-and-max-values.njk +6 -3
  5. package/components/chart/example-area-chart.njk +6 -3
  6. package/components/chart/example-bar-chart-with-annotations.njk +6 -3
  7. package/components/chart/example-bar-chart-with-axis-min-and-max-values.njk +6 -3
  8. package/components/chart/example-bar-chart-with-point-range-and-reference-line-annotations.njk +6 -3
  9. package/components/chart/example-bar-chart.njk +6 -3
  10. package/components/chart/example-bar-with-confidence-levels.njk +6 -3
  11. package/components/chart/example-clustered-bar-chart.njk +6 -3
  12. package/components/chart/example-clustered-column-chart.njk +6 -3
  13. package/components/chart/example-column-chart-with-annotations.njk +6 -3
  14. package/components/chart/example-column-chart-with-axis-min-and-max-values.njk +6 -3
  15. package/components/chart/example-column-chart-with-custom-reference-line-value.njk +6 -3
  16. package/components/chart/example-column-chart-with-range-annotations.njk +6 -3
  17. package/components/chart/example-column-chart-with-reference-line-annotations.njk +6 -3
  18. package/components/chart/example-column-chart.njk +6 -3
  19. package/components/chart/example-column-with-confidence-levels.njk +6 -3
  20. package/components/chart/example-column-with-line-chart.njk +6 -3
  21. package/components/chart/example-iframe-chart.njk +6 -3
  22. package/components/chart/example-line-chart-with-annotations.njk +6 -3
  23. package/components/chart/example-line-chart-with-axis-min-and-max-values.njk +6 -3
  24. package/components/chart/example-line-chart-with-custom-reference-line-value.njk +6 -3
  25. package/components/chart/example-line-chart-with-label-format.njk +6 -3
  26. package/components/chart/example-line-chart-with-markers.njk +6 -3
  27. package/components/chart/example-line-chart-with-range-annotations-inside.njk +6 -3
  28. package/components/chart/example-line-chart-with-range-annotations-outside-left-right.njk +6 -3
  29. package/components/chart/example-line-chart-with-range-annotations-outside-top-bottom.njk +6 -3
  30. package/components/chart/example-line-chart-with-reference-line-annotations.njk +6 -3
  31. package/components/chart/example-line-chart.njk +6 -3
  32. package/components/chart/example-scatter-chart-with-axis-min-and-max-values.njk +6 -3
  33. package/components/chart/example-scatter-chart.njk +6 -3
  34. package/components/chart/example-stacked-bar-chart.njk +6 -3
  35. package/components/chart/example-stacked-column-chart.njk +6 -3
  36. package/components/document-list/_macro.njk +2 -2
  37. package/components/document-list/_macro.spec.js +55 -0
  38. package/components/featured-article/_macro.njk +3 -37
  39. package/components/featured-article/example-featured-article-with-chart.njk +19 -14
  40. package/components/featured-article/example-featured-article-with-image.njk +12 -7
  41. package/components/featured-article/featured-article.scss +1 -1
  42. package/components/featured-article/macro.spec.js +44 -67
  43. package/components/figure/_figure.scss +31 -0
  44. package/components/figure/_macro.njk +98 -0
  45. package/components/figure/_macro.spec.js +520 -0
  46. package/components/figure/example-figure-heading-level-2.njk +34 -0
  47. package/components/figure/example-figure-with-div.njk +29 -0
  48. package/components/figure/example-figure-without-footer.njk +12 -0
  49. package/components/figure/example-figure-without-header.njk +24 -0
  50. package/components/figure/example-figure.njk +34 -0
  51. package/components/image/_image.scss +0 -7
  52. package/components/image/_macro.njk +25 -14
  53. package/components/image/_macro.spec.js +122 -7
  54. package/components/image/example-image-with-figure-fields.njk +25 -0
  55. package/components/list/_macro.njk +1 -0
  56. package/components/list/_macro.spec.js +16 -0
  57. package/components/table/_macro.njk +138 -111
  58. package/components/table/_macro.spec.js +172 -2
  59. package/components/table/_table.scss +6 -1
  60. package/components/table/example-table-with-figure-fields.njk +86 -0
  61. package/css/main.css +1 -1
  62. package/package.json +2 -2
  63. package/scss/main.scss +1 -0
@@ -33,7 +33,7 @@ describe('macro: table', () => {
33
33
  expect(results).toHaveNoViolations();
34
34
  });
35
35
 
36
- it('has the provided `id` attribute', () => {
36
+ it('has the provided `id` on the wrapping element', () => {
37
37
  const $ = cheerio.load(
38
38
  renderComponent('table', {
39
39
  ...EXAMPLE_TABLE,
@@ -41,7 +41,7 @@ describe('macro: table', () => {
41
41
  }),
42
42
  );
43
43
 
44
- expect($('.ons-table').attr('id')).toBe('example-table');
44
+ expect($('.ons-figure').attr('id')).toBe('example-table');
45
45
  });
46
46
 
47
47
  it('has additionally provided style classes', () => {
@@ -669,4 +669,174 @@ describe('macro: table', () => {
669
669
  expect($('.ons-table__caption').hasClass('ons-u-vh')).toBe(true);
670
670
  });
671
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
+ });
672
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,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
+ }}