@scottish-government/designsystem-react 1.0.1 → 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 (83) hide show
  1. package/.storybook/sgdsArgTypes.ts +19 -3
  2. package/CHANGELOG.md +19 -0
  3. package/dist/common/AbstractNotificationMessage/AbstractNotificationMessage.d.ts +6 -0
  4. package/dist/common/AbstractNotificationMessage/AbstractNotificationMessage.jsx +34 -0
  5. package/dist/common/AbstractNotificationMessage/index.d.ts +1 -0
  6. package/dist/common/AbstractNotificationMessage/index.js +8 -0
  7. package/dist/common/AbstractNotificationMessage/types.d.ts +9 -0
  8. package/dist/common/AbstractNotificationMessage/types.js +2 -0
  9. package/dist/common/WrapperTag/WrapperTag.d.ts +11 -11
  10. package/dist/components/ConfirmationMessage/ConfirmationMessage.d.ts +18 -2
  11. package/dist/components/ConfirmationMessage/ConfirmationMessage.jsx +21 -17
  12. package/dist/components/ConfirmationNotification/ConfirmationNotification.d.ts +6 -0
  13. package/dist/components/ConfirmationNotification/ConfirmationNotification.jsx +26 -0
  14. package/dist/components/ConfirmationNotification/index.d.ts +1 -0
  15. package/dist/components/ConfirmationNotification/index.js +8 -0
  16. package/dist/components/ErrorNotification/ErrorNotification.d.ts +6 -0
  17. package/dist/components/ErrorNotification/ErrorNotification.jsx +26 -0
  18. package/dist/components/ErrorNotification/index.d.ts +1 -0
  19. package/dist/components/ErrorNotification/index.js +8 -0
  20. package/dist/components/FileUpload/FileUpload.d.ts +6 -0
  21. package/dist/components/FileUpload/FileUpload.jsx +55 -0
  22. package/dist/components/FileUpload/index.d.ts +1 -0
  23. package/dist/components/FileUpload/index.js +8 -0
  24. package/dist/components/FileUpload/types.d.ts +24 -0
  25. package/dist/components/FileUpload/types.js +2 -0
  26. package/dist/components/InfoNotification/InfoNotification.d.ts +6 -0
  27. package/dist/components/InfoNotification/InfoNotification.jsx +26 -0
  28. package/dist/components/InfoNotification/index.d.ts +1 -0
  29. package/dist/components/InfoNotification/index.js +8 -0
  30. package/dist/components/NotificationBanner/NotificationBanner.jsx +1 -1
  31. package/dist/components/WarningNotification/WarningNotification.d.ts +6 -0
  32. package/dist/components/WarningNotification/WarningNotification.jsx +26 -0
  33. package/dist/components/WarningNotification/index.d.ts +1 -0
  34. package/dist/components/WarningNotification/index.js +8 -0
  35. package/dist/components/WarningText/WarningText.jsx +4 -1
  36. package/dist/images/icons/index.d.ts +2 -0
  37. package/dist/images/icons/index.js +5 -1
  38. package/dist/images/icons/info.d.ts +4 -0
  39. package/dist/images/icons/info.jsx +40 -0
  40. package/dist/images/icons/warning.d.ts +4 -0
  41. package/dist/images/icons/warning.jsx +40 -0
  42. package/dist/shared-types.d.ts +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +22 -16
  45. package/src/common/AbstractNotificationMessage/AbstractNotificationMessage.test.tsx +101 -0
  46. package/src/common/AbstractNotificationMessage/AbstractNotificationMessage.tsx +56 -0
  47. package/src/common/AbstractNotificationMessage/index.ts +1 -0
  48. package/src/common/AbstractNotificationMessage/types.ts +10 -0
  49. package/src/components/Button/Button.stories.tsx +1 -1
  50. package/src/components/ConfirmationMessage/ConfirmationMessage.stories.tsx +11 -3
  51. package/src/components/ConfirmationMessage/ConfirmationMessage.test.tsx +58 -23
  52. package/src/components/ConfirmationMessage/ConfirmationMessage.tsx +32 -25
  53. package/src/components/ConfirmationMessage/confirmationmessage.mdx +17 -0
  54. package/src/components/ConfirmationNotification/ConfirmationNotification.stories.tsx +47 -0
  55. package/src/components/ConfirmationNotification/ConfirmationNotification.test.tsx +101 -0
  56. package/src/components/ConfirmationNotification/ConfirmationNotification.tsx +46 -0
  57. package/src/components/ConfirmationNotification/index.ts +1 -0
  58. package/src/components/ErrorNotification/ErrorNotification.stories.tsx +47 -0
  59. package/src/components/ErrorNotification/ErrorNotification.test.tsx +101 -0
  60. package/src/components/ErrorNotification/ErrorNotification.tsx +46 -0
  61. package/src/components/ErrorNotification/index.ts +1 -0
  62. package/src/components/FileDownload/FileDownload.test.tsx +1 -1
  63. package/src/components/FileUpload/FileUpload.stories.tsx +77 -0
  64. package/src/components/FileUpload/FileUpload.test.tsx +185 -0
  65. package/src/components/FileUpload/FileUpload.tsx +87 -0
  66. package/src/components/FileUpload/index.ts +1 -0
  67. package/src/components/FileUpload/types.ts +25 -0
  68. package/src/components/InfoNotification/InfoNotification.stories.tsx +47 -0
  69. package/src/components/InfoNotification/InfoNotification.test.tsx +101 -0
  70. package/src/components/InfoNotification/InfoNotification.tsx +46 -0
  71. package/src/components/InfoNotification/index.ts +1 -0
  72. package/src/components/NotificationBanner/NotificationBanner.tsx +1 -1
  73. package/src/components/TextInput/TextInput.stories.tsx +1 -1
  74. package/src/components/WarningNotification/WarningNotification.stories.tsx +47 -0
  75. package/src/components/WarningNotification/WarningNotification.test.tsx +101 -0
  76. package/src/components/WarningNotification/WarningNotification.tsx +46 -0
  77. package/src/components/WarningNotification/index.ts +1 -0
  78. package/src/components/WarningText/WarningText.tsx +4 -1
  79. package/src/images/icons/index.ts +2 -0
  80. package/src/images/icons/info.tsx +14 -0
  81. package/src/images/icons/warning.tsx +14 -0
  82. package/src/shared-types.ts +1 -1
  83. package/src/components/ConfirmationMessage/types.ts +0 -7
package/package.json CHANGED
@@ -1,37 +1,43 @@
1
1
  {
2
2
  "name": "@scottish-government/designsystem-react",
3
3
  "description": "A React/JSX implementation of the Scottish Government Design System",
4
- "version": "1.0.1",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Scottish Government Digital Design System team",
8
8
  "email": "designsystem@gov.scot",
9
9
  "url": "https://designsystem.gov.scot"
10
10
  },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/scottish-government-design-system/designsystem-react"
14
+ },
11
15
  "typings": "dist/index.d.ts",
12
16
  "main": "dist/index.js",
13
17
  "scripts": {
14
18
  "build": "npx eslint && npm run svgr && npm run tsc",
19
+ "build-storybook": "storybook build",
20
+ "prepare": "npm run build",
21
+ "prepublishOnly": "vitest test.tsx --run",
15
22
  "svgr": "npx @svgr/cli node_modules/@scottish-government/design-system/src/images/icons/svg --config-file .svgrrc",
16
23
  "svgr_documents": "npx @svgr/cli node_modules/@scottish-government/design-system/src/images/documents/svg --config-file .svgrrc_documents",
17
24
  "test": "vitest test.tsx",
18
- "test:coverage": "vitest test.tsx run --coverage",
25
+ "test:coverage": "vitest test.tsx --run --coverage",
19
26
  "tsc": "node ./node_modules/typescript/bin/tsc",
20
- "storybook": "storybook dev -p 6006",
21
- "build-storybook": "storybook build"
27
+ "storybook": "storybook dev -p 6006"
22
28
  },
23
29
  "peerDependencies": {
24
- "@scottish-government/design-system": "^4.0.0"
30
+ "@scottish-government/design-system": "^4.1.1"
25
31
  },
26
32
  "devDependencies": {
27
33
  "@chromatic-com/storybook": "^4.1.3",
28
34
  "@eslint/js": "^9.39.1",
29
- "@scottish-government/design-system": "^4.0.0",
30
- "@storybook/addon-a11y": "^10.0.8",
31
- "@storybook/addon-docs": "^10.0.8",
32
- "@storybook/addon-onboarding": "^10.0.8",
33
- "@storybook/addon-vitest": "^10.0.8",
34
- "@storybook/react-vite": "^10.0.8",
35
+ "@scottish-government/design-system": "^4.1.1",
36
+ "@storybook/addon-a11y": "^10.4.1",
37
+ "@storybook/addon-docs": "^10.4.2",
38
+ "@storybook/addon-onboarding": "^10.4.2",
39
+ "@storybook/addon-vitest": "^10.4.2",
40
+ "@storybook/react-vite": "^10.4.2",
35
41
  "@svgr/cli": "^8.1.0",
36
42
  "@testing-library/dom": "^10.4.1",
37
43
  "@testing-library/jest-dom": "^6.9.1",
@@ -41,9 +47,9 @@
41
47
  "@types/react": "^19.2.6",
42
48
  "@types/react-dom": "^19.2.3",
43
49
  "@vitejs/plugin-react-swc": "^4.2.2",
44
- "@vitest/browser": "4.0.10",
45
- "@vitest/browser-playwright": "^4.0.10",
46
- "@vitest/coverage-v8": "^4.0.10",
50
+ "@vitest/browser": "^4.1.8",
51
+ "@vitest/browser-playwright": "^4.1.8",
52
+ "@vitest/coverage-v8": "^4.1.8",
47
53
  "clsx": "^2.1.1",
48
54
  "eslint": "^9.39.1",
49
55
  "eslint-plugin-react": "^7.37.5",
@@ -51,9 +57,9 @@
51
57
  "jsdom": "^27.2.0",
52
58
  "react": "^19.2.0",
53
59
  "react-dom": "^19.2.0",
54
- "storybook": "^10.1.10",
60
+ "storybook": "^10.4.2",
55
61
  "typescript": "^5.9.3",
56
62
  "typescript-eslint": "^8.47.0",
57
- "vitest": "^4.0.10"
63
+ "vitest": "^4.1.8"
58
64
  }
59
65
  }
@@ -0,0 +1,101 @@
1
+ import { test, expect } from 'vitest';
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import AbstractNotificationMessage from './AbstractNotificationMessage';
4
+
5
+ const NOTIFICATION_TEXT = 'Further details of the notification message';
6
+ const TITLE_TEXT = 'Important information';
7
+
8
+ test('abstract notification message renders correctly', () => {
9
+ render(
10
+ <AbstractNotificationMessage title={TITLE_TEXT}>
11
+ {NOTIFICATION_TEXT}
12
+ </AbstractNotificationMessage>
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('abstract notification message with close button', () => {
27
+ render(
28
+ <AbstractNotificationMessage isDismissable>
29
+ {NOTIFICATION_TEXT}
30
+ </AbstractNotificationMessage>
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('abstract notification message with icon', () => {
47
+ render(
48
+ <AbstractNotificationMessage icon="Search">
49
+ {NOTIFICATION_TEXT}
50
+ </AbstractNotificationMessage>
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(<AbstractNotificationMessage title={TITLE_TEXT} />);
62
+
63
+ expect(
64
+ container.querySelector(".ds_notification-message__body"),
65
+ ).not.toBeInTheDocument();
66
+ });
67
+
68
+ test('abstract notification message with custom aria live and custom header level', () => {
69
+ render(
70
+ <AbstractNotificationMessage 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
+ <AbstractNotificationMessage data-test="foo">
84
+ {NOTIFICATION_TEXT}
85
+ </AbstractNotificationMessage>
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
+ <AbstractNotificationMessage className="foo">
95
+ {NOTIFICATION_TEXT}
96
+ </AbstractNotificationMessage>
97
+ )
98
+
99
+ const container = document.querySelector('.ds_notification-message') as HTMLElement;
100
+ expect(container).toHaveClass('foo', 'ds_notification-message');
101
+ });
@@ -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
  },
@@ -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
+ });