@scottish-government/designsystem-react 1.0.0 → 1.1.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 (109) hide show
  1. package/.storybook/sgdsArgTypes.ts +19 -3
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +1 -5
  4. package/dist/common/AbstractNotificationMessage/AbstractNotificationMessage.d.ts +6 -0
  5. package/dist/common/AbstractNotificationMessage/AbstractNotificationMessage.jsx +34 -0
  6. package/dist/common/AbstractNotificationMessage/index.d.ts +1 -0
  7. package/dist/common/AbstractNotificationMessage/index.js +8 -0
  8. package/dist/common/AbstractNotificationMessage/types.d.ts +9 -0
  9. package/dist/common/AbstractNotificationMessage/types.js +2 -0
  10. package/dist/common/WrapperTag/WrapperTag.d.ts +11 -11
  11. package/dist/components/ConfirmationMessage/ConfirmationMessage.d.ts +18 -2
  12. package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +21 -17
  13. package/dist/components/ConfirmationNotification/ConfirmationNotification.d.ts +6 -0
  14. package/dist/components/ConfirmationNotification/ConfirmationNotification.jsx +26 -0
  15. package/dist/components/ConfirmationNotification/index.d.ts +1 -0
  16. package/dist/components/ConfirmationNotification/index.js +8 -0
  17. package/dist/components/CookieBanner/CookieBanner.jsx +2 -2
  18. package/dist/components/ErrorNotification/ErrorNotification.d.ts +6 -0
  19. package/dist/components/ErrorNotification/ErrorNotification.jsx +26 -0
  20. package/dist/components/ErrorNotification/index.d.ts +1 -0
  21. package/dist/components/ErrorNotification/index.js +8 -0
  22. package/dist/components/FileUpload/FileUpload.d.ts +6 -0
  23. package/dist/components/FileUpload/FileUpload.jsx +55 -0
  24. package/dist/components/FileUpload/index.d.ts +1 -0
  25. package/dist/components/FileUpload/index.js +8 -0
  26. package/dist/components/FileUpload/types.d.ts +24 -0
  27. package/dist/components/FileUpload/types.js +2 -0
  28. package/dist/components/InfoNotification/InfoNotification.d.ts +6 -0
  29. package/dist/components/InfoNotification/InfoNotification.jsx +26 -0
  30. package/dist/components/InfoNotification/index.d.ts +1 -0
  31. package/dist/components/InfoNotification/index.js +8 -0
  32. package/dist/components/NotificationBanner/NotificationBanner.jsx +1 -1
  33. package/dist/components/SummaryList/SummaryList.d.ts +1 -1
  34. package/dist/components/WarningNotification/WarningNotification.d.ts +6 -0
  35. package/dist/components/WarningNotification/WarningNotification.jsx +26 -0
  36. package/dist/components/WarningNotification/index.d.ts +1 -0
  37. package/dist/components/WarningNotification/index.js +8 -0
  38. package/dist/components/WarningText/WarningText.jsx +4 -1
  39. package/dist/images/icons/index.d.ts +2 -0
  40. package/dist/images/icons/index.js +5 -1
  41. package/dist/images/icons/info.d.ts +4 -0
  42. package/dist/images/icons/info.jsx +40 -0
  43. package/dist/images/icons/warning.d.ts +4 -0
  44. package/dist/images/icons/warning.jsx +40 -0
  45. package/dist/index.d.ts +4 -0
  46. package/dist/index.js +40 -0
  47. package/dist/shared-types.d.ts +35 -0
  48. package/dist/shared-types.js +2 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -0
  50. package/package.json +22 -16
  51. package/src/common/AbstractNotificationMessage/AbstractNotificationMessage.test.tsx +101 -0
  52. package/src/common/AbstractNotificationMessage/AbstractNotificationMessage.tsx +56 -0
  53. package/src/common/AbstractNotificationMessage/index.ts +1 -0
  54. package/src/common/AbstractNotificationMessage/types.ts +10 -0
  55. package/src/components/Button/Button.stories.tsx +1 -1
  56. package/src/components/Card/Card.tsx +2 -2
  57. package/src/components/ConfirmationMessage/ConfirmationMessage.stories.tsx +11 -3
  58. package/src/components/ConfirmationMessage/ConfirmationMessage.test.tsx +58 -23
  59. package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +32 -25
  60. package/src/components/ConfirmationMessage/confirmationmessage.mdx +17 -0
  61. package/src/components/ConfirmationNotification/ConfirmationNotification.stories.tsx +47 -0
  62. package/src/components/ConfirmationNotification/ConfirmationNotification.test.tsx +101 -0
  63. package/src/components/ConfirmationNotification/ConfirmationNotification.tsx +46 -0
  64. package/src/components/ConfirmationNotification/index.ts +1 -0
  65. package/src/components/CookieBanner/CookieBanner.tsx +1 -1
  66. package/src/components/ErrorNotification/ErrorNotification.stories.tsx +47 -0
  67. package/src/components/ErrorNotification/ErrorNotification.test.tsx +101 -0
  68. package/src/components/ErrorNotification/ErrorNotification.tsx +46 -0
  69. package/src/components/ErrorNotification/index.ts +1 -0
  70. package/src/components/FileDownload/FileDownload.test.tsx +1 -1
  71. package/src/components/FileUpload/FileUpload.stories.tsx +77 -0
  72. package/src/components/FileUpload/FileUpload.test.tsx +185 -0
  73. package/src/components/FileUpload/FileUpload.tsx +87 -0
  74. package/src/components/FileUpload/index.ts +1 -0
  75. package/src/components/FileUpload/types.ts +25 -0
  76. package/src/components/InfoNotification/InfoNotification.stories.tsx +47 -0
  77. package/src/components/InfoNotification/InfoNotification.test.tsx +101 -0
  78. package/src/components/InfoNotification/InfoNotification.tsx +46 -0
  79. package/src/components/InfoNotification/index.ts +1 -0
  80. package/src/components/NotificationBanner/NotificationBanner.tsx +1 -1
  81. package/src/components/SummaryList/SummaryList.tsx +1 -1
  82. package/src/components/TextInput/TextInput.stories.tsx +1 -1
  83. package/src/components/WarningNotification/WarningNotification.stories.tsx +47 -0
  84. package/src/components/WarningNotification/WarningNotification.test.tsx +101 -0
  85. package/src/components/WarningNotification/WarningNotification.tsx +46 -0
  86. package/src/components/WarningNotification/index.ts +1 -0
  87. package/src/components/WarningText/WarningText.tsx +4 -1
  88. package/src/images/icons/arrow_upward.tsx +10 -10
  89. package/src/images/icons/calendar_today.tsx +10 -10
  90. package/src/images/icons/cancel.tsx +8 -8
  91. package/src/images/icons/check_circle.tsx +10 -10
  92. package/src/images/icons/chevron_left.tsx +10 -10
  93. package/src/images/icons/chevron_right.tsx +10 -10
  94. package/src/images/icons/close.tsx +10 -10
  95. package/src/images/icons/description.tsx +10 -10
  96. package/src/images/icons/double_chevron_left.tsx +8 -8
  97. package/src/images/icons/double_chevron_right.tsx +8 -8
  98. package/src/images/icons/error.tsx +10 -10
  99. package/src/images/icons/expand_less.tsx +10 -10
  100. package/src/images/icons/expand_more.tsx +10 -10
  101. package/src/images/icons/index.ts +2 -0
  102. package/src/images/icons/info.tsx +14 -0
  103. package/src/images/icons/list.tsx +13 -13
  104. package/src/images/icons/menu.tsx +10 -10
  105. package/src/images/icons/priority_high.tsx +11 -11
  106. package/src/images/icons/search.tsx +10 -10
  107. package/src/images/icons/warning.tsx +14 -0
  108. package/src/shared-types.ts +1 -1
  109. package/src/components/ConfirmationMessage/types.ts +0 -7
@@ -0,0 +1,56 @@
1
+ import Icon from '../Icon';
2
+ import ScreenReaderText from '../ScreenReaderText';
3
+ import WrapperTag from '../WrapperTag';
4
+ import { AbstractNotificationMessageProps } from './types';
5
+ import clsx from 'clsx';
6
+
7
+ const AbstractNotificationMessage = ({
8
+ ariaLive = 'polite',
9
+ children,
10
+ className,
11
+ headingLevel = 'h3',
12
+ icon,
13
+ isDismissable,
14
+ title,
15
+ ...props
16
+ }: AbstractNotificationMessageProps) => {
17
+
18
+ return (
19
+ <div
20
+ aria-live={ariaLive}
21
+ className={clsx([
22
+ 'ds_notification-message',
23
+ className
24
+ ])}
25
+ data-module="ds-notification-message"
26
+ {...props}
27
+ >
28
+ {icon &&
29
+ <Icon icon={icon} className="ds_notification-message__icon" iconSize="24" />
30
+ }
31
+ <WrapperTag
32
+ className="ds_notification-message__title"
33
+ tagName={headingLevel}
34
+ >
35
+ {title}
36
+ </WrapperTag>
37
+
38
+ {children &&
39
+ <div className="ds_notification-message__body">
40
+ {children}
41
+ </div>
42
+ }
43
+
44
+ {isDismissable &&
45
+ <button type="button" className="ds_notification-message__close js-close-notification-message">
46
+ <ScreenReaderText>Close this notification</ScreenReaderText>
47
+ <Icon isFilled icon="Close" aria-hidden="true" />
48
+ </button>
49
+ }
50
+ </div>
51
+ );
52
+ };
53
+
54
+ AbstractNotificationMessage.displayName = 'AbstractNotificationMessage';
55
+
56
+ export default AbstractNotificationMessage;
@@ -0,0 +1 @@
1
+ export { default } from './AbstractNotificationMessage';
@@ -0,0 +1,10 @@
1
+ import { HeadingLevel, IconName } from '../../shared-types';
2
+
3
+ export interface AbstractNotificationMessageProps extends React.AllHTMLAttributes<HTMLDivElement> {
4
+ ariaLive?: React.AriaAttributes['aria-live'];
5
+ headingLevel?: HeadingLevel;
6
+ icon?: IconName;
7
+ isDismissable?: boolean;
8
+ title?: string;
9
+ ref?: React.Ref<HTMLDivElement>;
10
+ }
@@ -33,7 +33,7 @@ const meta = {
33
33
  },
34
34
  icon: {
35
35
  description: 'Name of the icon component to use',
36
- options: ['ArrowUpward', 'CalendarToday', 'Cancel', 'CheckCircle', 'ChevronLeft', 'ChevronRight', 'Close', 'Description', 'DoubleChevronLeft', 'DoubleChevronRight' ,'Error', 'ExpandLess', 'ExpandMore', 'List', 'PriorityHigh', 'Search'],
36
+ options: ['ArrowUpward', 'CalendarToday', 'Cancel', 'CheckCircle', 'ChevronLeft', 'ChevronRight', 'Close', 'Description', 'DoubleChevronLeft', 'DoubleChevronRight' ,'Error', 'ExpandLess', 'ExpandMore', 'Info', 'List', 'PriorityHigh', 'Search', 'Warning'],
37
37
  control: { type: 'select' },
38
38
  type: 'string'
39
39
  },
@@ -5,7 +5,7 @@ import AspectBox from '../AspectBox';
5
5
  import Metadata from '../PageMetadata';
6
6
  import Tag from '../Tag';
7
7
  import { CardProps, CardHeaderProps, CardMediaProps, CardStatusTagProps } from "./types";
8
- import { HeadingLevel, LinkComponent } from '@/src/shared-types';
8
+ import { HeadingLevel, LinkComponent } from '../../shared-types';
9
9
  import clsx from 'clsx';
10
10
 
11
11
  type CardSettingsContextProps = {
@@ -124,7 +124,7 @@ const CardMedia = ({
124
124
  ...props
125
125
  }: CardMediaProps) => {
126
126
  return (
127
- <div
127
+ <div
128
128
  className={clsx([
129
129
  'ds_card__media',
130
130
  isCover && ratio && 'ds_card__media--cover',
@@ -4,17 +4,19 @@ import argTypes from '../../../.storybook/sgdsArgTypes';
4
4
  import ConfirmationMessage from './ConfirmationMessage';
5
5
 
6
6
  const meta = {
7
- title: 'Components/ConfirmationMessage',
7
+ title: 'Deprecated/ConfirmationMessage',
8
8
  component: ConfirmationMessage,
9
9
  argTypes: {
10
- headingLevel: argTypes.headingLevel(),
11
10
  ariaLive: argTypes.ariaLive(),
12
- children: argTypes.children()
11
+ children: argTypes.children(),
12
+ headingLevel: argTypes.headingLevel(),
13
+ isDismissable: argTypes.boolean()
13
14
  },
14
15
  args: {
15
16
  ariaLive: 'polite',
16
17
  children: (<p>You have added the landlord <strong>John Smith</strong> to the application.</p>),
17
18
  headingLevel: 'h3',
19
+ isDismissable: false,
18
20
  title: 'Landlord added successfully',
19
21
  }
20
22
  } satisfies Meta<typeof ConfirmationMessage>;
@@ -36,3 +38,9 @@ export const DifferentHeadingLevel: Story = {
36
38
  headingLevel: 'h2'
37
39
  }
38
40
  };
41
+
42
+ export const Dismissable: Story = {
43
+ args: {
44
+ isDismissable: true
45
+ }
46
+ };
@@ -1,66 +1,101 @@
1
1
  import { test, expect } from 'vitest';
2
- import { render, screen } from '@testing-library/react';
2
+ import { render, screen, within } from '@testing-library/react';
3
3
  import ConfirmationMessage from './ConfirmationMessage';
4
4
 
5
- const TITLE_TEXT = 'Landlord added successfully';
5
+ const NOTIFICATION_TEXT = 'Further details of the notification message';
6
+ const TITLE_TEXT = 'Important information';
6
7
 
7
- test('renders correctly with icon, title and message', () => {
8
+ test('confirmation notification message renders correctly', () => {
8
9
  render(
9
10
  <ConfirmationMessage title={TITLE_TEXT}>
10
- <p>You have added the landlord <strong>John Smith</strong> to the application.</p>
11
+ {NOTIFICATION_TEXT}
11
12
  </ConfirmationMessage>
12
13
  );
13
14
 
14
- const container = document.querySelector('.ds_confirmation-message');
15
+ const container = document.querySelector('.ds_notification-message');
15
16
  const heading = screen.getByRole('heading');
16
-
17
+ const content = heading.nextElementSibling;
18
+
17
19
  expect(container?.ariaLive).toEqual('polite');
18
20
 
19
21
  expect(heading.tagName).toEqual('H3');
20
22
  expect(heading.textContent).toEqual(TITLE_TEXT)
23
+ expect(content?.textContent).toEqual(NOTIFICATION_TEXT)
24
+ });
25
+
26
+ test('confirmation notification message with close button', () => {
27
+ render(
28
+ <ConfirmationMessage isDismissable>
29
+ {NOTIFICATION_TEXT}
30
+ </ConfirmationMessage>
31
+ );
32
+
33
+ const closeButton = screen.getByRole('button');
34
+ const closeButtonLabel = within(closeButton).getByText('Close this notification');
35
+ const closeButtonIcon = within(closeButton).getByRole('img', { hidden: true });
36
+
37
+ expect(closeButton).toHaveClass('ds_notification-message__close', 'js-close-notification-message');
38
+ expect(closeButton).toHaveAttribute('type', 'button');
39
+
40
+ expect(closeButtonLabel).toBeInTheDocument();
41
+ expect(closeButtonLabel).toHaveClass('visually-hidden');
42
+
43
+ expect(closeButtonIcon).toHaveClass('ds_icon', 'ds_icon--fill');
44
+ });
45
+
46
+ test('confirmation notification message with icon', () => {
47
+ render(
48
+ <ConfirmationMessage icon="Search">
49
+ {NOTIFICATION_TEXT}
50
+ </ConfirmationMessage>
51
+ );
52
+
53
+
54
+ const notificationIcon = screen.getByRole('img', { hidden: true });
55
+
56
+ expect(notificationIcon).toHaveClass('ds_icon', 'ds_notification-message__icon', 'ds_icon--24');
57
+ expect(notificationIcon).toHaveAttribute('aria-hidden');
21
58
  });
22
59
 
23
60
  test("does not render body when no children specified", () => {
24
61
  const { container } = render(<ConfirmationMessage title={TITLE_TEXT} />);
25
62
 
26
63
  expect(
27
- container.querySelector(".ds_confirmation-message__body"),
64
+ container.querySelector(".ds_notification-message__body"),
28
65
  ).not.toBeInTheDocument();
29
66
  });
30
67
 
31
- test('renders confirmation message with custom aria live and custom heaer level', () => {
68
+ test('confirmation notification message with custom aria live and custom header level', () => {
32
69
  render(
33
- <ConfirmationMessage headingLevel="h2" ariaLive="alert" title={TITLE_TEXT}>
34
- <p>You have added the landlord <strong>John Smith</strong> to the application.</p>
35
- </ConfirmationMessage>
70
+ <ConfirmationMessage headingLevel="h2" ariaLive="assertive" title={TITLE_TEXT}/>
36
71
  );
37
72
 
38
- const container = document.querySelector('.ds_confirmation-message');
73
+ const container = document.querySelector('.ds_notification-message');
39
74
  const heading = screen.getByRole('heading');
40
75
 
41
- expect(container?.ariaLive).toEqual('alert');
76
+ expect(container?.ariaLive).toEqual('assertive');
42
77
 
43
78
  expect(heading.tagName).toEqual('H2');
44
79
  });
45
80
 
46
81
  test('passing additional props', () => {
47
82
  render(
48
- <ConfirmationMessage data-test="foo" title={TITLE_TEXT}>
49
- <p>You have added the landlord <strong>John Smith</strong> to the application.</p>
83
+ <ConfirmationMessage data-test="foo">
84
+ {NOTIFICATION_TEXT}
50
85
  </ConfirmationMessage>
51
- );
86
+ )
52
87
 
53
- const container = document.querySelector('.ds_confirmation-message') as HTMLElement;
88
+ const container = document.querySelector('.ds_notification-message') as HTMLElement;
54
89
  expect(container?.dataset.test).toEqual('foo');
55
90
  });
56
91
 
57
92
  test('passing additional CSS classes', () => {
58
93
  render(
59
- <ConfirmationMessage className="foo" title={TITLE_TEXT}>
60
- <p>You have added the landlord <strong>John Smith</strong> to the application.</p>
94
+ <ConfirmationMessage className="foo">
95
+ {NOTIFICATION_TEXT}
61
96
  </ConfirmationMessage>
62
- );
97
+ )
63
98
 
64
- const container = document.querySelector('.ds_confirmation-message');
65
- expect(container).toHaveClass('foo', 'ds_confirmation-message');
66
- })
99
+ const container = document.querySelector('.ds_notification-message') as HTMLElement;
100
+ expect(container).toHaveClass('foo', 'ds_notification-message');
101
+ });
@@ -1,37 +1,44 @@
1
- import Icon from '../../common/Icon';
2
- import WrapperTag from '../../common/WrapperTag';
3
- import { ConfirmationMessageProps } from './types';
4
- import clsx from 'clsx';
1
+ /**
2
+ * @deprecated
3
+ *
4
+ * This component has been deprecated, please use ConfirmationNotification instead
5
+ *
6
+ * Before:
7
+ *
8
+ * `<ConfirmationMessage />`
9
+ *
10
+ * After:
11
+ *
12
+ * `<ConfirmationNotification />`
13
+ *
14
+ * @deprecatedSince 1.1.0
15
+ *
16
+ */
17
+
18
+ import ConfirmationNotification from '..//ConfirmationNotification';
19
+ import { AbstractNotificationMessageProps } from '../../common/AbstractNotificationMessage/types';
5
20
 
6
21
  const ConfirmationMessage = ({
7
- ariaLive = 'polite',
22
+ ariaLive,
8
23
  children,
9
24
  className,
10
- headingLevel = 'h3',
25
+ headingLevel,
26
+ isDismissable,
11
27
  title,
12
28
  ...props
13
- }: ConfirmationMessageProps) => {
29
+ }: AbstractNotificationMessageProps) => {
30
+
14
31
  return (
15
- <div
16
- aria-live={ariaLive}
17
- className={clsx([
18
- 'ds_confirmation-message',
19
- className
20
- ])}
32
+ <ConfirmationNotification
33
+ ariaLive={ariaLive}
34
+ className={className}
35
+ headingLevel={headingLevel}
36
+ isDismissable={isDismissable}
37
+ title={title}
21
38
  {...props}
22
39
  >
23
- <Icon className="ds_confirmation-message__icon" icon="CheckCircle" iconSize="24" />
24
-
25
- <WrapperTag
26
- className="ds_confirmation-message__title"
27
- tagName={headingLevel}
28
- >
29
- {title}
30
- </WrapperTag>
31
- {children && <div className="ds_confirmation-message__body">
32
- {children}
33
- </div>}
34
- </div>
40
+ {children}
41
+ </ConfirmationNotification>
35
42
  );
36
43
  };
37
44
 
@@ -0,0 +1,17 @@
1
+ import { Canvas, Controls, Meta, Title, Stories } from '@storybook/addon-docs/blocks';
2
+
3
+ import * as ComponentStories from './ConfirmationMessage.stories';
4
+
5
+ <Meta of={ComponentStories} />
6
+
7
+ <Title></Title>
8
+
9
+ ## Deprecated
10
+
11
+ `<ConfirmationMessage>` is deprecated, instead use [Confirmation Notification](?path=/docs/components-notificationmessage-confirmationnotification--docs).
12
+
13
+ <Canvas of={ComponentStories.Default} />
14
+
15
+ <Controls of={ComponentStories.Default} />
16
+
17
+ <Stories/>
@@ -0,0 +1,47 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import argTypes from '../../../.storybook/sgdsArgTypes';
3
+
4
+ import ConfirmationNotification from './ConfirmationNotification';
5
+
6
+ const meta = {
7
+ title: 'Components/NotificationMessage/ConfirmationNotification',
8
+ component: ConfirmationNotification,
9
+ argTypes: {
10
+ ariaLive: argTypes.ariaLive(),
11
+ children: argTypes.children(),
12
+ headingLevel: argTypes.headingLevel(),
13
+ icon: { table: { disable: true } },
14
+ isDismissable: argTypes.boolean()
15
+ },
16
+ args: {
17
+ ariaLive: 'polite',
18
+ children: (<p>You have added the landlord <strong>John Smith</strong> to the application.</p>),
19
+ headingLevel: 'h3',
20
+ isDismissable: false,
21
+ title: 'Landlord added successfully',
22
+ }
23
+ } satisfies Meta<typeof ConfirmationNotification>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ export const Default: Story = {
29
+ };
30
+
31
+ export const NoChildren: Story = {
32
+ args: {
33
+ children: undefined
34
+ }
35
+ };
36
+
37
+ export const DifferentHeadingLevel: Story = {
38
+ args: {
39
+ headingLevel: 'h2'
40
+ }
41
+ };
42
+
43
+ export const Dismissable: Story = {
44
+ args: {
45
+ isDismissable: true
46
+ }
47
+ };
@@ -0,0 +1,101 @@
1
+ import { test, expect } from 'vitest';
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import ConfirmationNotification from './ConfirmationNotification';
4
+
5
+ const NOTIFICATION_TEXT = 'Further details of the notification message';
6
+ const TITLE_TEXT = 'Important information';
7
+
8
+ test('confirmation notification message renders correctly', () => {
9
+ render(
10
+ <ConfirmationNotification title={TITLE_TEXT}>
11
+ {NOTIFICATION_TEXT}
12
+ </ConfirmationNotification>
13
+ );
14
+
15
+ const container = document.querySelector('.ds_notification-message');
16
+ const heading = screen.getByRole('heading');
17
+ const content = heading.nextElementSibling;
18
+
19
+ expect(container?.ariaLive).toEqual('polite');
20
+
21
+ expect(heading.tagName).toEqual('H3');
22
+ expect(heading.textContent).toEqual(TITLE_TEXT)
23
+ expect(content?.textContent).toEqual(NOTIFICATION_TEXT)
24
+ });
25
+
26
+ test('confirmation notification message with close button', () => {
27
+ render(
28
+ <ConfirmationNotification isDismissable>
29
+ {NOTIFICATION_TEXT}
30
+ </ConfirmationNotification>
31
+ );
32
+
33
+ const closeButton = screen.getByRole('button');
34
+ const closeButtonLabel = within(closeButton).getByText('Close this notification');
35
+ const closeButtonIcon = within(closeButton).getByRole('img', { hidden: true });
36
+
37
+ expect(closeButton).toHaveClass('ds_notification-message__close', 'js-close-notification-message');
38
+ expect(closeButton).toHaveAttribute('type', 'button');
39
+
40
+ expect(closeButtonLabel).toBeInTheDocument();
41
+ expect(closeButtonLabel).toHaveClass('visually-hidden');
42
+
43
+ expect(closeButtonIcon).toHaveClass('ds_icon', 'ds_icon--fill');
44
+ });
45
+
46
+ test('confirmation notification message with icon', () => {
47
+ render(
48
+ <ConfirmationNotification icon="Search">
49
+ {NOTIFICATION_TEXT}
50
+ </ConfirmationNotification>
51
+ );
52
+
53
+
54
+ const notificationIcon = screen.getByRole('img', { hidden: true });
55
+
56
+ expect(notificationIcon).toHaveClass('ds_icon', 'ds_notification-message__icon', 'ds_icon--24');
57
+ expect(notificationIcon).toHaveAttribute('aria-hidden');
58
+ });
59
+
60
+ test("does not render body when no children specified", () => {
61
+ const { container } = render(<ConfirmationNotification title={TITLE_TEXT} />);
62
+
63
+ expect(
64
+ container.querySelector(".ds_notification-message__body"),
65
+ ).not.toBeInTheDocument();
66
+ });
67
+
68
+ test('confirmation notification message with custom aria live and custom header level', () => {
69
+ render(
70
+ <ConfirmationNotification headingLevel="h2" ariaLive="assertive" title={TITLE_TEXT}/>
71
+ );
72
+
73
+ const container = document.querySelector('.ds_notification-message');
74
+ const heading = screen.getByRole('heading');
75
+
76
+ expect(container?.ariaLive).toEqual('assertive');
77
+
78
+ expect(heading.tagName).toEqual('H2');
79
+ });
80
+
81
+ test('passing additional props', () => {
82
+ render(
83
+ <ConfirmationNotification data-test="foo">
84
+ {NOTIFICATION_TEXT}
85
+ </ConfirmationNotification>
86
+ )
87
+
88
+ const container = document.querySelector('.ds_notification-message') as HTMLElement;
89
+ expect(container?.dataset.test).toEqual('foo');
90
+ });
91
+
92
+ test('passing additional CSS classes', () => {
93
+ render(
94
+ <ConfirmationNotification className="foo">
95
+ {NOTIFICATION_TEXT}
96
+ </ConfirmationNotification>
97
+ )
98
+
99
+ const container = document.querySelector('.ds_notification-message') as HTMLElement;
100
+ expect(container).toHaveClass('foo', 'ds_notification-message');
101
+ });
@@ -0,0 +1,46 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import AbstractNotificationMessage from '../../common/AbstractNotificationMessage';
3
+ import DSNotificationMessage from '@scottish-government/design-system/src/components/notification-message/notification-message';
4
+ import { AbstractNotificationMessageProps } from '../../common/AbstractNotificationMessage/types';
5
+ import clsx from 'clsx';
6
+
7
+ const ConfirmationNotification = ({
8
+ ariaLive,
9
+ children,
10
+ className,
11
+ headingLevel = 'h3',
12
+ isDismissable,
13
+ title,
14
+ ...props
15
+ }: AbstractNotificationMessageProps) => {
16
+ const ref = useRef(null);
17
+
18
+ useEffect(() => {
19
+ /* istanbul ignore else */
20
+ if (ref.current) {
21
+ new DSNotificationMessage(ref.current).init();
22
+ }
23
+ }, [ref]);
24
+
25
+ return (
26
+ <AbstractNotificationMessage
27
+ ariaLive={ariaLive}
28
+ className={clsx([
29
+ 'ds_notification-message--success',
30
+ className
31
+ ])}
32
+ headingLevel={headingLevel}
33
+ icon="CheckCircle"
34
+ isDismissable={isDismissable}
35
+ ref={ref}
36
+ title={title}
37
+ {...props}
38
+ >
39
+ {children}
40
+ </AbstractNotificationMessage>
41
+ );
42
+ };
43
+
44
+ ConfirmationNotification.displayName = 'ConfirmationNotification';
45
+
46
+ export default ConfirmationNotification;
@@ -0,0 +1 @@
1
+ export { default } from './ConfirmationNotification';
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { useEffect, useRef } from 'react';
3
3
  import AbstractNotificationBanner from '../../common/AbstractNotificationBanner';
4
- import DSCookieBanner from '@scottish-government/design-system/src/components/cookie-notification/cookie-notification.js';
4
+ import DSCookieBanner from '@scottish-government/design-system/src/components/cookie-notification/cookie-notification';
5
5
  import { AbstractNotificationBannerProps } from '../../common/AbstractNotificationBanner/types';
6
6
  import clsx from 'clsx';
7
7
 
@@ -0,0 +1,47 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+ import argTypes from '../../../.storybook/sgdsArgTypes';
3
+
4
+ import ErrorNotification from './ErrorNotification';
5
+
6
+ const meta = {
7
+ title: 'Components/NotificationMessage/ErrorNotification',
8
+ component: ErrorNotification,
9
+ argTypes: {
10
+ ariaLive: argTypes.ariaLive(),
11
+ children: argTypes.children(),
12
+ headingLevel: argTypes.headingLevel(),
13
+ icon: { table: { disable: true } },
14
+ isDismissable: argTypes.boolean()
15
+ },
16
+ args: {
17
+ ariaLive: 'polite',
18
+ children: (<p>That link does not seem to be working.<br />Please try again.</p>),
19
+ headingLevel: 'h3',
20
+ isDismissable: false,
21
+ title: 'Something went wrong',
22
+ }
23
+ } satisfies Meta<typeof ErrorNotification>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ export const Default: Story = {
29
+ };
30
+
31
+ export const NoChildren: Story = {
32
+ args: {
33
+ children: undefined
34
+ }
35
+ };
36
+
37
+ export const DifferentHeadingLevel: Story = {
38
+ args: {
39
+ headingLevel: 'h2'
40
+ }
41
+ };
42
+
43
+ export const Dismissable: Story = {
44
+ args: {
45
+ isDismissable: true
46
+ }
47
+ };