@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.
Files changed (140) 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/Breadcrumbs.d.ts +2 -5
  6. package/@types/components/Checkbox.d.ts +0 -2
  7. package/@types/components/ConfirmationMessage.d.ts +1 -1
  8. package/@types/components/ContentsNav.d.ts +4 -6
  9. package/@types/components/DatePicker.d.ts +1 -1
  10. package/@types/components/ErrorSummary.d.ts +3 -4
  11. package/@types/components/NotificationPanel.d.ts +1 -1
  12. package/@types/components/Pagination.d.ts +5 -4
  13. package/@types/components/PhaseBanner.d.ts +0 -1
  14. package/@types/components/Question.d.ts +1 -1
  15. package/@types/components/RadioButton.d.ts +0 -1
  16. package/@types/components/Select.d.ts +0 -7
  17. package/@types/components/SequentialNavigation.d.ts +4 -4
  18. package/@types/components/SideNavigation.d.ts +4 -5
  19. package/@types/components/SiteFooter.d.ts +25 -0
  20. package/@types/components/SiteHeader.d.ts +10 -3
  21. package/@types/components/SiteNavigation.d.ts +2 -3
  22. package/@types/components/SkipLinks.d.ts +3 -4
  23. package/@types/components/SummaryCard.d.ts +0 -2
  24. package/@types/components/SummaryList.d.ts +0 -13
  25. package/@types/components/Tabs.d.ts +0 -1
  26. package/@types/components/Tag.d.ts +1 -3
  27. package/@types/components/TaskList.d.ts +1 -0
  28. package/@types/sgds.d.ts +13 -2
  29. package/CHANGELOG.md +63 -1
  30. package/dist/common/AbstractNotificationBanner.jsx +8 -6
  31. package/dist/common/ActionLink.jsx +19 -0
  32. package/dist/common/FileIcon.jsx +2 -7
  33. package/dist/common/Icon.jsx +3 -9
  34. package/dist/components/Accordion/Accordion.jsx +2 -2
  35. package/dist/components/Breadcrumbs/Breadcrumbs.jsx +20 -15
  36. package/dist/components/Checkbox/Checkbox.jsx +2 -30
  37. package/dist/components/Checkbox/CheckboxGroup.jsx +69 -0
  38. package/dist/components/ContentsNav/ContentsNav.jsx +27 -16
  39. package/dist/components/CookieBanner/CookieBanner.jsx +1 -0
  40. package/dist/components/DatePicker/DatePicker.jsx +5 -5
  41. package/dist/components/ErrorSummary/ErrorSummary.jsx +28 -18
  42. package/dist/components/NotificationBanner/NotificationBanner.jsx +2 -2
  43. package/dist/components/Pagination/Pagination.jsx +42 -22
  44. package/dist/components/PhaseBanner/PhaseBanner.jsx +3 -3
  45. package/dist/components/Question/Question.jsx +3 -3
  46. package/dist/components/RadioButton/RadioButton.jsx +3 -17
  47. package/dist/components/RadioButton/RadioGroup.jsx +61 -0
  48. package/dist/components/Select/Select.jsx +4 -7
  49. package/dist/components/SequentialNavigation/SequentialNavigation.jsx +31 -18
  50. package/dist/components/SideNavigation/SideNavigation.jsx +17 -16
  51. package/dist/components/SiteFooter/SiteFooter.jsx +104 -0
  52. package/dist/components/SiteHeader/SiteHeader.jsx +113 -32
  53. package/dist/components/SiteNavigation/SiteNavigation.jsx +20 -7
  54. package/dist/components/SkipLinks/SkipLinks.jsx +10 -10
  55. package/dist/components/SummaryCard/SummaryCard.jsx +25 -14
  56. package/dist/components/SummaryList/SummaryList.jsx +65 -47
  57. package/dist/components/Tabs/Tabs.jsx +6 -6
  58. package/dist/components/Tag/Tag.jsx +2 -2
  59. package/dist/components/TaskList/TaskList.jsx +14 -3
  60. package/dist/components/TextInput/TextInput.jsx +3 -3
  61. package/dist/components/Textarea/Textarea.jsx +3 -3
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +1 -1
  64. package/src/common/AbstractNotificationBanner.test.tsx +1 -1
  65. package/src/common/AbstractNotificationBanner.tsx +14 -13
  66. package/src/common/ActionLink.test.tsx +80 -0
  67. package/src/common/ActionLink.tsx +27 -0
  68. package/src/common/ConditionalWrapper.tsx +1 -1
  69. package/src/common/FileIcon.tsx +7 -11
  70. package/src/common/HintText.tsx +2 -2
  71. package/src/common/Icon.tsx +13 -17
  72. package/src/common/ScreenReaderText.tsx +2 -2
  73. package/src/common/WrapperTag.tsx +2 -2
  74. package/src/components/Accordion/Accordion.test.tsx +1 -1
  75. package/src/components/Accordion/Accordion.tsx +6 -7
  76. package/src/components/AspectBox/AspectBox.tsx +2 -2
  77. package/src/components/BackToTop/BackToTop.tsx +2 -2
  78. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +79 -47
  79. package/src/components/Breadcrumbs/Breadcrumbs.tsx +31 -31
  80. package/src/components/Button/Button.tsx +2 -2
  81. package/src/components/Checkbox/Checkbox.test.tsx +1 -96
  82. package/src/components/Checkbox/Checkbox.tsx +3 -55
  83. package/src/components/Checkbox/CheckboxGroup.test.tsx +37 -0
  84. package/src/components/Checkbox/CheckboxGroup.tsx +46 -0
  85. package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +2 -2
  86. package/src/components/ContentsNav/ContentsNav.test.tsx +40 -51
  87. package/src/components/ContentsNav/ContentsNav.tsx +32 -25
  88. package/src/components/CookieBanner/CookieBanner.tsx +3 -3
  89. package/src/components/DatePicker/DatePicker.test.tsx +1 -1
  90. package/src/components/DatePicker/DatePicker.tsx +7 -7
  91. package/src/components/Details/Details.tsx +2 -2
  92. package/src/components/ErrorMessage/ErrorMessage.tsx +2 -2
  93. package/src/components/ErrorSummary/ErrorSummary.test.tsx +40 -34
  94. package/src/components/ErrorSummary/ErrorSummary.tsx +40 -32
  95. package/src/components/FileDownload/FileDownload.tsx +2 -2
  96. package/src/components/HideThisPage/HideThisPage.tsx +2 -2
  97. package/src/components/InsetText/InsetText.tsx +2 -2
  98. package/src/components/NotificationBanner/NotificationBanner.tsx +6 -7
  99. package/src/components/NotificationPanel/NotificationPanel.tsx +2 -2
  100. package/src/components/PageHeader/PageHeader.tsx +2 -2
  101. package/src/components/PageMetadata/PageMetadata.tsx +4 -5
  102. package/src/components/Pagination/Pagination.test.tsx +26 -7
  103. package/src/components/Pagination/Pagination.tsx +70 -36
  104. package/src/components/PhaseBanner/PhaseBanner.tsx +4 -5
  105. package/src/components/Question/Question.test.tsx +1 -1
  106. package/src/components/Question/Question.tsx +5 -5
  107. package/src/components/RadioButton/RadioButton.test.tsx +7 -126
  108. package/src/components/RadioButton/RadioButton.tsx +4 -41
  109. package/src/components/RadioButton/RadioGroup.test.tsx +65 -0
  110. package/src/components/RadioButton/RadioGroup.tsx +38 -0
  111. package/src/components/Select/Select.test.tsx +39 -37
  112. package/src/components/Select/Select.tsx +7 -22
  113. package/src/components/SequentialNavigation/SequentialNavigation.test.tsx +32 -21
  114. package/src/components/SequentialNavigation/SequentialNavigation.tsx +52 -30
  115. package/src/components/SideNavigation/SideNavigation.test.tsx +39 -85
  116. package/src/components/SideNavigation/SideNavigation.tsx +27 -29
  117. package/src/components/SiteFooter/SiteFooter.test.tsx +153 -0
  118. package/src/components/SiteFooter/SiteFooter.tsx +107 -0
  119. package/src/components/SiteHeader/SiteHeader.test.tsx +87 -79
  120. package/src/components/SiteHeader/SiteHeader.tsx +103 -40
  121. package/src/components/SiteNavigation/SiteNavigation.test.tsx +42 -23
  122. package/src/components/SiteNavigation/SiteNavigation.tsx +28 -16
  123. package/src/components/SiteSearch/SiteSearch.tsx +2 -2
  124. package/src/components/SkipLinks/SkipLinks.test.tsx +22 -10
  125. package/src/components/SkipLinks/SkipLinks.tsx +16 -15
  126. package/src/components/SummaryCard/SummaryCard.test.tsx +31 -35
  127. package/src/components/SummaryCard/SummaryCard.tsx +39 -28
  128. package/src/components/SummaryList/SummaryList.test.tsx +49 -148
  129. package/src/components/SummaryList/SummaryList.tsx +54 -92
  130. package/src/components/Table/Table.tsx +2 -2
  131. package/src/components/Tabs/Tabs.tsx +14 -15
  132. package/src/components/Tag/Tag.test.tsx +4 -4
  133. package/src/components/Tag/Tag.tsx +4 -4
  134. package/src/components/TaskList/TaskList.test.tsx +26 -0
  135. package/src/components/TaskList/TaskList.tsx +21 -11
  136. package/src/components/TextInput/TextInput.test.tsx +1 -1
  137. package/src/components/TextInput/TextInput.tsx +5 -5
  138. package/src/components/Textarea/Textarea.test.tsx +1 -1
  139. package/src/components/Textarea/Textarea.tsx +5 -5
  140. package/src/components/WarningText/WarningText.tsx +2 -2
@@ -1,28 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const Breadcrumb = ({ hidden, href, title }) => {
3
+ const BreadcrumbItem = ({ children, isHidden, href, linkComponent, ...props }) => {
4
+ const BREADCRUMB_LINK_CLASSNAME = 'ds_breadcrumbs__link';
5
+ function processChildren(children) {
6
+ if (linkComponent) {
7
+ return linkComponent({ className: BREADCRUMB_LINK_CLASSNAME, href, children });
8
+ }
9
+ else if (href) {
10
+ return <a href={href} className={BREADCRUMB_LINK_CLASSNAME}>{children}</a>;
11
+ }
12
+ else {
13
+ return children;
14
+ }
15
+ }
4
16
  return (<li className={[
5
17
  'ds_breadcrumbs__item',
6
- hidden && 'visually-hidden'
7
- ].join(' ')}>
8
-
9
- {href ? (<a className="ds_breadcrumbs__link" href={href}>
10
- {title}
11
- </a>) : (title)}
18
+ isHidden && 'visually-hidden'
19
+ ].join(' ')} {...props}>
20
+ {processChildren(children)}
12
21
  </li>);
13
22
  };
14
- /**
15
- * @param {boolean} hideLastItem
16
- * @param {Array} items
17
- * @param {Object} props - Properties for the element
18
- * @returns {JSX.Element} - The element
19
- */
20
- const Breadcrumbs = ({ hideLastItem, items, ...props }) => {
23
+ const Breadcrumbs = ({ children, ...props }) => {
21
24
  return (<nav aria-label="Breadcrumb" {...props}>
22
25
  <ol className="ds_breadcrumbs">
23
- {items && items.map((item, index) => (<Breadcrumb title={item.title} href={item.href} hidden={(hideLastItem) && index + 1 === items.length} key={'breadcrumb' + index}/>))}
26
+ {children}
24
27
  </ol>
25
28
  </nav>);
26
29
  };
27
30
  Breadcrumbs.displayName = 'Breadcrumbs';
31
+ BreadcrumbItem.displayName = 'Breadcrumbs.Item';
32
+ Breadcrumbs.Item = BreadcrumbItem;
28
33
  exports.default = Breadcrumbs;
@@ -3,10 +3,6 @@ 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.CheckboxGroup = exports.Checkbox = void 0;
7
- const react_1 = require("react");
8
- // @ts-ignore
9
- const checkboxes_1 = __importDefault(require("@scottish-government/design-system/src/forms/checkbox/checkboxes"));
10
6
  const HintText_1 = __importDefault(require("../../common/HintText"));
11
7
  const Checkbox = ({ checked, hintText, id, exclusive, label, name, onBlur, onChange, small }) => {
12
8
  const hintTextId = `hint-text-${id}`;
@@ -34,29 +30,5 @@ const Checkbox = ({ checked, hintText, id, exclusive, label, name, onBlur, onCha
34
30
  </div>
35
31
  </>);
36
32
  };
37
- exports.Checkbox = Checkbox;
38
- /**
39
- * @param {Object} props - Properties for the element
40
- * @param {Array} items - Checkboxes
41
- * @param {boolean} small - Use the small display style for all checkboxes
42
- * @returns {JSX.Element} - The element
43
- */
44
- const CheckboxGroup = ({ className, items, small, ...props }) => {
45
- const ref = (0, react_1.useRef)(null);
46
- (0, react_1.useEffect)(() => {
47
- if (ref.current) {
48
- new checkboxes_1.default(ref.current).init();
49
- }
50
- }, [ref]);
51
- return (<div className={[
52
- 'ds_checkboxes',
53
- 'ds_field-group',
54
- className
55
- ].join(' ')} data-module="ds-checkboxes" ref={ref} {...props}>
56
- {items && items.map((item, index) => (<exports.Checkbox exclusive={item.exclusive} checked={item.checked} hintText={item.hintText} id={item.id} key={'checkbox' + index} label={item.label} onBlur={item.onBlur} onChange={item.onChange} small={small || item.small}/>))}
57
- </div>);
58
- };
59
- exports.CheckboxGroup = CheckboxGroup;
60
- exports.Checkbox.displayName = 'Checkbox';
61
- exports.CheckboxGroup.displayName = 'CheckboxGroup';
62
- exports.default = exports.CheckboxGroup;
33
+ Checkbox.displayName = 'Checkbox';
34
+ exports.default = Checkbox;
@@ -0,0 +1,69 @@
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
+ exports.CheckboxGroup = void 0;
40
+ const react_1 = __importStar(require("react"));
41
+ const Checkbox_1 = __importDefault(require("./Checkbox"));
42
+ // @ts-ignore
43
+ const checkboxes_1 = __importDefault(require("@scottish-government/design-system/src/forms/checkbox/checkboxes"));
44
+ const CheckboxGroup = ({ children, className, small, ...props }) => {
45
+ function processChild(child) {
46
+ if (child && child.type === Checkbox_1.default) {
47
+ return react_1.default.cloneElement(child, { small: small });
48
+ }
49
+ else {
50
+ return child;
51
+ }
52
+ }
53
+ const ref = (0, react_1.useRef)(null);
54
+ (0, react_1.useEffect)(() => {
55
+ if (ref.current) {
56
+ new checkboxes_1.default(ref.current).init();
57
+ }
58
+ }, [ref]);
59
+ return (<div className={[
60
+ 'ds_checkboxes',
61
+ 'ds_field-group',
62
+ className
63
+ ].join(' ')} data-module="ds-checkboxes" ref={ref} {...props}>
64
+ {react_1.Children.map(children, child => processChild(child))}
65
+ </div>);
66
+ };
67
+ exports.CheckboxGroup = CheckboxGroup;
68
+ exports.CheckboxGroup.displayName = 'CheckboxGroup';
69
+ exports.default = exports.CheckboxGroup;
@@ -3,31 +3,42 @@ 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 = void 0;
7
- const WrapperTag_1 = __importDefault(require("../../common/WrapperTag"));
8
- const Link = ({ current, href, title }) => {
9
- // determine which HTML tag to use
10
- const tagName = href && !current ? 'a' : 'span';
11
- return (<li aria-current={current && 'page' || undefined} className="ds_contents-nav__item">
12
- <WrapperTag_1.default tagName={tagName} className={[
13
- 'ds_contents-nav__link',
14
- current && 'ds_current'
15
- ].join(' ')} href={!current ? href : undefined}>
16
- {title}
17
- </WrapperTag_1.default>
6
+ const react_1 = __importDefault(require("react"));
7
+ const ContentsNavItem = ({ children, current, href, linkComponent }) => {
8
+ const classNames = ['ds_contents-nav__link'];
9
+ let ariaCurrent;
10
+ if (current) {
11
+ classNames.push('ds_current');
12
+ ariaCurrent = 'page';
13
+ }
14
+ function processChildren(children) {
15
+ if (linkComponent) {
16
+ return linkComponent({ className: classNames.join(' '), href, children });
17
+ }
18
+ else if (href) {
19
+ return <a href={href} aria-current={ariaCurrent ? ariaCurrent : undefined} className={classNames.join(' ')}>{children}</a>;
20
+ }
21
+ else {
22
+ return <span aria-current={ariaCurrent ? ariaCurrent : undefined} className={classNames.join(' ')}>{children}</span>;
23
+ }
24
+ }
25
+ return (<li className="ds_contents-nav__item">
26
+ {processChildren(children)}
18
27
  </li>);
19
28
  };
20
- exports.Link = Link;
21
- const ContentsNav = function ({ className, items, label = 'Pages in this section', title = 'Contents', ...props }) {
22
- return (<nav aria-label={label} className={[
29
+ const ContentsNav = ({ ariaLabel = 'Pages in this section', children, className, title = 'Contents', ...props }) => {
30
+ return (<nav aria-label={ariaLabel} className={[
23
31
  'ds_contents-nav',
24
32
  className
25
33
  ].join(' ')} {...props}>
26
34
  <h2 className="ds_contents-nav__title">{title}</h2>
35
+
27
36
  <ul className="ds_contents-nav__list">
28
- {items && items.map((item, index) => (<exports.Link current={item.current} href={item.href} title={item.title} key={'link' + index}/>))}
37
+ {children}
29
38
  </ul>
30
39
  </nav>);
31
40
  };
32
41
  ContentsNav.displayName = 'ContentsNav';
42
+ ContentsNavItem.displayName = 'ContentsNav.Item';
43
+ ContentsNav.Item = ContentsNavItem;
33
44
  exports.default = ContentsNav;
@@ -18,4 +18,5 @@ const CookieBanner = ({ children, className, title, ...props }) => {
18
18
  };
19
19
  CookieBanner.displayName = 'CookieBanner';
20
20
  CookieBanner.Buttons = AbstractNotificationBanner_1.default.Buttons;
21
+ CookieBanner.Buttons.displayName = 'CookieBanner.Buttons';
21
22
  exports.default = CookieBanner;
@@ -8,7 +8,7 @@ const react_1 = require("react");
8
8
  const date_picker_1 = __importDefault(require("@scottish-government/design-system/src/components/date-picker/date-picker"));
9
9
  const ErrorMessage_1 = __importDefault(require("../ErrorMessage/ErrorMessage"));
10
10
  const TextInput_1 = __importDefault(require("../TextInput/TextInput"));
11
- const DatePicker = ({ className, dateSelectCallback, disabledDates, error, errorMessage, hintText, id, iconPath = './', label, maxDate, minDate, multiple, name, onBlur, onChange, value, width = 'fixed-10', ...props }) => {
11
+ const DatePicker = ({ className, dateSelectCallback, disabledDates, errorMessage, hasError, hintText, id, iconPath = './', label, maxDate, minDate, multiple, name, onBlur, onChange, value, width = 'fixed-10', ...props }) => {
12
12
  const ref = (0, react_1.useRef)(null);
13
13
  (0, react_1.useEffect)(() => {
14
14
  if (ref.current) {
@@ -37,17 +37,17 @@ const DatePicker = ({ className, dateSelectCallback, disabledDates, error, error
37
37
  <legend>{label}</legend>
38
38
  {errorMessage && <ErrorMessage_1.default text={errorMessage}/>}
39
39
  <div>
40
- <TextInput_1.default className="js-datepicker-date" error={!!error} id={id + "-day"} hintText={hintText} label="Day" name={name + "-day"} onBlur={handleBlur} onChange={handleChange} value={value?.split('/')[0]} width="fixed-2"/>
40
+ <TextInput_1.default className="js-datepicker-date" hasError={!!hasError} id={id + "-day"} hintText={hintText} label="Day" name={name + "-day"} onBlur={handleBlur} onChange={handleChange} value={value?.split('/')[0]} width="fixed-2"/>
41
41
  </div>
42
42
 
43
43
  <div>
44
- <TextInput_1.default className="js-datepicker-month" error={!!error} id={id + "-month"} hintText={hintText} label="Month" name={name + "-month"} onBlur={handleBlur} onChange={handleChange} value={value?.split('/')[1]} width="fixed-2"/>
44
+ <TextInput_1.default className="js-datepicker-month" hasError={!!hasError} id={id + "-month"} hintText={hintText} label="Month" name={name + "-month"} onBlur={handleBlur} onChange={handleChange} value={value?.split('/')[1]} width="fixed-2"/>
45
45
  </div>
46
46
 
47
47
  <div>
48
- <TextInput_1.default className="js-datepicker-year" error={!!error} id={id + "-year"} hintText={hintText} label="Year" name={name + "-year"} onBlur={handleBlur} onChange={handleChange} value={value?.split('/')[2]} width="fixed-4"/>
48
+ <TextInput_1.default className="js-datepicker-year" hasError={!!hasError} id={id + "-year"} hintText={hintText} label="Year" name={name + "-year"} onBlur={handleBlur} onChange={handleChange} value={value?.split('/')[2]} width="fixed-4"/>
49
49
  </div>
50
- </fieldset>) : (<TextInput_1.default error={!!error} errorMessage={errorMessage} id={id} hasButton hintText={hintText} label={label} name={name} onBlur={handleBlur} onChange={handleChange} placeholder="dd/mm/yyyy" value={value} width={width}/>))}
50
+ </fieldset>) : (<TextInput_1.default hasError={!!hasError} errorMessage={errorMessage} id={id} hasButton hintText={hintText} label={label} name={name} onBlur={handleBlur} onChange={handleChange} placeholder="dd/mm/yyyy" value={value} width={width}/>))}
51
51
  </div>);
52
52
  };
53
53
  DatePicker.displayName = 'DatePicker';
@@ -1,27 +1,37 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ConditionalWrapper_1 = __importDefault(require("../../common/ConditionalWrapper"));
7
- const Error = ({ fragmentId, title }) => {
3
+ const react_1 = require("react");
4
+ const ErrorSummaryItem = ({ children, fragmentId, linkComponent }) => {
5
+ const HREF = '#' + fragmentId;
6
+ function processChildren(children) {
7
+ if (linkComponent) {
8
+ return linkComponent({ className: '', href: HREF, children });
9
+ }
10
+ else if (fragmentId) {
11
+ return <a href={HREF}>{children}</a>;
12
+ }
13
+ else {
14
+ return children;
15
+ }
16
+ }
8
17
  return (<li>
9
- <ConditionalWrapper_1.default condition={!!fragmentId} wrapper={() => <a href={`#${fragmentId}`}>{title}</a>}>{title}</ConditionalWrapper_1.default>
18
+ {processChildren(children)}
10
19
  </li>);
11
20
  };
12
- const ErrorSummary = ({ className, errors, title = 'There is a problem', ...props }) => {
13
- return (<>
14
- {errors && errors.length && (<div className={[
15
- 'ds_error-summary',
16
- className
17
- ].join(' ')} aria-labelledby="error-summary-title" role="alert" {...props}>
18
- <h2 className="ds_error-summary__title" id="error-summary-title">{title}</h2>
21
+ const ErrorSummary = ({ children, className, title = 'There is a problem', ...props }) => {
22
+ const summaryTitleId = (0, react_1.useId)();
23
+ return (<div className={[
24
+ 'ds_error-summary',
25
+ className
26
+ ].join(' ')} aria-labelledby={summaryTitleId} role="alert" {...props}>
27
+ <h2 className="ds_error-summary__title" id={summaryTitleId}>{title}</h2>
19
28
 
20
- <ul className="ds_error-summary__list">
21
- {errors && errors.map((error, index) => (<Error fragmentId={error.fragmentId} title={error.title} key={'error' + index}/>))}
22
- </ul>
23
- </div>)}
24
- </>);
29
+ <ul className="ds_error-summary__list">
30
+ {children}
31
+ </ul>
32
+ </div>);
25
33
  };
26
34
  ErrorSummary.displayName = 'ErrorSummary';
35
+ ErrorSummaryItem.displayName = 'ErrorSummary.Item';
36
+ ErrorSummary.Item = ErrorSummaryItem;
27
37
  exports.default = ErrorSummary;
@@ -7,7 +7,7 @@ const react_1 = require("react");
7
7
  const AbstractNotificationBanner_1 = __importDefault(require("../../common/AbstractNotificationBanner"));
8
8
  // @ts-ignore
9
9
  const notification_banner_1 = __importDefault(require("@scottish-government/design-system/src/components/notification-banner/notification-banner"));
10
- const NotificationBanner = ({ children, className, close, icon, iconColour, iconInverse, title, ...props }) => {
10
+ const NotificationBanner = ({ children, className, close, hasColourIcon, hasInverseIcon, icon, title, ...props }) => {
11
11
  const ref = (0, react_1.useRef)(null);
12
12
  (0, react_1.useEffect)(() => {
13
13
  if (ref.current) {
@@ -17,7 +17,7 @@ const NotificationBanner = ({ children, className, close, icon, iconColour, icon
17
17
  return (<AbstractNotificationBanner_1.default className={[
18
18
  'ds_reversed',
19
19
  className
20
- ].join(' ')} close={close} icon={icon ? "PriorityHigh" : undefined} iconColour={iconColour} iconInverse={iconInverse} ref={ref} title="Information" {...props}>
20
+ ].join(' ')} close={close} icon={icon ? "PriorityHigh" : undefined} hasColourIcon={hasColourIcon} hasInverseIcon={hasInverseIcon} ref={ref} title="Information" {...props}>
21
21
  {children}
22
22
  </AbstractNotificationBanner_1.default>);
23
23
  };
@@ -5,19 +5,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Ellipsis = exports.Page = void 0;
7
7
  const Icon_1 = __importDefault(require("../../common/Icon"));
8
- const Page = ({ ariaLabel, current = false, href, onClick, text }) => {
8
+ const Page = ({ ariaLabel, children, className, current = false, href, linkComponent, onClick }) => {
9
9
  function handleClick(event) {
10
10
  if (typeof onClick === 'function') {
11
11
  onClick(event);
12
12
  }
13
13
  }
14
- return (<li className="ds_pagination__item">
15
- <a aria-label={ariaLabel} className={[
14
+ function processChildren(children) {
15
+ const classNames = [
16
16
  'ds_pagination__link',
17
+ className,
17
18
  current ? 'ds_current' : undefined
18
- ].join(' ')} href={href} aria-current={current ? "page" : undefined} onClick={handleClick}>
19
- <span className="ds_pagination__link-label">{text}</span>
20
- </a>
19
+ ].join(' ');
20
+ const linkProps = {
21
+ 'aria-label': ariaLabel,
22
+ href: href,
23
+ onClick: handleClick
24
+ };
25
+ if (current) {
26
+ linkProps['aria-current'] = 'page';
27
+ }
28
+ if (linkComponent) {
29
+ return linkComponent({ className: classNames, children: children, ...linkProps });
30
+ }
31
+ else if (href) {
32
+ return (<a href={href} className={classNames} {...linkProps}>
33
+ {children}
34
+ </a>);
35
+ }
36
+ }
37
+ return (<li className="ds_pagination__item">
38
+ {processChildren(children)}
21
39
  </li>);
22
40
  };
23
41
  exports.Page = Page;
@@ -27,7 +45,7 @@ const Ellipsis = () => {
27
45
  </li>);
28
46
  };
29
47
  exports.Ellipsis = Ellipsis;
30
- const Pagination = ({ ariaLabel = 'Pages', className, onClick, padding = 1, page = 1, pattern = '/search?page=$1', totalPages, ...props }) => {
48
+ const Pagination = ({ ariaLabel = 'Pages', className, onClick, padding = 1, page = 1, pattern = '/search?page=$1', totalPages, linkComponent, ...props }) => {
31
49
  padding = Number(padding);
32
50
  page = Number(page);
33
51
  const minToShow = padding + 2;
@@ -64,31 +82,33 @@ const Pagination = ({ ariaLabel = 'Pages', className, onClick, padding = 1, page
64
82
  className
65
83
  ].join(' ')} aria-label={ariaLabel} {...props}>
66
84
  <ul className="ds_pagination__list">
67
- {page > 1 && (<li className="ds_pagination__item">
68
- <a aria-label="Previous page" className="ds_pagination__link ds_pagination__link--text ds_pagination__link--icon" href={pattern.replace('$1', String(page - 1))} data-search="pagination-previous" onClick={onClick}>
69
- <Icon_1.default icon="ChevronLeft"/>
70
- <span className="ds_pagination__link-label">Previous</span>
71
- </a>
72
- </li>)}
85
+ {page > 1 && (<exports.Page ariaLabel="Previous page" className="ds_pagination__link--text ds_pagination__link--icon" data-search="pagination-previous" href={pattern.replace('$1', String(page - 1))} onClick={onClick}>
86
+ <Icon_1.default icon="ChevronLeft"/>
87
+ <span className="ds_pagination__link-label">Previous</span>
88
+ </exports.Page>)}
73
89
 
74
90
  {includeFirst && (<>
75
- <exports.Page ariaLabel="Page 1" href={pattern.replace('$1', String(1))} onClick={onClick} text="1"/>
91
+ <exports.Page ariaLabel="Page 1" href={pattern.replace('$1', String(1))} onClick={onClick} linkComponent={linkComponent}>
92
+ <span className="ds_pagination__link-label">1</span>
93
+ </exports.Page>
76
94
  <exports.Ellipsis />
77
95
  </>)}
78
96
 
79
- {pages && pages.map((item, index) => (<exports.Page ariaLabel={`Page ${item}`} current={item === page} href={pattern.replace('$1', String(item))} key={`pagination${index}`} onClick={onClick} pattern={pattern} text={item.toString()}/>))}
97
+ {pages && pages.map((item, index) => (<exports.Page ariaLabel={`Page ${item}`} href={pattern.replace('$1', String(item))} current={item === page} key={`pagination${index}`} linkComponent={linkComponent} onClick={onClick} pattern={pattern}>
98
+ <span className="ds_pagination__link-label">{item.toString()}</span>
99
+ </exports.Page>))}
80
100
 
81
101
  {includeLast && (<>
82
102
  <exports.Ellipsis />
83
- <exports.Page ariaLabel={`Page ${totalPages}`} href={pattern.replace('$1', String(totalPages))} onClick={onClick} pattern={pattern} text={totalPages.toString()}/>
103
+ <exports.Page ariaLabel={`Page ${totalPages}`} href={pattern.replace('$1', String(totalPages))} linkComponent={linkComponent} onClick={onClick} pattern={pattern}>
104
+ <span className="ds_pagination__link-label">{totalPages.toString()}</span>
105
+ </exports.Page>
84
106
  </>)}
85
107
 
86
- {page < totalPages && (<li className="ds_pagination__item">
87
- <a aria-label="Next page" className="ds_pagination__link ds_pagination__link--text ds_pagination__link--icon" href={pattern.replace('$1', String(page + 1))} data-search="pagination-next" onClick={onClick}>
88
- <span className="ds_pagination__link-label">Next</span>
89
- <Icon_1.default icon="ChevronRight"/>
90
- </a>
91
- </li>)}
108
+ {page < totalPages && (<exports.Page ariaLabel="Next page" href={pattern.replace('$1', String(page + 1))} className="ds_pagination__link ds_pagination__link--text ds_pagination__link--icon" onClick={onClick}>
109
+ <span className="ds_pagination__link-label">Next</span>
110
+ <Icon_1.default icon="ChevronRight"/>
111
+ </exports.Page>)}
92
112
 
93
113
  </ul>
94
114
  </nav>);
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Tag_1 = __importDefault(require("../Tag/Tag"));
7
- const PhaseBanner = ({ children, className, content, phaseName, ...props }) => {
7
+ const PhaseBanner = ({ children, className, phaseName, ...props }) => {
8
8
  return (<div className={[
9
9
  'ds_phase-banner',
10
10
  className
11
11
  ].join(' ')} {...props}>
12
12
  <div className="ds_wrapper">
13
13
  <p className="ds_phase-banner__content">
14
- {phaseName && <Tag_1.default title={phaseName} className="ds_phase-banner__tag"/>}
14
+ {phaseName && <Tag_1.default className="ds_phase-banner__tag">{phaseName}</Tag_1.default>}
15
15
  <span className="ds_phase-banner__text">
16
- {content ? content : children || "This is a new service"}
16
+ {children || "This is a new service"}
17
17
  </span>
18
18
  </p>
19
19
  </div>
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ErrorMessage_1 = __importDefault(require("../ErrorMessage/ErrorMessage"));
7
7
  const HintText_1 = __importDefault(require("../../common/HintText"));
8
8
  const WrapperTag_1 = __importDefault(require("../../common/WrapperTag"));
9
- const Question = function ({ children, className, error, errorMessage, hintText, legend, tagName = 'div', ...props }) {
9
+ const Question = function ({ children, className, errorMessage, hasError, hintText, legend, tagName = 'div', ...props }) {
10
10
  return (<WrapperTag_1.default tagName={tagName} className={[
11
11
  'ds_question',
12
- error && 'ds_question--error',
12
+ hasError && 'ds_question--error',
13
13
  className
14
14
  ].join(' ')} {...props}>
15
15
  {legend && <legend>{legend}</legend>}
16
16
  {hintText && <HintText_1.default text={hintText}/>}
17
- {error && errorMessage && <ErrorMessage_1.default text={errorMessage}/>}
17
+ {hasError && errorMessage && <ErrorMessage_1.default text={errorMessage}/>}
18
18
  {children}
19
19
  </WrapperTag_1.default>);
20
20
  };
@@ -3,9 +3,8 @@ 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.Radio = void 0;
7
6
  const HintText_1 = __importDefault(require("../../common/HintText"));
8
- const Radio = ({ checked, hintText, id, label, name, onBlur, onChange, small }) => {
7
+ const RadioButton = ({ checked, hintText, id, label, name, onBlur, onChange, small }) => {
9
8
  const hintTextId = `hint-text-${id}`;
10
9
  function handleBlur(event) {
11
10
  if (typeof onBlur === 'function') {
@@ -26,18 +25,5 @@ const Radio = ({ checked, hintText, id, label, name, onBlur, onChange, small })
26
25
  {hintText && <HintText_1.default id={hintTextId} text={hintText}/>}
27
26
  </div>);
28
27
  };
29
- exports.Radio = Radio;
30
- const RadioGroup = ({ className, inline, items, name, small, ...props }) => {
31
- return (<div className={[
32
- 'ds_radios',
33
- 'ds_field-group',
34
- inline && 'ds_field-group--inline',
35
- className
36
- ].join(' ')} {...props}>
37
-
38
- {items && items.map((item, index) => (<exports.Radio checked={item.checked} hintText={item.hintText} id={item.id} key={'radio' + index} label={item.label} name={name} onBlur={item.onBlur} onChange={item.onChange} small={small || item.small}/>))}
39
- </div>);
40
- };
41
- exports.Radio.displayName = 'Radio';
42
- RadioGroup.displayName = 'RadioGroup';
43
- exports.default = RadioGroup;
28
+ RadioButton.displayName = 'RadioButton';
29
+ exports.default = RadioButton;
@@ -0,0 +1,61 @@
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 RadioButton_1 = __importDefault(require("./RadioButton"));
41
+ const RadioGroup = ({ children, className, inline, name, small, ...props }) => {
42
+ function processChild(child) {
43
+ if (child && child.type === RadioButton_1.default) {
44
+ return react_1.default.cloneElement(child, { small: small, name: name });
45
+ }
46
+ else {
47
+ return child;
48
+ }
49
+ }
50
+ return (<div className={[
51
+ 'ds_radios',
52
+ 'ds_field-group',
53
+ inline && 'ds_field-group--inline',
54
+ className
55
+ ].join(' ')} {...props}>
56
+
57
+ {react_1.Children.map(children, child => processChild(child))}
58
+ </div>);
59
+ };
60
+ RadioGroup.displayName = 'RadioGroup';
61
+ exports.default = RadioGroup;
@@ -5,10 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ErrorMessage_1 = __importDefault(require("../ErrorMessage/ErrorMessage"));
7
7
  const HintText_1 = __importDefault(require("../../common/HintText"));
8
- const Option = function ({ text, value }) {
9
- return (<option value={value}>{text}</option>);
10
- };
11
- const Select = function ({ className, defaultValue, error, errorMessage, hintText, id, label, name, onBlur, onChange, options, placeholder, width, ...props }) {
8
+ const Select = function ({ children, className, defaultValue, errorMessage, hasError, hintText, id, label, name, onBlur, onChange, placeholder, width, ...props }) {
12
9
  const errorMessageId = `error-message-${id}`;
13
10
  const hintTextId = `hint-text-${id}`;
14
11
  const describedbys = [];
@@ -36,13 +33,13 @@ const Select = function ({ className, defaultValue, error, errorMessage, hintTex
36
33
  {errorMessage && <ErrorMessage_1.default id={errorMessageId} text={errorMessage}/>}
37
34
  <div className={[
38
35
  "ds_select-wrapper",
39
- error && 'ds_input--error',
36
+ hasError && 'ds_input--error',
40
37
  width && `ds_input--${width}`,
41
38
  className
42
39
  ].join(' ')} {...props}>
43
- <select aria-describedby={describedbys.join(' ')} aria-invalid={error} className="ds_select" defaultValue={defaultValue} id={id} name={name || id} onBlur={handleBlur} onChange={handleChange}>
40
+ <select aria-describedby={describedbys.join(' ')} aria-invalid={hasError} className="ds_select" defaultValue={defaultValue} id={id} name={name || id} onBlur={handleBlur} onChange={handleChange}>
44
41
  <option value="">{placeholder}</option>
45
- {options && options.map((option, index) => (<Option value={option.value} text={option.text} key={`option-${index}`}/>))}
42
+ {children}
46
43
  </select>
47
44
  <span className="ds_select-arrow" aria-hidden="true"></span>
48
45
  </div>