@kaizen/components 1.35.1 → 1.36.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 (153) hide show
  1. package/dist/cjs/Button/GenericButton/GenericButton.cjs +1 -1
  2. package/dist/cjs/Button/GenericButton/GenericButton.cjs.map +1 -1
  3. package/dist/cjs/KaizenProvider/KaizenProvider.cjs +6 -1
  4. package/dist/cjs/KaizenProvider/KaizenProvider.cjs.map +1 -1
  5. package/dist/cjs/Modal/ContextModal/ContextModal.cjs +9 -6
  6. package/dist/cjs/Modal/ContextModal/ContextModal.cjs.map +1 -1
  7. package/dist/cjs/MultiSelect/subcomponents/Popover/Popover.cjs +1 -1
  8. package/dist/cjs/MultiSelect/subcomponents/Popover/Popover.cjs.map +1 -1
  9. package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs +33 -0
  10. package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs.map +1 -0
  11. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.cjs +36 -0
  12. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.cjs.map +1 -0
  13. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.cjs +7 -0
  14. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.cjs.map +1 -0
  15. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs +42 -0
  16. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs.map +1 -0
  17. package/dist/cjs/Notification/ToastNotification/context/ToastNotificationContext.cjs +72 -0
  18. package/dist/cjs/Notification/ToastNotification/context/ToastNotificationContext.cjs.map +1 -0
  19. package/dist/cjs/Notification/ToastNotification/hooks/useToastNotification.cjs +9 -0
  20. package/dist/cjs/Notification/ToastNotification/hooks/useToastNotification.cjs.map +1 -0
  21. package/dist/cjs/RichTextEditor/RichTextEditor/RichTextEditor.cjs +6 -2
  22. package/dist/cjs/RichTextEditor/RichTextEditor/RichTextEditor.cjs.map +1 -1
  23. package/dist/cjs/__future__/Select/Select.cjs +24 -2
  24. package/dist/cjs/__future__/Select/Select.cjs.map +1 -1
  25. package/dist/cjs/dts/Modal/ContextModal/ContextModal.d.ts +2 -1
  26. package/dist/cjs/dts/MultiSelect/MultiSelect.d.ts +4 -2
  27. package/dist/cjs/dts/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.d.ts +3 -0
  28. package/dist/cjs/dts/MultiSelect/types.d.ts +6 -0
  29. package/dist/cjs/dts/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +16 -0
  30. package/dist/cjs/dts/Notification/ToastNotification/ToastNotification/index.d.ts +1 -0
  31. package/dist/cjs/dts/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.d.ts +4 -0
  32. package/dist/cjs/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.d.ts +12 -0
  33. package/dist/cjs/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/index.d.ts +1 -0
  34. package/dist/cjs/dts/Notification/ToastNotification/context/ToastNotificationContext.d.ts +21 -0
  35. package/dist/cjs/dts/Notification/ToastNotification/hooks/useToastNotification.d.ts +2 -0
  36. package/dist/cjs/dts/Notification/ToastNotification/index.d.ts +3 -2
  37. package/dist/cjs/dts/Notification/ToastNotification/types.d.ts +1 -9
  38. package/dist/cjs/dts/Notification/index.d.ts +1 -0
  39. package/dist/cjs/dts/RichTextEditor/RichTextEditor/RichTextEditor.d.ts +1 -1
  40. package/dist/cjs/dts/__future__/Select/Select.d.ts +5 -1
  41. package/dist/cjs/index.cjs +6 -0
  42. package/dist/cjs/index.cjs.map +1 -1
  43. package/dist/cjs/index.css +4 -3
  44. package/dist/esm/Button/GenericButton/GenericButton.mjs +1 -1
  45. package/dist/esm/Button/GenericButton/GenericButton.mjs.map +1 -1
  46. package/dist/esm/KaizenProvider/KaizenProvider.mjs +6 -1
  47. package/dist/esm/KaizenProvider/KaizenProvider.mjs.map +1 -1
  48. package/dist/esm/Modal/ContextModal/ContextModal.mjs +9 -6
  49. package/dist/esm/Modal/ContextModal/ContextModal.mjs.map +1 -1
  50. package/dist/esm/MultiSelect/subcomponents/Popover/Popover.mjs +1 -1
  51. package/dist/esm/MultiSelect/subcomponents/Popover/Popover.mjs.map +1 -1
  52. package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs +31 -0
  53. package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs.map +1 -0
  54. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.mjs +34 -0
  55. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.mjs.map +1 -0
  56. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.mjs +5 -0
  57. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.mjs.map +1 -0
  58. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs +40 -0
  59. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs.map +1 -0
  60. package/dist/esm/Notification/ToastNotification/context/ToastNotificationContext.mjs +69 -0
  61. package/dist/esm/Notification/ToastNotification/context/ToastNotificationContext.mjs.map +1 -0
  62. package/dist/esm/Notification/ToastNotification/hooks/useToastNotification.mjs +7 -0
  63. package/dist/esm/Notification/ToastNotification/hooks/useToastNotification.mjs.map +1 -0
  64. package/dist/esm/RichTextEditor/RichTextEditor/RichTextEditor.mjs +6 -2
  65. package/dist/esm/RichTextEditor/RichTextEditor/RichTextEditor.mjs.map +1 -1
  66. package/dist/esm/__future__/Select/Select.mjs +25 -3
  67. package/dist/esm/__future__/Select/Select.mjs.map +1 -1
  68. package/dist/esm/dts/Modal/ContextModal/ContextModal.d.ts +2 -1
  69. package/dist/esm/dts/MultiSelect/MultiSelect.d.ts +4 -2
  70. package/dist/esm/dts/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.d.ts +3 -0
  71. package/dist/esm/dts/MultiSelect/types.d.ts +6 -0
  72. package/dist/esm/dts/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +16 -0
  73. package/dist/esm/dts/Notification/ToastNotification/ToastNotification/index.d.ts +1 -0
  74. package/dist/esm/dts/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.d.ts +4 -0
  75. package/dist/esm/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.d.ts +12 -0
  76. package/dist/esm/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/index.d.ts +1 -0
  77. package/dist/esm/dts/Notification/ToastNotification/context/ToastNotificationContext.d.ts +21 -0
  78. package/dist/esm/dts/Notification/ToastNotification/hooks/useToastNotification.d.ts +2 -0
  79. package/dist/esm/dts/Notification/ToastNotification/index.d.ts +3 -2
  80. package/dist/esm/dts/Notification/ToastNotification/types.d.ts +1 -9
  81. package/dist/esm/dts/Notification/index.d.ts +1 -0
  82. package/dist/esm/dts/RichTextEditor/RichTextEditor/RichTextEditor.d.ts +1 -1
  83. package/dist/esm/dts/__future__/Select/Select.d.ts +5 -1
  84. package/dist/esm/index.css +5 -4
  85. package/dist/esm/index.mjs +3 -0
  86. package/dist/esm/index.mjs.map +1 -1
  87. package/dist/index.d.ts +50 -3
  88. package/dist/styles.css +1 -1
  89. package/package.json +2 -2
  90. package/src/Button/Button/_docs/Button.mdx +5 -0
  91. package/src/Button/Button/_docs/Button.stories.tsx +27 -1
  92. package/src/Button/GenericButton/GenericButton.spec.tsx +69 -0
  93. package/src/Button/GenericButton/GenericButton.tsx +1 -1
  94. package/src/DatePicker/DatePicker.spec.tsx +1 -1
  95. package/src/KaizenProvider/KaizenProvider.tsx +6 -1
  96. package/src/Modal/ContextModal/ContextModal.spec.tsx +3 -3
  97. package/src/Modal/ContextModal/ContextModal.tsx +9 -5
  98. package/src/MultiSelect/MultiSelect.spec.tsx +56 -1
  99. package/src/MultiSelect/MultiSelect.tsx +10 -3
  100. package/src/MultiSelect/_docs/MultiSelect.mdx +10 -0
  101. package/src/MultiSelect/_docs/MultiSelect.stickersheet.stories.tsx +81 -43
  102. package/src/MultiSelect/_docs/MultiSelect.stories.tsx +21 -0
  103. package/src/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.module.scss +9 -0
  104. package/src/MultiSelect/subcomponents/MultiSelectToggle/MultiSelectToggle.tsx +8 -1
  105. package/src/MultiSelect/subcomponents/MultiSelectToggle/_docs/MultiSelectToggle.stickersheet.stories.tsx +17 -0
  106. package/src/MultiSelect/subcomponents/Popover/Popover.tsx +1 -1
  107. package/src/MultiSelect/types.ts +7 -0
  108. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.spec.tsx +33 -0
  109. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.tsx +48 -0
  110. package/src/Notification/ToastNotification/ToastNotification/index.ts +1 -0
  111. package/src/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/ToastNotificationsList.module.scss +1 -1
  112. package/src/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.tsx +40 -0
  113. package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.tsx +49 -0
  114. package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/index.ts +1 -0
  115. package/src/Notification/ToastNotification/_docs/ToastNotification.mdx +19 -14
  116. package/src/Notification/ToastNotification/_docs/ToastNotification.stickersheet.stories.tsx +33 -70
  117. package/src/Notification/ToastNotification/_docs/ToastNotification.stories.tsx +123 -93
  118. package/src/Notification/ToastNotification/context/ToastNotificationContext.tsx +96 -0
  119. package/src/Notification/ToastNotification/hooks/useToastNotification.ts +9 -0
  120. package/src/Notification/ToastNotification/index.ts +3 -2
  121. package/src/Notification/ToastNotification/types.ts +1 -18
  122. package/src/Notification/index.ts +1 -0
  123. package/src/RichTextEditor/RichTextEditor/RichTextEditor.tsx +6 -1
  124. package/src/RichTextEditor/utils/commands/addMark.spec.ts +0 -1
  125. package/src/Tooltip/Tooltip.spec.tsx +6 -1
  126. package/src/__future__/Select/Select.spec.tsx +109 -14
  127. package/src/__future__/Select/Select.tsx +32 -3
  128. package/src/__future__/Select/_docs/Select.mdx +8 -0
  129. package/src/__future__/Select/_docs/Select.stories.tsx +29 -0
  130. package/dist/cjs/dts/Notification/ToastNotification/ToastNotification.d.ts +0 -14
  131. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.d.ts +0 -7
  132. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/index.d.ts +0 -1
  133. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationsList/ToastNotificationsList.d.ts +0 -11
  134. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.d.ts +0 -7
  135. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/index.d.ts +0 -1
  136. package/dist/esm/dts/Notification/ToastNotification/ToastNotification.d.ts +0 -14
  137. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.d.ts +0 -7
  138. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/index.d.ts +0 -1
  139. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationsList/ToastNotificationsList.d.ts +0 -11
  140. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.d.ts +0 -7
  141. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/index.d.ts +0 -1
  142. package/src/Notification/ToastNotification/ToastNotification.spec.tsx +0 -31
  143. package/src/Notification/ToastNotification/ToastNotification.tsx +0 -43
  144. package/src/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.spec.tsx +0 -144
  145. package/src/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.tsx +0 -135
  146. package/src/Notification/ToastNotification/subcomponents/ToastNotificationManager/index.ts +0 -1
  147. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsList/ToastNotificationsList.tsx +0 -40
  148. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.spec.tsx +0 -73
  149. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.tsx +0 -31
  150. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/index.ts +0 -1
  151. /package/dist/cjs/dts/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/index.d.ts +0 -0
  152. /package/dist/esm/dts/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/index.d.ts +0 -0
  153. /package/src/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/index.ts +0 -0
@@ -0,0 +1,33 @@
1
+ import React from "react"
2
+ import { render, screen } from "@testing-library/react"
3
+ import { ToastNotification, ToastNotificationProps } from "../ToastNotification"
4
+ import { ToastNotificationsList } from "../ToastNotificationsList"
5
+ import { ToastNotificationProvider } from "../context/ToastNotificationContext"
6
+
7
+ const ToastNotificationWrapper = ({
8
+ children,
9
+ ...props
10
+ }: Partial<ToastNotificationProps>): JSX.Element => (
11
+ <ToastNotificationProvider>
12
+ <ToastNotificationsList />
13
+ <ToastNotification type="positive" title="Success" {...props}>
14
+ {children ?? "It worked!"}
15
+ </ToastNotification>
16
+ </ToastNotificationProvider>
17
+ )
18
+
19
+ describe("<ToastNotification />", () => {
20
+ it('creates a single "status" container for notifications', async () => {
21
+ render(<ToastNotificationWrapper />)
22
+
23
+ const toastPortalManager = screen.getAllByRole("status")
24
+ expect(toastPortalManager).toHaveLength(1)
25
+ })
26
+
27
+ it("renders a basic notification correctly", async () => {
28
+ render(<ToastNotificationWrapper />)
29
+
30
+ const notification = await screen.findByText("Success")
31
+ expect(notification).toBeInTheDocument()
32
+ })
33
+ })
@@ -0,0 +1,48 @@
1
+ import React, { useEffect, useId } from "react"
2
+ import { useToastNotificationContext } from "../context/ToastNotificationContext"
3
+ import { ToastNotificationObj } from "../types"
4
+
5
+ export type ToastNotificationProps = Omit<
6
+ ToastNotificationObj,
7
+ "id" | "message" | "persistent"
8
+ > & {
9
+ children: React.ReactNode
10
+ id?: string
11
+ /**
12
+ * Removes the dismiss trigger. Functions the same as `persistent` in `addToastNotification`.
13
+ * If this is true you will need to manage the removal of notifications manually.
14
+ * @default false
15
+ */
16
+ hideCloseIcon?: boolean
17
+ }
18
+
19
+ export const ToastNotification = ({
20
+ id: propsId,
21
+ hideCloseIcon = false,
22
+ type,
23
+ title,
24
+ onHide,
25
+ children,
26
+ ...restProps
27
+ }: ToastNotificationProps): null => {
28
+ const reactId = useId()
29
+ const id = propsId || reactId
30
+ const { addToastNotification } = useToastNotificationContext()
31
+ const persistent = hideCloseIcon
32
+
33
+ useEffect(() => {
34
+ addToastNotification({
35
+ id,
36
+ type,
37
+ title,
38
+ message: children,
39
+ persistent,
40
+ onHide,
41
+ ...restProps,
42
+ })
43
+ }, [])
44
+
45
+ return null
46
+ }
47
+
48
+ ToastNotification.displayName = "ToastNotification"
@@ -0,0 +1 @@
1
+ export * from "./ToastNotification"
@@ -1,7 +1,7 @@
1
1
  @import "~@kaizen/design-tokens/sass/spacing";
2
2
  @import "~@kaizen/design-tokens/sass/layout";
3
3
 
4
- .list {
4
+ .toastNotificationsList {
5
5
  display: flex;
6
6
  flex-direction: column;
7
7
  align-items: flex-end;
@@ -0,0 +1,40 @@
1
+ import React from "react"
2
+ import { createPortal } from "react-dom"
3
+ import { useToastNotificationContext } from "../context/ToastNotificationContext"
4
+ import { ToastNotificationsMap } from "./subcomponents/ToastNotificationsMap"
5
+ import styles from "./ToastNotificationsList.module.scss"
6
+
7
+ export const ToastNotificationsList = (): JSX.Element => {
8
+ const { notifications, removeToastNotification } =
9
+ useToastNotificationContext()
10
+
11
+ const containers = document.querySelectorAll(
12
+ '[data-testid="toast-notifications-list"'
13
+ )
14
+
15
+ if (containers) {
16
+ // Remove any duplicate instances
17
+ // (eg. Storybook docs page has multiple stories each with their own context)
18
+ containers.forEach((c, i) => {
19
+ if (i === 0) return
20
+ c.remove()
21
+ })
22
+ }
23
+
24
+ return createPortal(
25
+ <div
26
+ data-testid="toast-notifications-list"
27
+ role="status"
28
+ className={styles.toastNotificationsList}
29
+ >
30
+ <ToastNotificationsMap
31
+ notifications={notifications}
32
+ onHide={removeToastNotification}
33
+ container={containers[0]}
34
+ />
35
+ </div>,
36
+ document.body
37
+ )
38
+ }
39
+
40
+ ToastNotificationsList.displayName = "ToastNotificationsList"
@@ -0,0 +1,49 @@
1
+ import React, { HTMLAttributes } from "react"
2
+ import { createPortal } from "react-dom"
3
+ import { GenericNotification } from "~components/Notification/subcomponents/GenericNotification"
4
+ import { OverrideClassName } from "~types/OverrideClassName"
5
+ import { ToastNotificationObj } from "../../../types"
6
+
7
+ export type ToastNotificationsMapProps = {
8
+ notifications: ToastNotificationObj[]
9
+ onHide: (notificationId: string) => void
10
+ container: Element | null
11
+ } & OverrideClassName<HTMLAttributes<HTMLDivElement>>
12
+
13
+ export const ToastNotificationsMap = ({
14
+ notifications,
15
+ onHide: defaultOnHide,
16
+ container,
17
+ }: ToastNotificationsMapProps): JSX.Element | null => {
18
+ if (!container) return null
19
+
20
+ // To consolidate all notifications into a single list when there are multiple contexts,
21
+ // this list cannot render with a container (must be portalled into one).
22
+ return createPortal(
23
+ <>
24
+ {notifications.map(
25
+ ({ id, type, title, persistent, onHide, message, ...restProps }) => (
26
+ <GenericNotification
27
+ key={id}
28
+ style="toast"
29
+ type={type}
30
+ title={title}
31
+ persistent={persistent}
32
+ onHide={(): void => {
33
+ if (typeof onHide !== "undefined") {
34
+ onHide()
35
+ }
36
+ defaultOnHide(id)
37
+ }}
38
+ {...restProps}
39
+ >
40
+ {message}
41
+ </GenericNotification>
42
+ )
43
+ )}
44
+ </>,
45
+ container
46
+ )
47
+ }
48
+
49
+ ToastNotificationsMap.displayName = "ToastNotificationsMap"
@@ -1,5 +1,5 @@
1
1
  import { Canvas, Controls, Meta } from "@storybook/blocks"
2
- import { ResourceLinks, KaioNotification, Installation } from "~storybook/components"
2
+ import { ResourceLinks, KaioNotification, Installation, LinkTo } from "~storybook/components"
3
3
  import * as ToastNotificationStories from "./ToastNotification.stories"
4
4
 
5
5
  <Meta title="Components/Notifications/ToastNotification" />
@@ -17,51 +17,56 @@ import * as ToastNotificationStories from "./ToastNotification.stories"
17
17
 
18
18
  <Installation
19
19
  installCommand="yarn add @kaizen/components"
20
- importStatement='import { addToastNotification, removeToastNotification, clearToastNotifications, ToastNotification } from "@kaizen/components"'
20
+ importStatement='import { addToastNotification } from "@kaizen/components"'
21
21
  />
22
22
 
23
23
  ## Overview
24
24
 
25
- Toast notifications are used to notifying a user of an outcome for an action they have taken. They appended to the root of the document body and will render in the top corner of the window.
25
+ Toast notifications are used to notifying a user of an outcome for an action they have taken.
26
+ They appended to the root of the document body and will render in the top corner of the window.
27
+
28
+ **Note:** Toast notifications must be used within <LinkTo pageId="components-kaizen-provider-installation">KaizenProvider</LinkTo>.
26
29
 
27
30
  <Canvas of={ToastNotificationStories.Playground} />
28
31
  <Controls of={ToastNotificationStories.Playground} />
29
32
 
30
33
  ## API
31
34
 
32
- In addition to the `ToastNotification` JSX element, there are three API methods exported from this package to create and manage Toast notifications.
35
+ Use the following helper methods available through the `useToastNotification` hook to create and manage Toast notifications.
33
36
 
34
37
  ### addToastNotification
35
- Creates an instance of the the Toast Notification manager and appends new notifications to the list.
38
+
39
+ Adds and appends a new notification to the list.
36
40
 
37
41
  <Canvas of={ToastNotificationStories.CreateNotification} />
38
42
 
39
- If `addToastNotification` is called with an `id` that matches an existing notification, then it will update the content of that component.
43
+ ### updateToastNotification
40
44
 
41
- This will also be invoked if you use the `ToastNotification` component.
45
+ Updates a single notification that matches the `id` passed to the function.
42
46
 
43
47
  <Canvas of={ToastNotificationStories.UpdateNotification} />
44
48
 
45
-
46
49
  ### removeToastNotification
47
50
 
48
51
  Removes a single notification that matches the `id` passed to the function.
49
52
 
50
53
  <Canvas of={ToastNotificationStories.RemoveNotification} />
51
54
 
52
-
53
55
  ### clearToastNotifications
54
56
 
55
57
  Clears all notifications currently held in state.
56
58
 
57
- <Canvas of={ToastNotificationStories.ClearNotifications} />
59
+ Note that since each story has an individual context, this example will only clear the ones it adds.
58
60
 
61
+ <Canvas of={ToastNotificationStories.ClearNotifications} />
59
62
 
60
63
  ## Accessibility and removal of notifications
61
64
 
62
- Any notification that is temporarily rendered on screen should provide a user ample time to read its contents and provide a way to stop its removal ([WCAG guidline here](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits.html)
63
- )).
65
+ Any notification that is temporarily rendered on screen should provide a user ample time to read its contents and
66
+ provide a way to stop its removal ([WCAG guidline here](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits.html)).
64
67
 
65
- By default, all Toast notifications will remain on screen until dismissed. This ensures the accessibility is met and does not require additional intervention.
68
+ By default, all Toast notifications will remain on screen until dismissed.
69
+ This ensures the accessibility is met and does not require additional intervention.
66
70
 
67
- If you required to be automatically removed, you must provide a means of stopping and re-enabling its removal and ensures that a user can reasonably access this before it is removed.
71
+ If you required to be automatically removed, you must provide a means of stopping and re-enabling its
72
+ removal and ensures that a user can reasonably access this before it is removed.
@@ -1,7 +1,7 @@
1
1
  import React from "react"
2
2
  import { Meta } from "@storybook/react"
3
3
  import { StickerSheetStory } from "~storybook/components/StickerSheet"
4
- import { addToastNotification } from "../subcomponents/ToastNotificationManager"
4
+ import { ToastNotification } from "../ToastNotification"
5
5
 
6
6
  export default {
7
7
  title: "Components/Notifications/ToastNotification",
@@ -12,75 +12,38 @@ export default {
12
12
  } satisfies Meta
13
13
 
14
14
  const StickerSheetTemplate: StickerSheetStory = {
15
- render: () => {
16
- React.useEffect(() => {
17
- addToastNotification({
18
- type: "positive",
19
- title: "Positive",
20
- message: (
21
- <>
22
- New user data, imported by mackenzie@hooli.com has successfully
23
- uploaded. <a href="/">Manage users is now available</a>
24
- </>
25
- ),
26
- })
27
- addToastNotification({
28
- type: "informative",
29
- title: "Informative",
30
- message: (
31
- <>
32
- New user data is currently being processed. We’ll let you know when
33
- the process is completed. <a href="/">Manage users</a>
34
- </>
35
- ),
36
- })
37
- addToastNotification({
38
- type: "cautionary",
39
- title: "Cautionary",
40
- message: (
41
- <>
42
- New user data, imported by mackenzie@hooli.com has uploaded with
43
- some minor issues. <a href="/">View issues</a>
44
- </>
45
- ),
46
- })
47
- addToastNotification({
48
- type: "security",
49
- title: "Security",
50
- message: (
51
- <>
52
- Results hidden to protect confidentiality of individuals and small
53
- groups. <a href="/">Learn more</a>
54
- </>
55
- ),
56
- })
57
- addToastNotification({
58
- type: "negative",
59
- title: "Negative",
60
- message: (
61
- <>
62
- Check your connection and try again. <a href="/">Refresh</a>.
63
- </>
64
- ),
65
- })
66
- addToastNotification({
67
- type: "positive",
68
- title:
69
- "Very long Title Example Very long title Example VerylongTitleExampleVerylongtitleExample ",
70
- message: (
71
- <>
72
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla
73
- semper odio vitae sem gravida rutrum. Praesent vel sapien eget eros
74
- dictum luctus scelerisque eu nibh. Etiam ullamcorper lobortis
75
- gravida. Suspendisse massa tortor, ultricies et ipsum at, iaculis
76
- bibendum est.
77
- </>
78
- ),
79
- })
80
- }, [])
81
-
82
- return <></>
83
- },
15
+ render: () => (
16
+ <>
17
+ <ToastNotification type="positive" title="Positive">
18
+ New user data, imported by mackenzie@hooli.com has successfully
19
+ uploaded. <a href="/">Manage users is now available</a>
20
+ </ToastNotification>
21
+ <ToastNotification type="informative" title="Informative">
22
+ New user data is currently being processed. We&apos;ll let you know when
23
+ the process is completed. <a href="/">Manage users</a>
24
+ </ToastNotification>
25
+ <ToastNotification type="cautionary" title="Cautionary">
26
+ New user data, imported by mackenzie@hooli.com has uploaded with some
27
+ minor issues. <a href="/">View issues</a>
28
+ </ToastNotification>
29
+ <ToastNotification type="security" title="Security">
30
+ Results hidden to protect confidentiality of individuals and small
31
+ groups. <a href="/">Learn more</a>
32
+ </ToastNotification>
33
+ <ToastNotification type="negative" title="Negative">
34
+ Check your connection and try again. <a href="/">Refresh</a>.
35
+ </ToastNotification>
36
+ <ToastNotification
37
+ type="positive"
38
+ title="Very long Title Example Very long title Example VerylongTitleExampleVerylongtitleExample"
39
+ >
40
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla semper
41
+ odio vitae sem gravida rutrum. Praesent vel sapien eget eros dictum
42
+ luctus scelerisque eu nibh. Etiam ullamcorper lobortis gravida.
43
+ Suspendisse massa tortor, ultricies et ipsum at, iaculis bibendum est.
44
+ </ToastNotification>
45
+ </>
46
+ ),
84
47
  }
85
48
 
86
49
  export const StickerSheetDefault: StickerSheetStory = {
@@ -1,12 +1,7 @@
1
- import React from "react"
1
+ import React, { useEffect, useId } from "react"
2
2
  import { Meta, StoryObj } from "@storybook/react"
3
3
  import { Button } from "~components/Button"
4
- import {
5
- addToastNotification,
6
- removeToastNotification,
7
- clearToastNotifications,
8
- ToastNotification,
9
- } from "../index"
4
+ import { ToastNotification, useToastNotification } from "../index"
10
5
 
11
6
  const meta = {
12
7
  title: "Components/Notifications/ToastNotification",
@@ -28,7 +23,26 @@ export default meta
28
23
 
29
24
  type Story = StoryObj<typeof meta>
30
25
 
26
+ const ToastNotificationTemplate: Story = {
27
+ render: args => {
28
+ const reactId = useId()
29
+ const { updateToastNotification } = useToastNotification()
30
+
31
+ useEffect(() => {
32
+ updateToastNotification({
33
+ ...args,
34
+ id: args.id ?? reactId,
35
+ message: args.children,
36
+ persistent: args.hideCloseIcon,
37
+ })
38
+ }, [args])
39
+
40
+ return <ToastNotification {...args} />
41
+ },
42
+ }
43
+
31
44
  export const Playground: Story = {
45
+ ...ToastNotificationTemplate,
32
46
  parameters: {
33
47
  docs: {
34
48
  canvas: {
@@ -39,104 +53,120 @@ export const Playground: Story = {
39
53
  }
40
54
 
41
55
  export const CreateNotification: Story = {
42
- render: () => (
43
- <Button
44
- label="Create notification"
45
- onClick={() =>
46
- addToastNotification({
47
- title: "Informative",
48
- type: "informative",
49
- message: "New notification!",
50
- })
51
- }
52
- />
53
- ),
54
- }
56
+ render: () => {
57
+ const { addToastNotification } = useToastNotification()
55
58
 
56
- export const UpdateNotification: Story = {
57
- render: () => (
58
- <>
59
+ return (
59
60
  <Button
60
61
  label="Create notification"
61
- classNameOverride="!mr-12"
62
- onClick={() =>
63
- addToastNotification({
64
- id: "id--update-example",
65
- title: "Cautionary",
66
- type: "cautionary",
67
- message: "This content will be updated",
68
- })
69
- }
70
- />
71
- <Button
72
- label="Update notification"
73
62
  onClick={() =>
74
63
  addToastNotification({
75
- id: "id--update-example",
76
- title: "Success",
77
- type: "positive",
78
- message: "The content was successfully updated",
64
+ title: "Informative",
65
+ type: "informative",
66
+ message: "New notification!",
79
67
  })
80
68
  }
81
69
  />
82
- </>
83
- ),
70
+ )
71
+ },
72
+ }
73
+
74
+ export const UpdateNotification: Story = {
75
+ render: () => {
76
+ const { addToastNotification, updateToastNotification } =
77
+ useToastNotification()
78
+ return (
79
+ <>
80
+ <Button
81
+ label="Create notification"
82
+ classNameOverride="!mr-12"
83
+ onClick={() =>
84
+ addToastNotification({
85
+ id: "id--update-example",
86
+ title: "Cautionary",
87
+ type: "cautionary",
88
+ message: "This content will be updated",
89
+ })
90
+ }
91
+ />
92
+ <Button
93
+ label="Update notification"
94
+ onClick={() =>
95
+ updateToastNotification({
96
+ id: "id--update-example",
97
+ title: "Success",
98
+ type: "positive",
99
+ message: "The content was successfully updated",
100
+ })
101
+ }
102
+ />
103
+ </>
104
+ )
105
+ },
84
106
  }
85
107
 
86
108
  export const RemoveNotification: Story = {
87
- render: () => (
88
- <>
89
- <Button
90
- label="Create notification"
91
- classNameOverride="!mr-12"
92
- onClick={() =>
93
- addToastNotification({
94
- id: "id--remove-example",
95
- title: "Remove",
96
- type: "negative",
97
- message: "This notification will be removed",
98
- })
99
- }
100
- />
101
- <Button
102
- label="Remove notification"
103
- onClick={() => removeToastNotification("id--remove-example")}
104
- />
105
- </>
106
- ),
109
+ render: () => {
110
+ const { addToastNotification, removeToastNotification } =
111
+ useToastNotification()
112
+ return (
113
+ <>
114
+ <Button
115
+ label="Create notification"
116
+ classNameOverride="!mr-12"
117
+ onClick={() =>
118
+ addToastNotification({
119
+ id: "id--remove-example",
120
+ title: "Remove",
121
+ type: "negative",
122
+ message: "This notification will be removed",
123
+ })
124
+ }
125
+ />
126
+ <Button
127
+ label="Remove notification"
128
+ onClick={() => removeToastNotification("id--remove-example")}
129
+ />
130
+ </>
131
+ )
132
+ },
107
133
  }
108
134
 
109
135
  export const ClearNotifications: Story = {
110
- render: () => (
111
- <>
112
- <Button
113
- label="Create notifications"
114
- classNameOverride="!mr-12"
115
- onClick={() => {
116
- addToastNotification({
117
- id: "id--clear-example-1",
118
- title: "First",
119
- type: "positive",
120
- message: "This notification will be removed",
121
- })
122
- addToastNotification({
123
- id: "id--clear-example-2",
124
- title: "Second",
125
- type: "cautionary",
126
- message: "This notification will also be removed",
127
- })
128
- addToastNotification({
129
- id: "id--clear-example-3",
130
- title: "Third",
131
- type: "negative",
132
- message: "This notification will also also be removed",
133
- })
134
- }}
135
- />
136
- <Button
137
- label="Clear notifications"
138
- onClick={() => clearToastNotifications()}
139
- />
140
- </>
141
- ),
136
+ render: () => {
137
+ const { addToastNotification, clearToastNotifications } =
138
+ useToastNotification()
139
+ return (
140
+ <>
141
+ <Button
142
+ label="Create notifications"
143
+ classNameOverride="!mr-12"
144
+ onClick={() => {
145
+ addToastNotification({
146
+ id: "id--clear-example-1",
147
+ title: "First",
148
+ type: "positive",
149
+ message: "This notification will be removed",
150
+ })
151
+ addToastNotification({
152
+ id: "id--clear-example-2",
153
+ title: "Second",
154
+ type: "cautionary",
155
+ message: "This notification will also be removed",
156
+ })
157
+ addToastNotification({
158
+ id: "id--clear-example-3",
159
+ title: "Third",
160
+ type: "negative",
161
+ message: "This notification will also also be removed",
162
+ })
163
+ }}
164
+ />
165
+ <Button
166
+ label="Clear notifications"
167
+ onClick={() => clearToastNotifications()}
168
+ />
169
+ </>
170
+ )
171
+ },
142
172
  }