@scottish-government/designsystem-react 0.7.1 → 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.
- package/@types/common/AbstractNotificationBanner.d.ts +2 -2
- package/@types/common/ActionLink.d.ts +8 -0
- package/@types/common/FileIcon.d.ts +1 -1
- package/@types/common/Icon.d.ts +1 -1
- package/@types/components/Accordion.d.ts +0 -1
- package/@types/components/Breadcrumbs.d.ts +2 -5
- package/@types/components/Checkbox.d.ts +0 -2
- package/@types/components/ConfirmationMessage.d.ts +1 -1
- package/@types/components/ContentsNav.d.ts +4 -6
- package/@types/components/DatePicker.d.ts +1 -1
- package/@types/components/ErrorSummary.d.ts +3 -4
- package/@types/components/NotificationPanel.d.ts +1 -1
- package/@types/components/Pagination.d.ts +5 -4
- package/@types/components/PhaseBanner.d.ts +0 -1
- package/@types/components/Question.d.ts +1 -1
- package/@types/components/RadioButton.d.ts +0 -1
- package/@types/components/Select.d.ts +0 -7
- package/@types/components/SequentialNavigation.d.ts +4 -4
- package/@types/components/SideNavigation.d.ts +4 -5
- package/@types/components/SiteFooter.d.ts +25 -0
- package/@types/components/SiteHeader.d.ts +10 -3
- package/@types/components/SiteNavigation.d.ts +2 -3
- package/@types/components/SkipLinks.d.ts +3 -4
- package/@types/components/SummaryCard.d.ts +0 -2
- package/@types/components/SummaryList.d.ts +0 -13
- package/@types/components/Tabs.d.ts +0 -1
- package/@types/components/Tag.d.ts +1 -3
- package/@types/components/TaskList.d.ts +1 -0
- package/@types/sgds.d.ts +13 -2
- package/CHANGELOG.md +63 -1
- package/dist/common/AbstractNotificationBanner.jsx +8 -6
- package/dist/common/ActionLink.jsx +19 -0
- package/dist/common/FileIcon.jsx +2 -7
- package/dist/common/Icon.jsx +3 -9
- package/dist/components/Accordion/Accordion.jsx +12 -7
- package/dist/components/Breadcrumbs/Breadcrumbs.jsx +20 -15
- package/dist/components/Checkbox/Checkbox.jsx +4 -29
- package/dist/components/Checkbox/CheckboxGroup.jsx +63 -0
- package/dist/components/ContentsNav/ContentsNav.jsx +27 -16
- package/dist/components/CookieBanner/CookieBanner.jsx +1 -0
- package/dist/components/DatePicker/DatePicker.jsx +5 -5
- package/dist/components/ErrorSummary/ErrorSummary.jsx +28 -18
- package/dist/components/NotificationBanner/NotificationBanner.jsx +2 -2
- package/dist/components/Pagination/Pagination.jsx +42 -22
- package/dist/components/PhaseBanner/PhaseBanner.jsx +3 -3
- package/dist/components/Question/Question.jsx +3 -3
- package/dist/components/RadioButton/RadioButton.jsx +7 -17
- package/dist/components/RadioButton/RadioGroup.jsx +21 -0
- package/dist/components/Select/Select.jsx +4 -7
- package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -18
- package/dist/components/SideNavigation/SideNavigation.jsx +17 -16
- package/dist/components/SiteFooter/SiteFooter.jsx +104 -0
- package/dist/components/SiteHeader/SiteHeader.jsx +113 -32
- package/dist/components/SiteNavigation/SiteNavigation.jsx +20 -7
- package/dist/components/SkipLinks/SkipLinks.jsx +10 -10
- package/dist/components/SummaryCard/SummaryCard.jsx +25 -14
- package/dist/components/SummaryList/SummaryList.jsx +65 -47
- package/dist/components/Tabs/Tabs.jsx +6 -6
- package/dist/components/Tag/Tag.jsx +2 -2
- package/dist/components/TaskList/TaskList.jsx +14 -3
- package/dist/components/TextInput/TextInput.jsx +3 -3
- package/dist/components/Textarea/Textarea.jsx +3 -3
- package/dist/hooks/useTracking.js +21 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/context.js +5 -0
- package/package.json +2 -2
- package/src/common/AbstractNotificationBanner.test.tsx +1 -1
- package/src/common/AbstractNotificationBanner.tsx +14 -13
- package/src/common/ActionLink.test.tsx +80 -0
- package/src/common/ActionLink.tsx +27 -0
- package/src/common/ConditionalWrapper.tsx +1 -1
- package/src/common/FileIcon.tsx +7 -11
- package/src/common/HintText.tsx +2 -2
- package/src/common/Icon.tsx +13 -17
- package/src/common/ScreenReaderText.tsx +2 -2
- package/src/common/WrapperTag.tsx +2 -2
- package/src/components/Accordion/Accordion.test.tsx +17 -4
- package/src/components/Accordion/Accordion.tsx +19 -14
- package/src/components/AspectBox/AspectBox.tsx +2 -2
- package/src/components/BackToTop/BackToTop.tsx +2 -2
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +79 -48
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +31 -31
- package/src/components/Button/Button.tsx +2 -2
- package/src/components/Checkbox/Checkbox.test.tsx +1 -96
- package/src/components/Checkbox/Checkbox.tsx +8 -55
- package/src/components/Checkbox/CheckboxGroup.test.tsx +37 -0
- package/src/components/Checkbox/CheckboxGroup.tsx +41 -0
- package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +2 -2
- package/src/components/ContentsNav/ContentsNav.test.tsx +40 -51
- package/src/components/ContentsNav/ContentsNav.tsx +32 -25
- package/src/components/CookieBanner/CookieBanner.tsx +3 -3
- package/src/components/DatePicker/DatePicker.test.tsx +1 -1
- package/src/components/DatePicker/DatePicker.tsx +7 -7
- package/src/components/Details/Details.tsx +2 -2
- package/src/components/ErrorMessage/ErrorMessage.tsx +2 -2
- package/src/components/ErrorSummary/ErrorSummary.test.tsx +40 -34
- package/src/components/ErrorSummary/ErrorSummary.tsx +40 -32
- package/src/components/FileDownload/FileDownload.tsx +2 -2
- package/src/components/HideThisPage/HideThisPage.tsx +2 -2
- package/src/components/InsetText/InsetText.tsx +2 -2
- package/src/components/NotificationBanner/NotificationBanner.tsx +6 -7
- package/src/components/NotificationPanel/NotificationPanel.tsx +2 -2
- package/src/components/PageHeader/PageHeader.tsx +2 -2
- package/src/components/PageMetadata/PageMetadata.tsx +4 -5
- package/src/components/Pagination/Pagination.test.tsx +26 -7
- package/src/components/Pagination/Pagination.tsx +70 -36
- package/src/components/PhaseBanner/PhaseBanner.tsx +4 -5
- package/src/components/Question/Question.test.tsx +1 -1
- package/src/components/Question/Question.tsx +5 -5
- package/src/components/RadioButton/RadioButton.test.tsx +7 -126
- package/src/components/RadioButton/RadioButton.tsx +10 -41
- package/src/components/RadioButton/RadioGroup.test.tsx +65 -0
- package/src/components/RadioButton/RadioGroup.tsx +31 -0
- package/src/components/Select/Select.test.tsx +39 -37
- package/src/components/Select/Select.tsx +7 -22
- package/src/components/SequentialNavigation/SequentialNavigation.test.tsx +32 -21
- package/src/components/SequentialNavigation/SequentialNavigation.tsx +52 -30
- package/src/components/SideNavigation/SideNavigation.test.tsx +39 -85
- package/src/components/SideNavigation/SideNavigation.tsx +27 -29
- package/src/components/SiteFooter/SiteFooter.test.tsx +153 -0
- package/src/components/SiteFooter/SiteFooter.tsx +107 -0
- package/src/components/SiteHeader/SiteHeader.test.tsx +87 -79
- package/src/components/SiteHeader/SiteHeader.tsx +103 -40
- package/src/components/SiteNavigation/SiteNavigation.test.tsx +42 -23
- package/src/components/SiteNavigation/SiteNavigation.tsx +28 -16
- package/src/components/SiteSearch/SiteSearch.tsx +2 -2
- package/src/components/SkipLinks/SkipLinks.test.tsx +22 -10
- package/src/components/SkipLinks/SkipLinks.tsx +16 -15
- package/src/components/SummaryCard/SummaryCard.test.tsx +31 -35
- package/src/components/SummaryCard/SummaryCard.tsx +39 -28
- package/src/components/SummaryList/SummaryList.test.tsx +49 -148
- package/src/components/SummaryList/SummaryList.tsx +54 -92
- package/src/components/Table/Table.tsx +2 -2
- package/src/components/Tabs/Tabs.tsx +14 -15
- package/src/components/Tag/Tag.test.tsx +4 -4
- package/src/components/Tag/Tag.tsx +4 -4
- package/src/components/TaskList/TaskList.test.tsx +26 -0
- package/src/components/TaskList/TaskList.tsx +21 -11
- package/src/components/TextInput/TextInput.test.tsx +1 -1
- package/src/components/TextInput/TextInput.tsx +5 -5
- package/src/components/Textarea/Textarea.test.tsx +1 -1
- package/src/components/Textarea/Textarea.tsx +5 -5
- package/src/components/WarningText/WarningText.tsx +2 -2
- package/src/hooks/useTracking.test.tsx +64 -0
- package/src/hooks/useTracking.ts +19 -0
- package/src/utils/context.ts +3 -0
- package/tsconfig.json +1 -1
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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={
|
|
11
|
+
id={isRoot ? 'side-navigation-root' : undefined }
|
|
12
12
|
>
|
|
13
|
-
{
|
|
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
|
-
|
|
27
|
-
|
|
18
|
+
const SideNavigationItem = function ({
|
|
19
|
+
children,
|
|
28
20
|
href,
|
|
29
|
-
|
|
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
|
-
|
|
31
|
+
children && 'ds_side-navigation__item--has-children'
|
|
37
32
|
].join(' ')}
|
|
38
33
|
>
|
|
39
34
|
{current ?
|
|
40
|
-
<span className=
|
|
41
|
-
|
|
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
|
-
{
|
|
40
|
+
{children}
|
|
45
41
|
</li>
|
|
46
42
|
);
|
|
47
43
|
};
|
|
48
44
|
|
|
49
|
-
const SideNavigation
|
|
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
|
-
{
|
|
75
|
+
{children}
|
|
81
76
|
</nav>
|
|
82
77
|
);
|
|
83
78
|
};
|
|
84
79
|
|
|
85
80
|
SideNavigation.displayName = 'SideNavigation';
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
12
|
-
alt
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
|
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
|
-
|
|
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',
|
|
134
|
+
expect(siteHeaderLogoLink).toHaveAttribute('href', HOME_URL);
|
|
139
135
|
});
|
|
140
136
|
|
|
141
|
-
test('site header with
|
|
142
|
-
const
|
|
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
|
|
156
|
-
|
|
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
|
|
161
|
-
const
|
|
162
|
-
const siteSearchReference = screen.getByTestId('sitesearch');
|
|
151
|
+
const item = screen.getByRole('banner');
|
|
152
|
+
const link = within(item).getByRole('link');
|
|
163
153
|
|
|
164
|
-
expect(
|
|
154
|
+
expect(link?.tagName).toEqual('STRONG');
|
|
165
155
|
});
|
|
166
156
|
|
|
167
157
|
test('site header with site navigation', () => {
|
|
168
|
-
const NAVIGATION_ITEMS =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
180
|
-
|
|
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
|
|
215
|
+
const PHASE_BANNER = {
|
|
216
216
|
content: 'My content',
|
|
217
217
|
phaseName: 'Beta'
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
render(
|
|
221
221
|
<>
|
|
222
|
-
<SiteHeader
|
|
223
|
-
|
|
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
|
|