@scottish-government/designsystem-react 0.7.0 → 0.8.0-beta.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.
Files changed (211) hide show
  1. package/@types/common/AbstractNotificationBanner.d.ts +2 -2
  2. package/@types/common/ActionLink.d.ts +8 -0
  3. package/@types/common/FileIcon.d.ts +1 -1
  4. package/@types/common/Icon.d.ts +1 -1
  5. package/@types/components/Accordion.d.ts +0 -1
  6. package/@types/components/Breadcrumbs.d.ts +2 -5
  7. package/@types/components/Checkbox.d.ts +0 -2
  8. package/@types/components/ConfirmationMessage.d.ts +1 -1
  9. package/@types/components/ContentsNav.d.ts +4 -6
  10. package/@types/components/DatePicker.d.ts +1 -1
  11. package/@types/components/ErrorSummary.d.ts +3 -4
  12. package/@types/components/NotificationPanel.d.ts +1 -1
  13. package/@types/components/Pagination.d.ts +5 -4
  14. package/@types/components/PhaseBanner.d.ts +0 -1
  15. package/@types/components/Question.d.ts +1 -1
  16. package/@types/components/RadioButton.d.ts +0 -1
  17. package/@types/components/Select.d.ts +0 -7
  18. package/@types/components/SequentialNavigation.d.ts +4 -4
  19. package/@types/components/SideNavigation.d.ts +4 -5
  20. package/@types/components/SiteFooter.d.ts +25 -0
  21. package/@types/components/SiteHeader.d.ts +10 -3
  22. package/@types/components/SiteNavigation.d.ts +2 -3
  23. package/@types/components/SkipLinks.d.ts +3 -4
  24. package/@types/components/SummaryCard.d.ts +0 -2
  25. package/@types/components/SummaryList.d.ts +0 -13
  26. package/@types/components/Tabs.d.ts +0 -1
  27. package/@types/components/Tag.d.ts +1 -3
  28. package/@types/components/TaskList.d.ts +1 -0
  29. package/@types/sgds.d.ts +13 -2
  30. package/CHANGELOG.md +63 -1
  31. package/dist/common/AbstractNotificationBanner.jsx +8 -6
  32. package/dist/common/ActionLink.jsx +19 -0
  33. package/dist/common/FileIcon.jsx +2 -7
  34. package/dist/common/Icon.jsx +3 -9
  35. package/dist/components/Accordion/Accordion.jsx +12 -7
  36. package/dist/components/Breadcrumbs/Breadcrumbs.jsx +20 -15
  37. package/dist/components/Checkbox/Checkbox.jsx +4 -29
  38. package/dist/components/{aspect-box/aspect-box.jsx → Checkbox/CheckboxGroup.jsx} +14 -30
  39. package/dist/components/ContentsNav/ContentsNav.jsx +27 -16
  40. package/dist/components/CookieBanner/CookieBanner.jsx +1 -0
  41. package/dist/components/DatePicker/DatePicker.jsx +5 -5
  42. package/dist/components/ErrorSummary/ErrorSummary.jsx +28 -18
  43. package/dist/components/NotificationBanner/NotificationBanner.jsx +2 -2
  44. package/dist/components/Pagination/Pagination.jsx +42 -22
  45. package/dist/components/PhaseBanner/PhaseBanner.jsx +3 -3
  46. package/dist/components/Question/Question.jsx +3 -3
  47. package/dist/components/RadioButton/RadioButton.jsx +7 -17
  48. package/dist/components/RadioButton/RadioGroup.jsx +21 -0
  49. package/dist/components/Select/Select.jsx +4 -7
  50. package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -18
  51. package/dist/components/SideNavigation/SideNavigation.jsx +17 -16
  52. package/dist/components/SiteFooter/SiteFooter.jsx +104 -0
  53. package/dist/components/SiteHeader/SiteHeader.jsx +113 -32
  54. package/dist/components/SiteNavigation/SiteNavigation.jsx +20 -7
  55. package/dist/components/SkipLinks/SkipLinks.jsx +10 -10
  56. package/dist/components/SummaryCard/SummaryCard.jsx +25 -14
  57. package/dist/components/SummaryList/SummaryList.jsx +65 -47
  58. package/dist/components/Tabs/Tabs.jsx +6 -6
  59. package/dist/components/Tag/Tag.jsx +2 -2
  60. package/dist/components/TaskList/TaskList.jsx +14 -3
  61. package/dist/components/TextInput/TextInput.jsx +3 -3
  62. package/dist/components/Textarea/Textarea.jsx +3 -3
  63. package/dist/hooks/useTracking.js +21 -0
  64. package/dist/tsconfig.tsbuildinfo +1 -1
  65. package/dist/utils/context.js +5 -0
  66. package/package.json +2 -2
  67. package/src/common/AbstractNotificationBanner.test.tsx +1 -1
  68. package/src/common/AbstractNotificationBanner.tsx +14 -13
  69. package/src/common/ActionLink.test.tsx +80 -0
  70. package/src/common/ActionLink.tsx +27 -0
  71. package/src/common/ConditionalWrapper.tsx +1 -1
  72. package/src/common/FileIcon.tsx +7 -11
  73. package/src/common/HintText.tsx +2 -2
  74. package/src/common/Icon.tsx +13 -17
  75. package/src/common/ScreenReaderText.tsx +2 -2
  76. package/src/common/WrapperTag.tsx +2 -2
  77. package/src/components/Accordion/Accordion.test.tsx +17 -4
  78. package/src/components/Accordion/Accordion.tsx +19 -14
  79. package/src/components/AspectBox/AspectBox.tsx +2 -2
  80. package/src/components/BackToTop/BackToTop.tsx +2 -2
  81. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +79 -48
  82. package/src/components/Breadcrumbs/Breadcrumbs.tsx +31 -31
  83. package/src/components/Button/Button.tsx +2 -2
  84. package/src/components/Checkbox/Checkbox.test.tsx +1 -96
  85. package/src/components/Checkbox/Checkbox.tsx +8 -55
  86. package/src/components/Checkbox/CheckboxGroup.test.tsx +37 -0
  87. package/src/components/Checkbox/CheckboxGroup.tsx +41 -0
  88. package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +2 -2
  89. package/src/components/ContentsNav/ContentsNav.test.tsx +40 -51
  90. package/src/components/ContentsNav/ContentsNav.tsx +32 -25
  91. package/src/components/CookieBanner/CookieBanner.tsx +3 -3
  92. package/src/components/DatePicker/DatePicker.test.tsx +1 -1
  93. package/src/components/DatePicker/DatePicker.tsx +7 -7
  94. package/src/components/Details/Details.tsx +2 -2
  95. package/src/components/ErrorMessage/ErrorMessage.tsx +2 -2
  96. package/src/components/ErrorSummary/ErrorSummary.test.tsx +40 -34
  97. package/src/components/ErrorSummary/ErrorSummary.tsx +40 -32
  98. package/src/components/FileDownload/FileDownload.tsx +2 -2
  99. package/src/components/HideThisPage/HideThisPage.tsx +2 -2
  100. package/src/components/InsetText/InsetText.tsx +2 -2
  101. package/src/components/NotificationBanner/NotificationBanner.tsx +6 -7
  102. package/src/components/NotificationPanel/NotificationPanel.tsx +2 -2
  103. package/src/components/PageHeader/PageHeader.tsx +2 -2
  104. package/src/components/PageMetadata/PageMetadata.tsx +4 -5
  105. package/src/components/Pagination/Pagination.test.tsx +26 -7
  106. package/src/components/Pagination/Pagination.tsx +70 -36
  107. package/src/components/PhaseBanner/PhaseBanner.tsx +4 -5
  108. package/src/components/Question/Question.test.tsx +1 -1
  109. package/src/components/Question/Question.tsx +5 -5
  110. package/src/components/RadioButton/RadioButton.test.tsx +7 -126
  111. package/src/components/RadioButton/RadioButton.tsx +10 -41
  112. package/src/components/RadioButton/RadioGroup.test.tsx +65 -0
  113. package/src/components/RadioButton/RadioGroup.tsx +31 -0
  114. package/src/components/Select/Select.test.tsx +39 -37
  115. package/src/components/Select/Select.tsx +7 -22
  116. package/src/components/SequentialNavigation/SequentialNavigation.test.tsx +32 -21
  117. package/src/components/SequentialNavigation/SequentialNavigation.tsx +52 -30
  118. package/src/components/SideNavigation/SideNavigation.test.tsx +39 -85
  119. package/src/components/SideNavigation/SideNavigation.tsx +27 -29
  120. package/src/components/SiteFooter/SiteFooter.test.tsx +153 -0
  121. package/src/components/SiteFooter/SiteFooter.tsx +107 -0
  122. package/src/components/SiteHeader/SiteHeader.test.tsx +87 -79
  123. package/src/components/SiteHeader/SiteHeader.tsx +103 -40
  124. package/src/components/SiteNavigation/SiteNavigation.test.tsx +42 -23
  125. package/src/components/SiteNavigation/SiteNavigation.tsx +28 -16
  126. package/src/components/SiteSearch/SiteSearch.tsx +2 -2
  127. package/src/components/SkipLinks/SkipLinks.test.tsx +22 -10
  128. package/src/components/SkipLinks/SkipLinks.tsx +16 -15
  129. package/src/components/SummaryCard/SummaryCard.test.tsx +31 -35
  130. package/src/components/SummaryCard/SummaryCard.tsx +39 -28
  131. package/src/components/SummaryList/SummaryList.test.tsx +49 -148
  132. package/src/components/SummaryList/SummaryList.tsx +54 -92
  133. package/src/components/Table/Table.tsx +2 -2
  134. package/src/components/Tabs/Tabs.tsx +14 -15
  135. package/src/components/Tag/Tag.test.tsx +4 -4
  136. package/src/components/Tag/Tag.tsx +4 -4
  137. package/src/components/TaskList/TaskList.test.tsx +26 -0
  138. package/src/components/TaskList/TaskList.tsx +21 -11
  139. package/src/components/TextInput/TextInput.test.tsx +1 -1
  140. package/src/components/TextInput/TextInput.tsx +5 -5
  141. package/src/components/Textarea/Textarea.test.tsx +1 -1
  142. package/src/components/Textarea/Textarea.tsx +5 -5
  143. package/src/components/WarningText/WarningText.tsx +2 -2
  144. package/src/hooks/useTracking.test.tsx +64 -0
  145. package/src/hooks/useTracking.ts +19 -0
  146. package/src/utils/context.ts +3 -0
  147. package/tsconfig.json +1 -1
  148. package/dist/common/abstract-notification-banner.jsx +0 -63
  149. package/dist/common/conditional-wrapper.jsx +0 -8
  150. package/dist/common/file-icon.jsx +0 -51
  151. package/dist/common/hint-text.jsx +0 -9
  152. package/dist/common/icon.jsx +0 -57
  153. package/dist/common/screen-reader-text.jsx +0 -9
  154. package/dist/common/wrapper-tag.jsx +0 -11
  155. package/dist/components/accordion/accordion.jsx +0 -102
  156. package/dist/components/back-to-top/back-to-top.jsx +0 -27
  157. package/dist/components/breadcrumbs/breadcrumbs.jsx +0 -28
  158. package/dist/components/button/button.jsx +0 -30
  159. package/dist/components/checkbox/checkbox.jsx +0 -62
  160. package/dist/components/confirmation-message/confirmation-message.jsx +0 -24
  161. package/dist/components/contents-nav/contents-nav.jsx +0 -33
  162. package/dist/components/cookie-banner/cookie-banner.jsx +0 -21
  163. package/dist/components/date-picker/date-picker.jsx +0 -54
  164. package/dist/components/details/details.jsx +0 -17
  165. package/dist/components/error-message/error-message.jsx +0 -12
  166. package/dist/components/error-summary/error-summary.jsx +0 -27
  167. package/dist/components/file-download/file-download.jsx +0 -50
  168. package/dist/components/hide-this-page/hide-this-page.jsx +0 -71
  169. package/dist/components/inset-text/inset-text.jsx +0 -14
  170. package/dist/components/notification-banner/notification-banner.jsx +0 -26
  171. package/dist/components/notification-panel/notification-panel.jsx +0 -21
  172. package/dist/components/page-header/page-header.jsx +0 -15
  173. package/dist/components/page-metadata/page-metadata.jsx +0 -26
  174. package/dist/components/pagination/pagination.jsx +0 -97
  175. package/dist/components/phase-banner/phase-banner.jsx +0 -23
  176. package/dist/components/question/question.jsx +0 -22
  177. package/dist/components/radio-button/radio-button.jsx +0 -43
  178. package/dist/components/select/select.jsx +0 -52
  179. package/dist/components/sequential-navigation/sequential-navigation.jsx +0 -31
  180. package/dist/components/side-navigation/side-navigation.jsx +0 -52
  181. package/dist/components/site-header/site-header.jsx +0 -68
  182. package/dist/components/site-navigation/site-navigation.jsx +0 -22
  183. package/dist/components/site-search/site-search.jsx +0 -55
  184. package/dist/components/skip-links/skip-links.jsx +0 -21
  185. package/dist/components/summary-card/summary-card.jsx +0 -67
  186. package/dist/components/summary-list/summary-list.jsx +0 -75
  187. package/dist/components/table/table.jsx +0 -24
  188. package/dist/components/tabs/tabs.jsx +0 -99
  189. package/dist/components/tag/tag.jsx +0 -13
  190. package/dist/components/task-list/task-list.jsx +0 -95
  191. package/dist/components/text-input/text-input.jsx +0 -58
  192. package/dist/components/textarea/textarea.jsx +0 -54
  193. package/dist/components/warning-text/warning-text.jsx +0 -16
  194. package/dist/icons/ArrowUpward.jsx +0 -41
  195. package/dist/icons/CalendarToday.jsx +0 -41
  196. package/dist/icons/Cancel.jsx +0 -40
  197. package/dist/icons/CheckCircle.jsx +0 -41
  198. package/dist/icons/ChevronLeft.jsx +0 -41
  199. package/dist/icons/ChevronRight.jsx +0 -41
  200. package/dist/icons/Close.jsx +0 -41
  201. package/dist/icons/Description.jsx +0 -41
  202. package/dist/icons/DoubleChevronLeft.jsx +0 -40
  203. package/dist/icons/DoubleChevronRight.jsx +0 -40
  204. package/dist/icons/Error.jsx +0 -41
  205. package/dist/icons/ExpandLess.jsx +0 -41
  206. package/dist/icons/ExpandMore.jsx +0 -41
  207. package/dist/icons/List.jsx +0 -44
  208. package/dist/icons/Menu.jsx +0 -41
  209. package/dist/icons/PriorityHigh.jsx +0 -42
  210. package/dist/icons/Search.jsx +0 -41
  211. package/dist/icons/index.js +0 -40
@@ -2,60 +2,55 @@ import { useEffect, useRef } from 'react';
2
2
  // @ts-ignore
3
3
  import DSSideNavigation from '@scottish-government/design-system/src/components/side-navigation/side-navigation';
4
4
 
5
- export const List: React.FC<SGDS.Component.SideNavigation.List> = function ({
6
- items,
7
- root
8
- }) {
5
+ const SideNavigationList = function ({
6
+ children,
7
+ isRoot
8
+ }: SGDS.Component.SideNavigation.List) {
9
9
  return (
10
10
  <ul className="ds_side-navigation__list"
11
- id={root ? 'side-navigation-root' : undefined }
11
+ id={isRoot ? 'side-navigation-root' : undefined }
12
12
  >
13
- {items && items.map((item, index: number) => (
14
- <Link
15
- title={item.title}
16
- href={item.href}
17
- items={item.items}
18
- current={item.current}
19
- key={'sidenavitem' + index}
20
- />
21
- ))}
13
+ {children}
22
14
  </ul>
23
15
  );
24
16
  };
25
17
 
26
- export const Link: React.FC<SGDS.Component.SideNavigation.Link> = function ({
27
- current = false,
18
+ const SideNavigationItem = function ({
19
+ children,
28
20
  href,
29
- items,
21
+ current = false,
22
+ linkComponent,
30
23
  title
31
- }) {
24
+ }: SGDS.Component.SideNavigation.Item) {
25
+ const LINK_CLASS = 'ds_side-navigation__link';
26
+
32
27
  return (
33
28
  <li
34
29
  className={[
35
30
  'ds_side-navigation__item',
36
- items && 'ds_side-navigation__item--has-children'
31
+ children && 'ds_side-navigation__item--has-children'
37
32
  ].join(' ')}
38
33
  >
39
34
  {current ?
40
- <span className="ds_side-navigation__link ds_current">{title}</span> :
41
- <a href={href} className="ds_side-navigation__link">{title}</a>
35
+ <span className={LINK_CLASS + ' ds_current'}>{title}</span> :
36
+ linkComponent ? linkComponent({ className: LINK_CLASS, href, children: title }) :
37
+ <a href={href} className={LINK_CLASS}>{title}</a>
42
38
  }
43
39
 
44
- {items && <List items={items} />}
40
+ {children}
45
41
  </li>
46
42
  );
47
43
  };
48
44
 
49
- const SideNavigation: React.FC<SGDS.Component.SideNavigation> = function ({
45
+ const SideNavigation = function ({
50
46
  children,
51
47
  className,
52
- items,
53
48
  ...props
54
- }) {
49
+ }: SGDS.Component.SideNavigation) {
55
50
  const ref = useRef(null);
56
51
 
57
52
  useEffect(() => {
58
- if (ref.current) {
53
+ if (ref.current && children) {
59
54
  new DSSideNavigation(ref.current).init();
60
55
  }
61
56
  }, [ref]);
@@ -77,13 +72,16 @@ const SideNavigation: React.FC<SGDS.Component.SideNavigation> = function ({
77
72
  <span className="ds_side-navigation__expand-indicator"></span>
78
73
  </label>
79
74
 
80
- {items && <List root items={items} />}
75
+ {children}
81
76
  </nav>
82
77
  );
83
78
  };
84
79
 
85
80
  SideNavigation.displayName = 'SideNavigation';
86
- Link.displayName = 'SideNavLink';
87
- List.displayName = 'SideNavList';
81
+ SideNavigationItem.displayName = 'SideNavigation.Item';
82
+ SideNavigationList.displayName = 'SideNavigation.List';
83
+
84
+ SideNavigation.Item = SideNavigationItem;
85
+ SideNavigation.List = SideNavigationList;
88
86
 
89
87
  export default SideNavigation;
@@ -0,0 +1,153 @@
1
+ import { test, expect } from 'vitest';
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import SiteFooter from './SiteFooter';
4
+
5
+ const LINK_HREF = '#cookies';
6
+ const LINK_TEXT = 'Cookies';
7
+
8
+ test('site footer renders correctly', () => {
9
+ render(
10
+ <SiteFooter data-testid="sitefooter">
11
+ <SiteFooter.Links data-testid="sitefooterlinks" />
12
+ <SiteFooter.License data-testid="sitefooterlicense" />
13
+ <SiteFooter.Org data-testid="sitefooterorg" />
14
+ </SiteFooter>
15
+ );
16
+
17
+ const siteFooter = screen.getByTestId('sitefooter');
18
+ const siteFooterWrapper = siteFooter.children[0];
19
+ const siteFooterContent = siteFooterWrapper.children[0];
20
+
21
+ const siteFooterLinksContainer = screen.getByTestId('sitefooterlinks');
22
+ const siteFooterLicenseContainer = screen.getByTestId('sitefooterlicense');
23
+ const siteFooterOrgContainer = screen.getByTestId('sitefooterorg');
24
+
25
+ expect(siteFooter).toHaveClass('ds_site-footer');
26
+ expect(siteFooter.tagName).toEqual('FOOTER');
27
+
28
+ expect(siteFooterWrapper).toHaveClass('ds_wrapper');
29
+ expect(siteFooterWrapper.tagName).toEqual('DIV');
30
+
31
+ expect(siteFooterContent).toHaveClass('ds_site-footer__content');
32
+ expect(siteFooterContent.tagName).toEqual('DIV');
33
+
34
+ expect(siteFooterLinksContainer).toHaveClass('ds_site-footer__site-items');
35
+ expect(siteFooterLinksContainer.tagName).toEqual('UL');
36
+
37
+ expect(siteFooterLicenseContainer).toHaveClass('ds_site-footer__copyright');
38
+ expect(siteFooterLicenseContainer.tagName).toEqual('DIV');
39
+
40
+ expect(siteFooterOrgContainer).toHaveClass('ds_site-footer__org');
41
+ expect(siteFooterOrgContainer.tagName).toEqual('DIV');
42
+ });
43
+
44
+ test('site footer links render correctly', () => {
45
+ render(
46
+ <SiteFooter.Link href={LINK_HREF}>{LINK_TEXT}</SiteFooter.Link>
47
+ );
48
+
49
+ const listItem = screen.getByRole('listitem');
50
+ const link = within(listItem).getByRole('link');
51
+
52
+ expect(listItem).toHaveClass('ds_site-items__item');
53
+ expect(link).toHaveAttribute('href', LINK_HREF);
54
+ expect(link.textContent).toEqual(LINK_TEXT);
55
+ });
56
+
57
+ test('site footer links with custom element render correctly', () => {
58
+ render(
59
+ <SiteFooter.Link href={LINK_HREF} linkComponent={
60
+ ({ className, ...props }) => (
61
+ <span role="link" className={className} {...props}/>
62
+ )}>
63
+ {LINK_TEXT}
64
+ </SiteFooter.Link>
65
+ );
66
+
67
+ const listItem = screen.getByRole('listitem');
68
+ const link = within(listItem).getByRole('link');
69
+
70
+ expect(listItem).toHaveClass('ds_site-items__item');
71
+ expect(link).toHaveAttribute('href', LINK_HREF);
72
+ expect(link.textContent).toEqual(LINK_TEXT);
73
+ expect(link.tagName).toEqual('SPAN');
74
+ });
75
+
76
+ test('site footer links with no href render correctly', () => {
77
+ render(
78
+ <SiteFooter.Link>{LINK_TEXT}</SiteFooter.Link>
79
+ );
80
+
81
+ const listItem = screen.getByRole('listitem');
82
+ const link = within(listItem).queryByRole('link');
83
+
84
+ expect(listItem).toHaveClass('ds_site-items__item');
85
+ expect(listItem.textContent).toEqual(LINK_TEXT);
86
+ expect(link).not.toBeInTheDocument();
87
+ });
88
+
89
+ test('site footer org renders correctly', () => {
90
+ const CHILDREN = 'Foo';
91
+
92
+ render(
93
+ <SiteFooter.Org data-testid="sitefooterorg" title="The Scottish Government" href="https://www.gov.scot/">
94
+ {CHILDREN}
95
+ </SiteFooter.Org>
96
+ );
97
+
98
+ const siteFooterOrgContainer = screen.getByTestId('sitefooterorg');
99
+ const siteFooterOrgLink = within(siteFooterOrgContainer).getByRole('link');
100
+
101
+ expect(siteFooterOrgContainer).toHaveClass('ds_site-footer__org');
102
+ expect(siteFooterOrgContainer.tagName).toEqual('DIV');
103
+
104
+ expect(siteFooterOrgLink).toHaveClass('ds_site-footer__org-link');
105
+ expect(siteFooterOrgLink.tagName).toEqual('A');
106
+ });
107
+
108
+ test('site footer org with image renders correctly', () => {
109
+ const CHILDREN = <img src="foo" alt="Foo" />
110
+
111
+ render(
112
+ <SiteFooter.Org data-testid="sitefooterorg" title="The Scottish Government" href="https://www.gov.scot/">
113
+ {CHILDREN}
114
+ </SiteFooter.Org>
115
+ );
116
+
117
+ const siteFooterOrgContainer = screen.getByTestId('sitefooterorg');
118
+ const siteFooterOrgImage = within(siteFooterOrgContainer).getByRole('img');
119
+
120
+ expect(siteFooterOrgImage).toHaveClass('ds_site-footer__org-logo');
121
+ });
122
+
123
+ test('site footer license renders correctly', () => {
124
+ const CHILDREN = 'Hello';
125
+
126
+ render(
127
+ <SiteFooter.License data-testid="sitefooterlicense">
128
+ {CHILDREN}
129
+ </SiteFooter.License>
130
+ );
131
+
132
+ const siteFooterLicenseContainer = screen.getByTestId('sitefooterlicense');
133
+
134
+ expect(siteFooterLicenseContainer.innerHTML).toEqual(CHILDREN);
135
+ });
136
+
137
+ test('passing additional props', () => {
138
+ render(
139
+ <SiteFooter data-testid="sitefooter" data-test="foo" />
140
+ );
141
+
142
+ const siteFooter = screen.getByTestId('sitefooter');
143
+ expect(siteFooter?.dataset.test).toEqual('foo');
144
+ });
145
+
146
+ test('passing additional CSS classes', () => {
147
+ render(
148
+ <SiteFooter data-testid="sitefooter" className="foo" />
149
+ );
150
+
151
+ const siteFooter = screen.getByTestId('sitefooter');
152
+ expect(siteFooter).toHaveClass('foo');
153
+ });
@@ -0,0 +1,107 @@
1
+ import React, { Children } from 'react';
2
+ import ConditionalWrapper from '../../common/ConditionalWrapper';
3
+
4
+ const License = ({
5
+ children,
6
+ ...props
7
+ }: SGDS.Component.SiteFooter.License) => {
8
+ return (
9
+ <div className="ds_site-footer__copyright" {...props}>
10
+ {children}
11
+ </div>
12
+ );
13
+ }
14
+
15
+ const Links = ({
16
+ children,
17
+ ...props
18
+ }: SGDS.Component.SiteFooter.Links) => {
19
+ return (
20
+ <ul className="ds_site-footer__site-items" {...props}>
21
+ {children}
22
+ </ul>
23
+ );
24
+ }
25
+
26
+ const Link = ({
27
+ children,
28
+ href,
29
+ linkComponent,
30
+ ...props
31
+ }: SGDS.Component.SiteFooter.Link) => {
32
+ function processChildren(children: React.ReactNode) {
33
+ if (linkComponent) {
34
+ return linkComponent({ href, children });
35
+ } else if (href) {
36
+ return <a href={href}>{children}</a>;
37
+ } else {
38
+ return children;
39
+ }
40
+ }
41
+
42
+ return <li className="ds_site-items__item" {...props}>
43
+ {processChildren(children)}
44
+ </li>;
45
+ }
46
+
47
+ const Org = ({
48
+ href,
49
+ title,
50
+ children,
51
+ ...props
52
+ }: SGDS.Component.SiteFooter.Org) => {
53
+ children = Children.map(children, child => {
54
+ let thisChild = child as React.ReactElement<HTMLElement>;
55
+ if (thisChild && ['img', 'svg', 'picture'].includes(thisChild.type as string)) {
56
+ return React.cloneElement(thisChild, { className: 'ds_site-footer__org-logo' });
57
+ } else {
58
+ return child;
59
+ }
60
+ });
61
+
62
+ return (
63
+ <div className="ds_site-footer__org" {...props}>
64
+ <ConditionalWrapper
65
+ condition={typeof href !== 'undefined'}
66
+ wrapper={(children: React.JSX.Element) => <a className="ds_site-footer__org-link" title={title} href={href}>{children}</a>}
67
+ >
68
+ {children}
69
+ </ConditionalWrapper>
70
+ </div>
71
+ );
72
+ }
73
+
74
+ const SiteFooter = ({
75
+ children,
76
+ className,
77
+ ...props
78
+ }: SGDS.Component.SiteFooter) => {
79
+ return (
80
+ <footer
81
+ className={[
82
+ "ds_site-footer",
83
+ className
84
+ ].join(' ')}
85
+ {...props}
86
+ >
87
+ <div className="ds_wrapper">
88
+ <div className="ds_site-footer__content">
89
+ {children}
90
+ </div>
91
+ </div>
92
+ </footer>
93
+ );
94
+ };
95
+
96
+ SiteFooter.Links = Links;
97
+ SiteFooter.Link = Link;
98
+ SiteFooter.License = License;
99
+ SiteFooter.Org = Org;
100
+
101
+ SiteFooter.displayName = 'SiteFooter';
102
+ Links.displayName = 'SiteFooter.Links';
103
+ Link.displayName = 'SiteFooter.Link';
104
+ License.displayName = 'SiteFooter.License';
105
+ Org.displayName = 'SiteFooter.Org';
106
+
107
+ export default SiteFooter;
@@ -7,25 +7,29 @@ import PhaseBanner from '../PhaseBanner/PhaseBanner';
7
7
 
8
8
  test('site header renders correctly (maximal, testing markup structure)', () => {
9
9
  render(
10
- <SiteHeader
11
- logo={{
12
- alt: 'The Scottish Government',
13
- src: './scottish-government.svg'
14
- }}
15
- navigationItems={[
16
- { title: 'About', href: '#about' },
17
- { title: 'Get started', href: '#get-started' },
18
- { title: 'Styles', href: '#styles' },
19
- { title: 'Components', href: '#components' },
20
- { title: 'Patterns', href: '#patterns' },
21
- { title: 'Guidance', href: '#guidance' },
22
- ]}
23
- phaseBanner={{
24
- phaseName: 'Beta'
25
- }}
26
- siteSearch
27
- siteTitle="Design System React"
28
- />
10
+ <SiteHeader>
11
+ <SiteHeader.Brand homeUrl="/" siteTitle="Design System React">
12
+ <img src="./scottish-government.svg" alt="gov.scot" loading="lazy" width="300" height="58" />
13
+ </SiteHeader.Brand>
14
+ <SiteHeader.Navigation>
15
+ <SiteNavigation>
16
+ <SiteNavigation.Item href="#about">About</SiteNavigation.Item>
17
+ <SiteNavigation.Item href="#get-started">Get started</SiteNavigation.Item>
18
+ <SiteNavigation.Item href="#styles">Styles</SiteNavigation.Item>
19
+ <SiteNavigation.Item href="#components" current>Components</SiteNavigation.Item>
20
+ <SiteNavigation.Item href="#patterns">Patterns</SiteNavigation.Item>
21
+ <SiteNavigation.Item href="#guidance">Guidance</SiteNavigation.Item>
22
+ </SiteNavigation>
23
+ </SiteHeader.Navigation>
24
+ <SiteHeader.Search>
25
+ <SiteSearch id="site-header-search"/>
26
+ </SiteHeader.Search>
27
+ <SiteHeader.Phase>
28
+ <PhaseBanner phaseName="Beta">
29
+ This is a new service. Your <a href="#feedback">feedback</a> will help us to improve it.
30
+ </PhaseBanner>
31
+ </SiteHeader.Phase>
32
+ </SiteHeader>
29
33
  );
30
34
 
31
35
  const siteHeader = screen.getByRole('banner');
@@ -37,7 +41,7 @@ test('site header renders correctly (maximal, testing markup structure)', () =>
37
41
  const siteHeaderNavigationMobile = within(siteHeader).getAllByRole('navigation')[0];
38
42
  const siteHeaderNavigationDesktop = within(siteHeader).getAllByRole('navigation')[1];
39
43
  const siteHeaderPhaseBanner = siteHeader.querySelector('.ds_phase-banner');
40
- const siteHeaderSearch = within(siteHeader).getByRole('search').parentElement;
44
+ const siteHeaderSearch = within(siteHeader).getByRole('search').parentElement?.parentElement;
41
45
 
42
46
  expect(siteHeader).toHaveClass('ds_site-header');
43
47
  expect(siteHeaderContentWrapper).toHaveClass('ds_wrapper');
@@ -67,15 +71,12 @@ test('site header renders correctly (maximal, testing markup structure)', () =>
67
71
  });
68
72
 
69
73
  test('site header branding: logo only, default URL', () => {
70
- const LOGO = {
71
- alt: 'The Scottish Government',
72
- src: './scottish-government.svg'
73
- };
74
-
75
74
  render(
76
- <SiteHeader
77
- logo={LOGO}
78
- />
75
+ <SiteHeader>
76
+ <SiteHeader.Brand>
77
+ <img src="./scottish-government.svg" alt="gov.scot" loading="lazy" width="300" height="58" />
78
+ </SiteHeader.Brand>
79
+ </SiteHeader>
79
80
  );
80
81
 
81
82
  const siteHeader = screen.getByRole('banner');
@@ -87,25 +88,22 @@ test('site header branding: logo only, default URL', () => {
87
88
  expect(siteHeaderLogoLink).toHaveAttribute('href', '/');
88
89
 
89
90
  expect(siteHeaderLogoImg).toHaveClass('ds_site-branding__logo-image');
90
- expect(siteHeaderLogoImg).toHaveAttribute('src', LOGO.src);
91
- expect(siteHeaderLogoImg).toHaveAttribute('alt', LOGO.alt);
92
91
 
93
92
  expect(siteHeaderLogoImg.parentElement).toEqual(siteHeaderLogoLink);
94
93
  expect(siteHeaderLogoLink.parentElement).toEqual(siteHeaderBranding);
94
+
95
+ expect(siteHeaderLogoImg).toHaveClass('ds_site-branding__logo-image');
95
96
  });
96
97
 
97
98
  test('site header branding: logo and site title', () => {
98
- const LOGO = {
99
- alt: 'The Scottish Government',
100
- src: './scottish-government.svg'
101
- };
102
99
  const SITE_TITLE_CONTENT = 'Design System React';
103
100
 
104
101
  render(
105
- <SiteHeader
106
- logo={LOGO}
107
- siteTitle={SITE_TITLE_CONTENT}
108
- />
102
+ <SiteHeader>
103
+ <SiteHeader.Brand homeUrl="/" siteTitle={SITE_TITLE_CONTENT}>
104
+ <img src="./scottish-government.svg" alt="gov.scot" loading="lazy" width="300" height="58" />
105
+ </SiteHeader.Brand>
106
+ </SiteHeader>
109
107
  );
110
108
 
111
109
  const siteHeader = screen.getByRole('banner');
@@ -120,64 +118,66 @@ test('site header branding: logo and site title', () => {
120
118
  });
121
119
 
122
120
  test('site header branding: custom link URL', () => {
123
- const LOGO = {
124
- alt: 'The Scottish Government',
125
- href: '/home.aspx',
126
- src: './scottish-government.svg'
127
- };
121
+ const HOME_URL = '/home.aspx';
128
122
 
129
123
  render(
130
- <SiteHeader
131
- logo={LOGO}
132
- />
124
+ <SiteHeader>
125
+ <SiteHeader.Brand homeUrl={HOME_URL}>
126
+ <img src="./scottish-government.svg" alt="gov.scot" loading="lazy" width="300" height="58" />
127
+ </SiteHeader.Brand>
128
+ </SiteHeader>
133
129
  );
134
130
 
135
131
  const siteHeader = screen.getByRole('banner');
136
132
  const siteHeaderLogoLink = within(siteHeader).getByRole('link');
137
133
 
138
- expect(siteHeaderLogoLink).toHaveAttribute('href', LOGO.href);
134
+ expect(siteHeaderLogoLink).toHaveAttribute('href', HOME_URL);
139
135
  });
140
136
 
141
- test('site header with site search', () => {
142
- const SEARCH_PROPS = {
143
- action: 'apple',
144
- autocompleteEndpoint: 'banana',
145
- autocompleteSuggestionMappingFunction: 'cucumber',
146
- className: 'durian',
147
- id: 'eggplant',
148
- method: 'POST',
149
- name: 'guava',
150
- placeholder: 'haw'
151
- };
137
+ test('site header logo link link with custom element', () => {
138
+ const LINK_CONTENT = <img src="./scottish-government.svg" alt="gov.scot" loading="lazy" width="300" height="58" />
152
139
 
153
140
  render(
154
- <>
155
- <SiteHeader siteSearch={SEARCH_PROPS} />
156
- <SiteSearch data-testid="sitesearch" {...SEARCH_PROPS} />
157
- </>
141
+ <SiteHeader>
142
+ <SiteHeader.Brand linkComponent={
143
+ ({ className, ...props }) => (
144
+ <strong role="link" className={className} {...props}/>
145
+ )}>
146
+ {LINK_CONTENT}
147
+ </SiteHeader.Brand>
148
+ </SiteHeader>
158
149
  );
159
150
 
160
- const siteHeader = screen.getByRole('banner');
161
- const siteHeaderSearch = within(siteHeader).getByRole('search')
162
- const siteSearchReference = screen.getByTestId('sitesearch');
151
+ const item = screen.getByRole('banner');
152
+ const link = within(item).getByRole('link');
163
153
 
164
- expect(siteHeaderSearch.outerHTML).toEqual(siteSearchReference.innerHTML);
154
+ expect(link?.tagName).toEqual('STRONG');
165
155
  });
166
156
 
167
157
  test('site header with site navigation', () => {
168
- const NAVIGATION_ITEMS = [
169
- { title: 'About', href: '#about' },
170
- { title: 'Get started', href: '#get-started' },
171
- { title: 'Styles', href: '#styles' },
172
- { title: 'Components', href: '#components' },
173
- { title: 'Patterns', href: '#patterns' },
174
- { title: 'Guidance', href: '#guidance' },
175
- ];
158
+ const NAVIGATION_ITEMS = (
159
+ <>
160
+ <SiteNavigation.Item href="#about">About</SiteNavigation.Item>
161
+ <SiteNavigation.Item href="#get-started">Get started</SiteNavigation.Item>
162
+ <SiteNavigation.Item href="#styles">Styles</SiteNavigation.Item>
163
+ <SiteNavigation.Item href="#components" current>Components</SiteNavigation.Item>
164
+ <SiteNavigation.Item href="#patterns">Patterns</SiteNavigation.Item>
165
+ <SiteNavigation.Item href="#guidance">Guidance</SiteNavigation.Item>
166
+ </>
167
+ );
176
168
 
177
169
  render(
178
170
  <>
179
- <SiteHeader navigationItems={NAVIGATION_ITEMS} />
180
- <SiteNavigation data-testid="sitenavigation" items={NAVIGATION_ITEMS} />
171
+ <SiteHeader>
172
+ <SiteHeader.Navigation>
173
+ <SiteNavigation>
174
+ {NAVIGATION_ITEMS}
175
+ </SiteNavigation>
176
+ </SiteHeader.Navigation>
177
+ </SiteHeader>
178
+ <SiteNavigation data-testid="sitenavigation">
179
+ {NAVIGATION_ITEMS}
180
+ </SiteNavigation>
181
181
  </>
182
182
  );
183
183
 
@@ -212,15 +212,23 @@ test('site header with site navigation', () => {
212
212
  });
213
213
 
214
214
  test('site header with phase banner', () => {
215
- const PHASE_BANNER_PROPS = {
215
+ const PHASE_BANNER = {
216
216
  content: 'My content',
217
217
  phaseName: 'Beta'
218
218
  };
219
219
 
220
220
  render(
221
221
  <>
222
- <SiteHeader phaseBanner={PHASE_BANNER_PROPS} />
223
- <PhaseBanner data-testid="phasebanner" {...PHASE_BANNER_PROPS} />
222
+ <SiteHeader>
223
+ <SiteHeader.Phase>
224
+ <PhaseBanner phaseName={PHASE_BANNER.phaseName}>
225
+ {PHASE_BANNER.content}
226
+ </PhaseBanner>
227
+ </SiteHeader.Phase>
228
+ </SiteHeader>
229
+ <PhaseBanner data-testid="phasebanner" phaseName={PHASE_BANNER.phaseName}>
230
+ {PHASE_BANNER.content}
231
+ </PhaseBanner>
224
232
  </>
225
233
  );
226
234