@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.
Files changed (147) 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/Checkbox/CheckboxGroup.jsx +63 -0
  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
@@ -1,31 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const NextLink = ({ href, title }) => {
4
- return (<div className="ds_sequential-nav__item ds_sequential-nav__item--next">
5
- <a href={href} className="ds_sequential-nav__button ds_sequential-nav__button--right">
6
- <span className="ds_sequential-nav__text" data-label="Next">
7
- {title}
8
- </span>
9
- </a>
3
+ const SeqNavLink = ({ children, href, isPrev, linkComponent, textLabel }) => {
4
+ const LINK_CLASSES = [
5
+ 'ds_sequential-nav__button',
6
+ isPrev ? 'ds_sequential-nav__button--left' : 'ds_sequential-nav__button--right'
7
+ ].join(' ');
8
+ const ITEM_CLASSES = [
9
+ 'ds_sequential-nav__item',
10
+ isPrev ? 'ds_sequential-nav__item--prev' : 'ds_sequential-nav__item--next'
11
+ ].join(' ');
12
+ function processChildren(children) {
13
+ const linkInner = <span className="ds_sequential-nav__text" data-label={textLabel}>{children}</span>;
14
+ if (linkComponent) {
15
+ return linkComponent({ className: LINK_CLASSES, href, children: linkInner });
16
+ }
17
+ else {
18
+ return <a href={href} className={LINK_CLASSES}>{linkInner}</a>;
19
+ }
20
+ }
21
+ return (<div className={ITEM_CLASSES}>
22
+ {processChildren(children)}
10
23
  </div>);
11
24
  };
12
- const PrevLink = ({ href, title, }) => {
13
- return (<div className="ds_sequential-nav__item ds_sequential-nav__item--prev">
14
- <a href={href} className="ds_sequential-nav__button ds_sequential-nav__button--left">
15
- <span className="ds_sequential-nav__text" data-label="Previous">
16
- {title}
17
- </span>
18
- </a>
19
- </div>);
25
+ const NextLink = ({ children, href, linkComponent, textLabel = 'Next' }) => {
26
+ return <SeqNavLink href={href} linkComponent={linkComponent} textLabel={textLabel}>{children}</SeqNavLink>;
27
+ };
28
+ const PreviousLink = ({ children, href, linkComponent, textLabel = 'Previous' }) => {
29
+ return <SeqNavLink href={href} linkComponent={linkComponent} textLabel={textLabel} isPrev>{children}</SeqNavLink>;
20
30
  };
21
- const SequentialNavigation = ({ ariaLabel = 'Article navigation', className, next, previous, ...props }) => {
31
+ const SequentialNavigation = ({ ariaLabel = 'Article navigation', children, className, ...props }) => {
22
32
  return (<nav className={[
23
33
  'ds_sequential-nav',
24
34
  className
25
35
  ].join(' ')} aria-label={ariaLabel} {...props}>
26
- {previous && <PrevLink href={previous.href} title={previous.title}></PrevLink>}
27
- {next && <NextLink href={next.href} title={next.title}></NextLink>}
36
+ {children}
28
37
  </nav>);
29
38
  };
30
39
  SequentialNavigation.displayName = 'SequentialNavigation';
40
+ SequentialNavigation.Next = NextLink;
41
+ SequentialNavigation.Previous = PreviousLink;
42
+ NextLink.displayName = 'SequentialNavigation.Next';
43
+ PreviousLink.displayName = 'SequentialNavigation.Previous';
31
44
  exports.default = SequentialNavigation;
@@ -3,33 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Link = exports.List = void 0;
7
6
  const react_1 = require("react");
8
7
  // @ts-ignore
9
8
  const side_navigation_1 = __importDefault(require("@scottish-government/design-system/src/components/side-navigation/side-navigation"));
10
- const List = function ({ items, root }) {
11
- return (<ul className="ds_side-navigation__list" id={root ? 'side-navigation-root' : undefined}>
12
- {items && items.map((item, index) => (<exports.Link title={item.title} href={item.href} items={item.items} current={item.current} key={'sidenavitem' + index}/>))}
9
+ const SideNavigationList = function ({ children, isRoot }) {
10
+ return (<ul className="ds_side-navigation__list" id={isRoot ? 'side-navigation-root' : undefined}>
11
+ {children}
13
12
  </ul>);
14
13
  };
15
- exports.List = List;
16
- const Link = function ({ current = false, href, items, title }) {
14
+ const SideNavigationItem = function ({ children, href, current = false, linkComponent, title }) {
15
+ const LINK_CLASS = 'ds_side-navigation__link';
17
16
  return (<li className={[
18
17
  'ds_side-navigation__item',
19
- items && 'ds_side-navigation__item--has-children'
18
+ children && 'ds_side-navigation__item--has-children'
20
19
  ].join(' ')}>
21
20
  {current ?
22
- <span className="ds_side-navigation__link ds_current">{title}</span> :
23
- <a href={href} className="ds_side-navigation__link">{title}</a>}
21
+ <span className={LINK_CLASS + ' ds_current'}>{title}</span> :
22
+ linkComponent ? linkComponent({ className: LINK_CLASS, href, children: title }) :
23
+ <a href={href} className={LINK_CLASS}>{title}</a>}
24
24
 
25
- {items && <exports.List items={items}/>}
25
+ {children}
26
26
  </li>);
27
27
  };
28
- exports.Link = Link;
29
- const SideNavigation = function ({ children, className, items, ...props }) {
28
+ const SideNavigation = function ({ children, className, ...props }) {
30
29
  const ref = (0, react_1.useRef)(null);
31
30
  (0, react_1.useEffect)(() => {
32
- if (ref.current) {
31
+ if (ref.current && children) {
33
32
  new side_navigation_1.default(ref.current).init();
34
33
  }
35
34
  }, [ref]);
@@ -43,10 +42,12 @@ const SideNavigation = function ({ children, className, items, ...props }) {
43
42
  <span className="ds_side-navigation__expand-indicator"></span>
44
43
  </label>
45
44
 
46
- {items && <exports.List root items={items}/>}
45
+ {children}
47
46
  </nav>);
48
47
  };
49
48
  SideNavigation.displayName = 'SideNavigation';
50
- exports.Link.displayName = 'SideNavLink';
51
- exports.List.displayName = 'SideNavList';
49
+ SideNavigationItem.displayName = 'SideNavigation.Item';
50
+ SideNavigationList.displayName = 'SideNavigation.List';
51
+ SideNavigation.Item = SideNavigationItem;
52
+ SideNavigation.List = SideNavigationList;
52
53
  exports.default = SideNavigation;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const react_1 = __importStar(require("react"));
40
+ const ConditionalWrapper_1 = __importDefault(require("../../common/ConditionalWrapper"));
41
+ const License = ({ children, ...props }) => {
42
+ return (<div className="ds_site-footer__copyright" {...props}>
43
+ {children}
44
+ </div>);
45
+ };
46
+ const Links = ({ children, ...props }) => {
47
+ return (<ul className="ds_site-footer__site-items" {...props}>
48
+ {children}
49
+ </ul>);
50
+ };
51
+ const Link = ({ children, href, linkComponent, ...props }) => {
52
+ function processChildren(children) {
53
+ if (linkComponent) {
54
+ return linkComponent({ href, children });
55
+ }
56
+ else if (href) {
57
+ return <a href={href}>{children}</a>;
58
+ }
59
+ else {
60
+ return children;
61
+ }
62
+ }
63
+ return <li className="ds_site-items__item" {...props}>
64
+ {processChildren(children)}
65
+ </li>;
66
+ };
67
+ const Org = ({ href, title, children, ...props }) => {
68
+ children = react_1.Children.map(children, child => {
69
+ let thisChild = child;
70
+ if (thisChild && ['img', 'svg', 'picture'].includes(thisChild.type)) {
71
+ return react_1.default.cloneElement(thisChild, { className: 'ds_site-footer__org-logo' });
72
+ }
73
+ else {
74
+ return child;
75
+ }
76
+ });
77
+ return (<div className="ds_site-footer__org" {...props}>
78
+ <ConditionalWrapper_1.default condition={typeof href !== 'undefined'} wrapper={(children) => <a className="ds_site-footer__org-link" title={title} href={href}>{children}</a>}>
79
+ {children}
80
+ </ConditionalWrapper_1.default>
81
+ </div>);
82
+ };
83
+ const SiteFooter = ({ children, className, ...props }) => {
84
+ return (<footer className={[
85
+ "ds_site-footer",
86
+ className
87
+ ].join(' ')} {...props}>
88
+ <div className="ds_wrapper">
89
+ <div className="ds_site-footer__content">
90
+ {children}
91
+ </div>
92
+ </div>
93
+ </footer>);
94
+ };
95
+ SiteFooter.Links = Links;
96
+ SiteFooter.Link = Link;
97
+ SiteFooter.License = License;
98
+ SiteFooter.Org = Org;
99
+ SiteFooter.displayName = 'SiteFooter';
100
+ Links.displayName = 'SiteFooter.Links';
101
+ Link.displayName = 'SiteFooter.Link';
102
+ License.displayName = 'SiteFooter.License';
103
+ Org.displayName = 'SiteFooter.Org';
104
+ exports.default = SiteFooter;
@@ -1,18 +1,101 @@
1
1
  'use client';
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
3
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
38
  };
6
39
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const react_1 = require("react");
40
+ const react_1 = __importStar(require("react"));
8
41
  const Icon_1 = __importDefault(require("../../common/Icon"));
9
- const PhaseBanner_1 = __importDefault(require("../PhaseBanner/PhaseBanner"));
10
42
  const SiteNavigation_1 = __importDefault(require("../SiteNavigation/SiteNavigation"));
11
- const SiteSearch_1 = __importDefault(require("../SiteSearch/SiteSearch"));
12
43
  // @ts-ignore
13
44
  const site_navigation_1 = __importDefault(require("@scottish-government/design-system/src/components/site-navigation/site-navigation"));
14
- const SiteHeader = ({ logo = {}, navigationItems, phaseBanner, siteSearch, siteTitle, ...props }) => {
45
+ const Brand = ({ children, homeUrl = '/', linkComponent, siteTitle }) => {
46
+ function processChildren(children) {
47
+ const image = react_1.default.cloneElement(children, { className: 'ds_site-branding__logo-image' });
48
+ if (linkComponent) {
49
+ return linkComponent({ className: 'ds_site-branding__logo ds_site-branding__link', href: homeUrl, children: image });
50
+ }
51
+ else if (homeUrl) {
52
+ return <a href={homeUrl} className="ds_site-branding__logo ds_site-branding__link">{image}</a>;
53
+ }
54
+ }
55
+ return (<>
56
+ {processChildren(children)}
57
+
58
+ {siteTitle &&
59
+ <div className="ds_site-branding__title">
60
+ {siteTitle}
61
+ </div>}
62
+ </>);
63
+ };
64
+ const Navigation = ({ children }) => {
65
+ return children;
66
+ };
67
+ const Phase = ({ children }) => {
68
+ return children;
69
+ };
70
+ const Search = ({ children }) => {
71
+ return children;
72
+ };
73
+ const SiteHeader = ({ children, logo = {}, navigationItems, phaseBanner, siteSearch, siteTitle, ...props }) => {
15
74
  const mobileMenuRef = (0, react_1.useRef)(null);
75
+ let branding;
76
+ let navigation;
77
+ let mobileNavigation;
78
+ let phase;
79
+ let search;
80
+ // assign to slots
81
+ react_1.Children.forEach(children, (child) => {
82
+ const thisChild = child;
83
+ if (thisChild && thisChild.type === Brand) {
84
+ branding = thisChild;
85
+ }
86
+ else if (thisChild && thisChild.type === Navigation) {
87
+ navigation = thisChild;
88
+ if (thisChild.props.children.type === SiteNavigation_1.default) {
89
+ mobileNavigation = react_1.default.cloneElement(thisChild.props.children, { className: 'ds_site-navigation--mobile', id: 'mobile-navigation', ref: mobileMenuRef });
90
+ }
91
+ }
92
+ else if (thisChild && thisChild.type === Phase) {
93
+ phase = thisChild;
94
+ }
95
+ else if (thisChild && thisChild.type === Search) {
96
+ search = thisChild;
97
+ }
98
+ });
16
99
  (0, react_1.useEffect)(() => {
17
100
  if (mobileMenuRef.current) {
18
101
  new site_navigation_1.default(mobileMenuRef.current).init();
@@ -22,47 +105,45 @@ const SiteHeader = ({ logo = {}, navigationItems, phaseBanner, siteSearch, siteT
22
105
  <div className="ds_wrapper">
23
106
  <div className="ds_site-header__content">
24
107
  <div className="ds_site-branding">
25
- {logo &&
26
- <a className="ds_site-branding__logo ds_site-branding__link" href={logo.href ? logo.href : '/'}>
27
- <img className="ds_site-branding__logo-image" src={logo.src} alt={logo.alt}/>
28
- </a>}
29
-
30
- {siteTitle && <div className="ds_site-branding__title">
31
- {siteTitle}
32
- </div>}
108
+ {branding}
33
109
  </div>
34
110
 
35
- {navigationItems &&
36
- <div className="ds_site-header__controls">
37
- <label aria-controls="mobile-navigation" className="ds_site-header__control js-toggle-menu" htmlFor="menu">
38
- <span className="ds_site-header__control-text">Menu</span>
39
- <Icon_1.default fill className="ds_site-header__control-icon" icon="Menu" aria-hidden="true"/>
40
- <Icon_1.default fill className="ds_site-header__control-icon ds_site-header__control-icon--active-icon" icon="Close" aria-hidden="true"/>
41
- </label>
42
- </div>}
111
+ {mobileNavigation &&
112
+ <>
113
+ <div className="ds_site-header__controls">
114
+ <label aria-controls="mobile-navigation" className="ds_site-header__control js-toggle-menu" htmlFor="menu">
115
+ <span className="ds_site-header__control-text">Menu</span>
116
+ <Icon_1.default fill className="ds_site-header__control-icon" icon="Menu" aria-hidden="true"/>
117
+ <Icon_1.default fill className="ds_site-header__control-icon ds_site-header__control-icon--active-icon" icon="Close" aria-hidden="true"/>
118
+ </label>
119
+ </div>
120
+
121
+ <input className="ds_site-navigation__toggle" id="menu" type="checkbox"/>
122
+ </>}
43
123
 
44
- {navigationItems &&
45
- <input className="ds_site-navigation__toggle" id="menu" type="checkbox"/>}
46
- {navigationItems &&
47
- <SiteNavigation_1.default id="mobile-navigation" className="ds_site-navigation--mobile" items={navigationItems} ref={mobileMenuRef}/>}
124
+ {mobileNavigation}
48
125
 
49
- {siteSearch &&
50
- <SiteSearch_1.default className="ds_site-header__search" {...siteSearch}/>}
126
+ <div className="ds_site-header__search">{search}</div>
51
127
  </div>
52
128
  </div>
53
129
 
54
- {phaseBanner &&
55
- <PhaseBanner_1.default phaseName={phaseBanner.phaseName}>
56
- {phaseBanner.content}
57
- </PhaseBanner_1.default>}
130
+ {phase}
58
131
 
59
- {navigationItems &&
132
+ {navigation &&
60
133
  <div className="ds_site-header__navigation">
61
134
  <div className="ds_wrapper">
62
- <SiteNavigation_1.default items={navigationItems}/>
135
+ {navigation}
63
136
  </div>
64
137
  </div>}
65
138
  </header>);
66
139
  };
140
+ SiteHeader.Brand = Brand;
141
+ SiteHeader.Navigation = Navigation;
142
+ SiteHeader.Phase = Phase;
143
+ SiteHeader.Search = Search;
67
144
  SiteHeader.displayName = 'SiteHeader';
145
+ Brand.displayName = 'SiteHeader.Brand';
146
+ Navigation.displayName = 'SiteHeader.Navigation';
147
+ Phase.displayName = 'SiteHeader.Phase';
148
+ Search.displayName = 'SiteHeader.Search';
68
149
  exports.default = SiteHeader;
@@ -1,22 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const SiteNavLink = ({ current = false, href, title }) => {
3
+ const Item = ({ children, current = false, href, linkComponent }) => {
4
+ const classNames = ['ds_site-navigation__link'];
5
+ let ariaCurrent;
6
+ if (current) {
7
+ classNames.push('ds_current');
8
+ ariaCurrent = 'page';
9
+ }
10
+ function processChildren(children) {
11
+ if (linkComponent) {
12
+ return linkComponent({ className: classNames.join(' '), href, children });
13
+ }
14
+ else if (href) {
15
+ return <a href={href} aria-current={ariaCurrent ? ariaCurrent : undefined} className={classNames.join(' ')}>{children}</a>;
16
+ }
17
+ }
4
18
  return (<li className="ds_site-navigation__item">
5
- <a href={href} className={[
6
- 'ds_site-navigation__link',
7
- current ? 'ds_current' : undefined
8
- ].join(' ')}>{title}</a>
19
+ {processChildren(children)}
9
20
  </li>);
10
21
  };
11
- const SiteNavigation = ({ className, items, ...props }) => {
22
+ const SiteNavigation = ({ children, className, ...props }) => {
12
23
  return (<nav className={[
13
24
  'ds_site-navigation',
14
25
  className
15
26
  ].join(' ')} {...props}>
16
27
  <ul className="ds_site-navigation__list">
17
- {items && items.map((item, index) => (<SiteNavLink current={item.current} href={item.href} title={item.title} key={`link-${index}`}/>))}
28
+ {children}
18
29
  </ul>
19
30
  </nav>);
20
31
  };
21
32
  SiteNavigation.displayName = 'SiteNavigation';
33
+ SiteNavigation.Item = Item;
34
+ Item.displayName = 'SiteNavigation.Item';
22
35
  exports.default = SiteNavigation;
@@ -1,21 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SkipLink = void 0;
4
- const SkipLink = ({ targetId, title }) => {
3
+ const Link = ({ children, fragmentId }) => {
5
4
  return (<li className="ds_skip-links__item">
6
- <a href={`#${targetId}`} className="ds_skip-links__link">{title}</a>
5
+ <a href={`#${fragmentId}`} className="ds_skip-links__link">{children}</a>
7
6
  </li>);
8
7
  };
9
- exports.SkipLink = SkipLink;
10
- const SkipLinks = ({ items, mainContentId = 'main-content', mainLinkText = 'Skip to main content', ...props }) => {
11
- return (<div className="ds_skip-links" {...props}>
8
+ const SkipLinks = ({ children, mainContentId = 'main-content', mainLinkText = 'Skip to main content', isStatic, ...props }) => {
9
+ return (<div className={[
10
+ 'ds_skip-links',
11
+ isStatic && 'ds_skip-links--static',
12
+ ].join(' ')} {...props}>
12
13
  <ul className="ds_skip-links__list">
13
- <exports.SkipLink title={mainLinkText} targetId={mainContentId}/>
14
-
15
- {items && items.map((item, index) => (<exports.SkipLink title={item.title} targetId={item.targetId} key={`skiplink-${index}`}/>))}
14
+ {children ? children : <Link fragmentId={mainContentId}>{mainLinkText}</Link>}
16
15
  </ul>
17
16
  </div>);
18
17
  };
19
18
  SkipLinks.displayName = 'SkipLinks';
20
- exports.SkipLink.displayName = 'SkipLink';
19
+ Link.displayName = 'SkipLink';
20
+ SkipLinks.Link = Link;
21
21
  exports.default = SkipLinks;
@@ -36,15 +36,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- const SummaryList_1 = __importStar(require("../SummaryList/SummaryList"));
39
+ const react_1 = __importStar(require("react"));
40
+ const ActionLink_1 = __importDefault(require("../../common/ActionLink"));
41
+ const ConditionalWrapper_1 = __importDefault(require("../../common/ConditionalWrapper"));
40
42
  const WrapperTag_1 = __importDefault(require("../../common/WrapperTag"));
41
- function convertToSlug(string) {
42
- return string.toLowerCase()
43
- .replace(/[^\w ]+/g, "")
44
- .replace(/ +/g, "-");
45
- }
46
- const SummaryCard = ({ actions, className, headingLevel = 'h3', items, title, ...props }) => {
47
- const describedById = `summary-card-${convertToSlug(title)}`;
43
+ const SummaryCard = ({ children, className, headingLevel = 'h3', title, ...props }) => {
44
+ let actions = [];
45
+ let remainingChildren = [];
46
+ const describedById = (0, react_1.useId)();
47
+ react_1.Children.forEach(children, (child) => {
48
+ const thisChild = child;
49
+ if (thisChild && thisChild.type === ActionLink_1.default) {
50
+ actions.push(react_1.default.cloneElement(thisChild, { describedby: describedById }));
51
+ }
52
+ else {
53
+ remainingChildren.push(thisChild);
54
+ }
55
+ });
48
56
  return (<div className={[
49
57
  'ds_summary-card',
50
58
  className
@@ -52,16 +60,19 @@ const SummaryCard = ({ actions, className, headingLevel = 'h3', items, title, ..
52
60
  <div className="ds_summary-card__header">
53
61
  <WrapperTag_1.default className="ds_summary-card__header-title" id={describedById} tagName={headingLevel}>{title}</WrapperTag_1.default>
54
62
 
55
- <ul className="ds_summary-card__actions-list">
56
- {actions && actions.map((action, index) => (<li className="ds_summary-card__actions-list-item" key={'summarylistaction' + index}>
57
- <SummaryList_1.Action describedby={describedById} href={action.href} onclick={action.onclick} title={action.title}/>
58
- </li>))}
59
- </ul>
63
+ {actions &&
64
+ <ConditionalWrapper_1.default condition={actions.length > 1} wrapper={(children) => <ul className="ds_summary-card__actions-list">{children}</ul>}>
65
+ {actions && actions.map((action, index) => (<ConditionalWrapper_1.default condition={actions.length > 1} wrapper={(children) => <li className="ds_summary-card__actions-list-item">{children}</li>} key={'action' + index}>
66
+ {action}
67
+ </ConditionalWrapper_1.default>))}
68
+ </ConditionalWrapper_1.default>}
60
69
  </div>
61
70
  <div className="ds_summary-card__content">
62
- <SummaryList_1.default items={items}/>
71
+ {remainingChildren}
63
72
  </div>
64
73
  </div>);
65
74
  };
66
75
  SummaryCard.displayName = 'SummaryCard';
76
+ SummaryCard.Action = ActionLink_1.default;
77
+ SummaryCard.Action.displayName = 'SummaryCard.Action';
67
78
  exports.default = SummaryCard;