@scottish-government/designsystem-react 0.7.1 → 0.8.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/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 +2 -2
- package/dist/components/Breadcrumbs/Breadcrumbs.jsx +20 -15
- package/dist/components/Checkbox/Checkbox.jsx +2 -30
- package/dist/components/Checkbox/CheckboxGroup.jsx +69 -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 +3 -17
- package/dist/components/RadioButton/RadioGroup.jsx +61 -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/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- 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 +1 -1
- package/src/components/Accordion/Accordion.tsx +6 -7
- package/src/components/AspectBox/AspectBox.tsx +2 -2
- package/src/components/BackToTop/BackToTop.tsx +2 -2
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +79 -47
- 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 +3 -55
- package/src/components/Checkbox/CheckboxGroup.test.tsx +37 -0
- package/src/components/Checkbox/CheckboxGroup.tsx +46 -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 +4 -41
- package/src/components/RadioButton/RadioGroup.test.tsx +65 -0
- package/src/components/RadioButton/RadioGroup.tsx +38 -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
|
@@ -1,27 +1,39 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const Item = ({
|
|
2
|
+
children,
|
|
3
|
+
current = false,
|
|
3
4
|
href,
|
|
4
|
-
|
|
5
|
-
}) => {
|
|
5
|
+
linkComponent
|
|
6
|
+
}: SGDS.Component.SiteNavigation.Item) => {
|
|
7
|
+
const classNames = ['ds_site-navigation__link'];
|
|
8
|
+
let ariaCurrent: React.AriaAttributes["aria-current"];
|
|
9
|
+
|
|
10
|
+
if (current) {
|
|
11
|
+
classNames.push('ds_current');
|
|
12
|
+
ariaCurrent = 'page';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function processChildren(children: React.ReactNode) {
|
|
16
|
+
if (linkComponent) {
|
|
17
|
+
return linkComponent({ className: classNames.join(' '), href, children });
|
|
18
|
+
} else if (href) {
|
|
19
|
+
return <a href={href} aria-current={ariaCurrent ? ariaCurrent : undefined} className={classNames.join(' ')}>{children}</a>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
6
23
|
return (
|
|
7
24
|
<li
|
|
8
25
|
className="ds_site-navigation__item"
|
|
9
26
|
>
|
|
10
|
-
|
|
11
|
-
href={href}
|
|
12
|
-
className={[
|
|
13
|
-
'ds_site-navigation__link',
|
|
14
|
-
current ? 'ds_current' : undefined
|
|
15
|
-
].join(' ')}>{title}</a>
|
|
27
|
+
{processChildren(children)}
|
|
16
28
|
</li>
|
|
17
29
|
);
|
|
18
30
|
};
|
|
19
31
|
|
|
20
|
-
const SiteNavigation
|
|
32
|
+
const SiteNavigation = ({
|
|
33
|
+
children,
|
|
21
34
|
className,
|
|
22
|
-
items,
|
|
23
35
|
...props
|
|
24
|
-
}) => {
|
|
36
|
+
}: SGDS.Component.SiteNavigation) => {
|
|
25
37
|
return (
|
|
26
38
|
<nav
|
|
27
39
|
className={[
|
|
@@ -31,14 +43,14 @@ const SiteNavigation: React.FC<SGDS.Component.SiteNavigation> = ({
|
|
|
31
43
|
{...props}
|
|
32
44
|
>
|
|
33
45
|
<ul className="ds_site-navigation__list">
|
|
34
|
-
{
|
|
35
|
-
<SiteNavLink current={item.current} href={item.href} title={item.title} key={`link-${index}`} />
|
|
36
|
-
))}
|
|
46
|
+
{children}
|
|
37
47
|
</ul>
|
|
38
48
|
</nav>
|
|
39
49
|
);
|
|
40
50
|
};
|
|
41
51
|
|
|
42
52
|
SiteNavigation.displayName = 'SiteNavigation';
|
|
53
|
+
SiteNavigation.Item = Item;
|
|
54
|
+
Item.displayName = 'SiteNavigation.Item';
|
|
43
55
|
|
|
44
56
|
export default SiteNavigation;
|
|
@@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react';
|
|
|
3
3
|
import DSAutocomplete from '@scottish-government/design-system/src/components/autocomplete/autocomplete';
|
|
4
4
|
import Button from '../Button/Button';
|
|
5
5
|
|
|
6
|
-
const SiteSearch
|
|
6
|
+
const SiteSearch = function ({
|
|
7
7
|
action = '/search',
|
|
8
8
|
autocompleteEndpoint,
|
|
9
9
|
autocompleteSuggestionMappingFunction,
|
|
@@ -14,7 +14,7 @@ const SiteSearch: React.FC<SGDS.Component.SiteSearch> = function ({
|
|
|
14
14
|
name = 'q',
|
|
15
15
|
placeholder = 'Search',
|
|
16
16
|
...props
|
|
17
|
-
}) {
|
|
17
|
+
}: SGDS.Component.SiteSearch) {
|
|
18
18
|
const ref = useRef(null);
|
|
19
19
|
const hasAutocomplete = !!autocompleteEndpoint;
|
|
20
20
|
let autocompleteId = hasAutocomplete ? id + '-autocomplete' : '';
|
|
@@ -54,23 +54,35 @@ test('custom link target', () => {
|
|
|
54
54
|
expect(skipLinksLink).toHaveAttribute('href', `#${CUSTOM_ID}`)
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
test('
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
];
|
|
57
|
+
test('explicit links', () => {
|
|
58
|
+
const LINK_ID = 'foo';
|
|
59
|
+
const LINK_TEXT = 'bar';
|
|
61
60
|
|
|
62
61
|
render(
|
|
63
|
-
<SkipLinks
|
|
62
|
+
<SkipLinks>
|
|
63
|
+
<SkipLinks.Link fragmentId={LINK_ID}>{LINK_TEXT}</SkipLinks.Link>
|
|
64
|
+
</SkipLinks>
|
|
64
65
|
);
|
|
65
66
|
|
|
66
67
|
const skipLinksList = screen.getByRole('list');
|
|
67
68
|
const skipLinksListItems = within(skipLinksList).getAllByRole('listitem');
|
|
68
|
-
const skipLinksSecondLink = within(skipLinksList).
|
|
69
|
+
const skipLinksSecondLink = within(skipLinksList).getByRole('link');
|
|
69
70
|
|
|
70
|
-
expect(skipLinksListItems.length).toEqual(
|
|
71
|
-
expect(skipLinksSecondLink).toHaveAttribute('href', `#${
|
|
72
|
-
expect(skipLinksSecondLink.textContent).toEqual(
|
|
73
|
-
})
|
|
71
|
+
expect(skipLinksListItems.length).toEqual(1);
|
|
72
|
+
expect(skipLinksSecondLink).toHaveAttribute('href', `#${LINK_ID}`);
|
|
73
|
+
expect(skipLinksSecondLink.textContent).toEqual(LINK_TEXT);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('static skip links', () => {
|
|
77
|
+
render(
|
|
78
|
+
<SkipLinks isStatic />
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const skipLinksList = screen.getByRole('list');
|
|
82
|
+
const skipLinksContainer = skipLinksList.parentElement;
|
|
83
|
+
|
|
84
|
+
expect(skipLinksContainer).toHaveClass('ds_skip-links--static');
|
|
85
|
+
});
|
|
74
86
|
|
|
75
87
|
test('passing additional props', () => {
|
|
76
88
|
render(
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}) => {
|
|
1
|
+
const Link = ({
|
|
2
|
+
children,
|
|
3
|
+
fragmentId
|
|
4
|
+
}: SGDS.Component.SkipLinks.Link) => {
|
|
5
5
|
return (
|
|
6
6
|
<li
|
|
7
7
|
className="ds_skip-links__item"
|
|
8
8
|
>
|
|
9
|
-
<a href={`#${
|
|
9
|
+
<a href={`#${fragmentId}`} className="ds_skip-links__link">{ children }</a>
|
|
10
10
|
</li>
|
|
11
11
|
);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const SkipLinks
|
|
15
|
-
|
|
14
|
+
const SkipLinks = ({
|
|
15
|
+
children,
|
|
16
16
|
mainContentId = 'main-content',
|
|
17
17
|
mainLinkText = 'Skip to main content',
|
|
18
|
+
isStatic,
|
|
18
19
|
...props
|
|
19
|
-
}) => {
|
|
20
|
+
}: SGDS.Component.SkipLinks) => {
|
|
20
21
|
return (
|
|
21
22
|
<div
|
|
22
|
-
className=
|
|
23
|
+
className={[
|
|
24
|
+
'ds_skip-links',
|
|
25
|
+
isStatic && 'ds_skip-links--static',
|
|
26
|
+
].join(' ')}
|
|
23
27
|
{...props}
|
|
24
28
|
>
|
|
25
29
|
<ul className="ds_skip-links__list">
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
{items && items.map((item, index: number) => (
|
|
29
|
-
<SkipLink title={item.title} targetId={item.targetId} key={`skiplink-${index}`}/>
|
|
30
|
-
))}
|
|
30
|
+
{children ? children : <Link fragmentId={mainContentId}>{mainLinkText}</Link>}
|
|
31
31
|
</ul>
|
|
32
32
|
</div>
|
|
33
33
|
);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
SkipLinks.displayName = 'SkipLinks';
|
|
37
|
-
|
|
37
|
+
Link.displayName = 'SkipLink';
|
|
38
|
+
SkipLinks.Link = Link;
|
|
38
39
|
|
|
39
40
|
export default SkipLinks;
|
|
@@ -30,29 +30,21 @@ const ITEMS = [
|
|
|
30
30
|
const TITLE_TEXT = 'Joe Bloggs';
|
|
31
31
|
|
|
32
32
|
test('summary card renders correctly', () => {
|
|
33
|
-
const DESCRIBEDBY_ID = 'summary-card-joe-bloggs';
|
|
34
|
-
|
|
35
33
|
render(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<SummaryList data-testid="bar" items={ITEMS}/>
|
|
45
|
-
</>
|
|
34
|
+
<SummaryCard
|
|
35
|
+
data-testid="foo"
|
|
36
|
+
title={TITLE_TEXT}
|
|
37
|
+
>
|
|
38
|
+
<SummaryCard.Action href={ACTIONS[0].href}>{ACTIONS[0].title}</SummaryCard.Action>
|
|
39
|
+
<SummaryList data-testid="bar" />
|
|
40
|
+
</SummaryCard>
|
|
46
41
|
);
|
|
47
42
|
|
|
48
43
|
const summaryCard = screen.getByTestId('foo');
|
|
49
44
|
const title = within(summaryCard).getByRole('heading');
|
|
50
45
|
const header = title.parentElement as HTMLElement;
|
|
51
46
|
const content = header?.nextElementSibling as HTMLElement;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const thisList = within(content).getByRole('list');
|
|
55
|
-
const comparisonList = screen.getByTestId('bar');
|
|
47
|
+
const action = within(header).getByRole('link');
|
|
56
48
|
|
|
57
49
|
expect(summaryCard).toHaveClass('ds_summary-card');
|
|
58
50
|
|
|
@@ -60,34 +52,20 @@ test('summary card renders correctly', () => {
|
|
|
60
52
|
expect(header?.tagName).toEqual('DIV');
|
|
61
53
|
|
|
62
54
|
expect(title).toHaveClass('ds_summary-card__header-title');
|
|
63
|
-
expect(title).toHaveAttribute('id', DESCRIBEDBY_ID);
|
|
64
55
|
expect(title?.tagName).toEqual('H3');
|
|
65
56
|
expect(title.textContent).toEqual(TITLE_TEXT);
|
|
66
57
|
|
|
67
|
-
expect(
|
|
68
|
-
expect(actionsList.children.length).toEqual(ACTIONS.length);
|
|
69
|
-
expect(actionsList.children[0]).toHaveClass('ds_summary-card__actions-list-item');
|
|
70
|
-
expect(actionsList.children[0].tagName).toEqual('LI');
|
|
71
|
-
expect(actionsList.children[0].innerHTML).toEqual('<a aria-describedby="summary-card-joe-bloggs" class="ds_link" href="#foo">Change</a>');
|
|
72
|
-
expect(actionsList.children[1].innerHTML).toEqual('<button aria-describedby="summary-card-joe-bloggs" class="ds_link" type="button">Delete</button>');
|
|
73
|
-
|
|
74
|
-
fireEvent.click(actionsList.children[1].children[0]);
|
|
75
|
-
|
|
76
|
-
expect(ONCLICK_FUNCTION).toHaveBeenCalled();
|
|
58
|
+
expect(action).toHaveAttribute('aria-describedby', title.id);
|
|
77
59
|
|
|
78
60
|
expect(content).toHaveClass('ds_summary-card__content');
|
|
79
61
|
expect(content?.tagName).toEqual('DIV');
|
|
80
|
-
|
|
81
|
-
expect(thisList?.innerHTML).toEqual(comparisonList?.innerHTML);
|
|
82
62
|
});
|
|
83
63
|
|
|
84
64
|
test('custom heading level', () => {
|
|
85
65
|
render(
|
|
86
66
|
<SummaryCard
|
|
87
67
|
data-testid="foo"
|
|
88
|
-
actions={ACTIONS}
|
|
89
68
|
headingLevel="h2"
|
|
90
|
-
items={ITEMS}
|
|
91
69
|
title={TITLE_TEXT}
|
|
92
70
|
/>
|
|
93
71
|
);
|
|
@@ -98,12 +76,32 @@ test('custom heading level', () => {
|
|
|
98
76
|
expect(title?.tagName).toEqual('H2');
|
|
99
77
|
});
|
|
100
78
|
|
|
79
|
+
test('summary card with multiple actions renders actions as a list', () => {
|
|
80
|
+
render(
|
|
81
|
+
<SummaryCard
|
|
82
|
+
data-testid="foo"
|
|
83
|
+
title={TITLE_TEXT}
|
|
84
|
+
>
|
|
85
|
+
<SummaryCard.Action href={ACTIONS[0].href}>{ACTIONS[0].title}</SummaryCard.Action>
|
|
86
|
+
<SummaryCard.Action onclick={ACTIONS[1].onclick}>{ACTIONS[1].title}</SummaryCard.Action>
|
|
87
|
+
<SummaryList data-testid="bar" />
|
|
88
|
+
</SummaryCard>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const summaryCard = screen.getByTestId('foo');
|
|
92
|
+
const title = within(summaryCard).getByRole('heading');
|
|
93
|
+
const header = title.parentElement as HTMLElement;
|
|
94
|
+
const actionsList = within(header).getByRole('list')
|
|
95
|
+
|
|
96
|
+
expect(actionsList?.tagName).toEqual('UL');
|
|
97
|
+
expect(actionsList.children[0]).toHaveClass('ds_summary-card__actions-list-item');
|
|
98
|
+
expect(actionsList.children[0].tagName).toEqual('LI');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
101
|
test('passing additional props', () => {
|
|
102
102
|
render(
|
|
103
103
|
<SummaryCard
|
|
104
104
|
data-testid="foo"
|
|
105
|
-
actions={ACTIONS}
|
|
106
|
-
items={ITEMS}
|
|
107
105
|
title={TITLE_TEXT}
|
|
108
106
|
data-test="foo"
|
|
109
107
|
/>
|
|
@@ -117,8 +115,6 @@ test('passing additional CSS classes', () => {
|
|
|
117
115
|
render(
|
|
118
116
|
<SummaryCard
|
|
119
117
|
data-testid="foo"
|
|
120
|
-
actions={ACTIONS}
|
|
121
|
-
items={ITEMS}
|
|
122
118
|
title={TITLE_TEXT}
|
|
123
119
|
className="foo"
|
|
124
120
|
/>
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import WrapperTag from "../../common/WrapperTag";
|
|
1
|
+
import React, { Children, useId } from 'react';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.replace(/ +/g, "-");
|
|
8
|
-
}
|
|
3
|
+
import ActionLink from '../../common/ActionLink';
|
|
4
|
+
import ConditionalWrapper from '../../common/ConditionalWrapper';
|
|
5
|
+
import WrapperTag from "../../common/WrapperTag";
|
|
9
6
|
|
|
10
|
-
const SummaryCard
|
|
11
|
-
|
|
7
|
+
const SummaryCard = ({
|
|
8
|
+
children,
|
|
12
9
|
className,
|
|
13
10
|
headingLevel = 'h3',
|
|
14
|
-
items,
|
|
15
11
|
title,
|
|
16
12
|
...props
|
|
17
|
-
}) => {
|
|
18
|
-
|
|
13
|
+
}: SGDS.Component.SummaryCard) => {
|
|
14
|
+
let actions: any[] = [];
|
|
15
|
+
let remainingChildren: any[] = [];
|
|
16
|
+
|
|
17
|
+
const describedById = useId();
|
|
18
|
+
|
|
19
|
+
Children.forEach(children, (child: React.ReactNode) => {
|
|
20
|
+
const thisChild = child as React.ReactElement<SGDS.Common.ActionLink>;
|
|
21
|
+
if (thisChild && thisChild.type === ActionLink) {
|
|
22
|
+
actions.push(React.cloneElement(thisChild, { describedby: describedById }));
|
|
23
|
+
} else {
|
|
24
|
+
remainingChildren.push(thisChild);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
19
27
|
|
|
20
28
|
return (
|
|
21
29
|
<div
|
|
@@ -32,29 +40,32 @@ const SummaryCard: React.FC<SGDS.Component.SummaryCard> = ({
|
|
|
32
40
|
tagName={headingLevel}
|
|
33
41
|
>{title}</WrapperTag>
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
{actions &&
|
|
44
|
+
<ConditionalWrapper
|
|
45
|
+
condition={actions.length > 1}
|
|
46
|
+
wrapper={(children: React.JSX.Element) => <ul className="ds_summary-card__actions-list">{children}</ul>}
|
|
47
|
+
>
|
|
48
|
+
{actions && actions.map((action, index: number) => (
|
|
49
|
+
<ConditionalWrapper
|
|
50
|
+
condition={actions.length > 1}
|
|
51
|
+
wrapper={(children: React.JSX.Element) => <li className="ds_summary-card__actions-list-item">{children}</li>}
|
|
52
|
+
key={'action' + index}
|
|
53
|
+
>
|
|
54
|
+
{action}
|
|
55
|
+
</ConditionalWrapper>
|
|
56
|
+
))}
|
|
57
|
+
</ConditionalWrapper>
|
|
58
|
+
}
|
|
50
59
|
</div>
|
|
51
60
|
<div className="ds_summary-card__content">
|
|
52
|
-
|
|
61
|
+
{remainingChildren}
|
|
53
62
|
</div>
|
|
54
63
|
</div>
|
|
55
64
|
);
|
|
56
65
|
};
|
|
57
66
|
|
|
58
67
|
SummaryCard.displayName = 'SummaryCard';
|
|
68
|
+
SummaryCard.Action = ActionLink;
|
|
69
|
+
SummaryCard.Action.displayName = 'SummaryCard.Action';
|
|
59
70
|
|
|
60
71
|
export default SummaryCard;
|