@kaizen/components 1.35.2 → 1.37.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 (128) hide show
  1. package/dist/cjs/KaizenProvider/KaizenProvider.cjs +6 -1
  2. package/dist/cjs/KaizenProvider/KaizenProvider.cjs.map +1 -1
  3. package/dist/cjs/Modal/ContextModal/ContextModal.cjs +9 -6
  4. package/dist/cjs/Modal/ContextModal/ContextModal.cjs.map +1 -1
  5. package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs +33 -0
  6. package/dist/cjs/Notification/ToastNotification/ToastNotification/ToastNotification.cjs.map +1 -0
  7. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.cjs +36 -0
  8. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.cjs.map +1 -0
  9. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.cjs +7 -0
  10. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.cjs.map +1 -0
  11. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs +42 -0
  12. package/dist/cjs/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.cjs.map +1 -0
  13. package/dist/cjs/Notification/ToastNotification/context/ToastNotificationContext.cjs +72 -0
  14. package/dist/cjs/Notification/ToastNotification/context/ToastNotificationContext.cjs.map +1 -0
  15. package/dist/cjs/Notification/ToastNotification/hooks/useToastNotification.cjs +9 -0
  16. package/dist/cjs/Notification/ToastNotification/hooks/useToastNotification.cjs.map +1 -0
  17. package/dist/cjs/RichTextEditor/RichTextEditor/RichTextEditor.cjs +6 -2
  18. package/dist/cjs/RichTextEditor/RichTextEditor/RichTextEditor.cjs.map +1 -1
  19. package/dist/cjs/__future__/Select/Select.cjs +14 -1
  20. package/dist/cjs/__future__/Select/Select.cjs.map +1 -1
  21. package/dist/cjs/dts/Modal/ContextModal/ContextModal.d.ts +2 -1
  22. package/dist/cjs/dts/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +16 -0
  23. package/dist/cjs/dts/Notification/ToastNotification/ToastNotification/index.d.ts +1 -0
  24. package/dist/cjs/dts/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.d.ts +4 -0
  25. package/dist/cjs/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.d.ts +12 -0
  26. package/dist/cjs/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/index.d.ts +1 -0
  27. package/dist/cjs/dts/Notification/ToastNotification/context/ToastNotificationContext.d.ts +21 -0
  28. package/dist/cjs/dts/Notification/ToastNotification/hooks/useToastNotification.d.ts +2 -0
  29. package/dist/cjs/dts/Notification/ToastNotification/index.d.ts +3 -2
  30. package/dist/cjs/dts/Notification/ToastNotification/types.d.ts +1 -9
  31. package/dist/cjs/dts/Notification/index.d.ts +1 -0
  32. package/dist/cjs/dts/RichTextEditor/RichTextEditor/RichTextEditor.d.ts +1 -1
  33. package/dist/cjs/dts/__future__/Select/Select.d.ts +5 -1
  34. package/dist/cjs/dts/index.d.ts +4 -3
  35. package/dist/cjs/index.cjs +16 -8
  36. package/dist/cjs/index.cjs.map +1 -1
  37. package/dist/cjs/index.css +9 -8
  38. package/dist/esm/KaizenProvider/KaizenProvider.mjs +6 -1
  39. package/dist/esm/KaizenProvider/KaizenProvider.mjs.map +1 -1
  40. package/dist/esm/Modal/ContextModal/ContextModal.mjs +9 -6
  41. package/dist/esm/Modal/ContextModal/ContextModal.mjs.map +1 -1
  42. package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs +31 -0
  43. package/dist/esm/Notification/ToastNotification/ToastNotification/ToastNotification.mjs.map +1 -0
  44. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.mjs +34 -0
  45. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.mjs.map +1 -0
  46. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.mjs +5 -0
  47. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.module.scss.mjs.map +1 -0
  48. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs +40 -0
  49. package/dist/esm/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.mjs.map +1 -0
  50. package/dist/esm/Notification/ToastNotification/context/ToastNotificationContext.mjs +69 -0
  51. package/dist/esm/Notification/ToastNotification/context/ToastNotificationContext.mjs.map +1 -0
  52. package/dist/esm/Notification/ToastNotification/hooks/useToastNotification.mjs +7 -0
  53. package/dist/esm/Notification/ToastNotification/hooks/useToastNotification.mjs.map +1 -0
  54. package/dist/esm/RichTextEditor/RichTextEditor/RichTextEditor.mjs +6 -2
  55. package/dist/esm/RichTextEditor/RichTextEditor/RichTextEditor.mjs.map +1 -1
  56. package/dist/esm/__future__/Select/Select.mjs +15 -2
  57. package/dist/esm/__future__/Select/Select.mjs.map +1 -1
  58. package/dist/esm/dts/Modal/ContextModal/ContextModal.d.ts +2 -1
  59. package/dist/esm/dts/Notification/ToastNotification/ToastNotification/ToastNotification.d.ts +16 -0
  60. package/dist/esm/dts/Notification/ToastNotification/ToastNotification/index.d.ts +1 -0
  61. package/dist/esm/dts/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.d.ts +4 -0
  62. package/dist/esm/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.d.ts +12 -0
  63. package/dist/esm/dts/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/index.d.ts +1 -0
  64. package/dist/esm/dts/Notification/ToastNotification/context/ToastNotificationContext.d.ts +21 -0
  65. package/dist/esm/dts/Notification/ToastNotification/hooks/useToastNotification.d.ts +2 -0
  66. package/dist/esm/dts/Notification/ToastNotification/index.d.ts +3 -2
  67. package/dist/esm/dts/Notification/ToastNotification/types.d.ts +1 -9
  68. package/dist/esm/dts/Notification/index.d.ts +1 -0
  69. package/dist/esm/dts/RichTextEditor/RichTextEditor/RichTextEditor.d.ts +1 -1
  70. package/dist/esm/dts/__future__/Select/Select.d.ts +5 -1
  71. package/dist/esm/dts/index.d.ts +4 -3
  72. package/dist/esm/index.css +8 -7
  73. package/dist/esm/index.mjs +8 -4
  74. package/dist/esm/index.mjs.map +1 -1
  75. package/dist/index.d.ts +136 -81
  76. package/dist/styles.css +1 -1
  77. package/package.json +2 -2
  78. package/src/DatePicker/DatePicker.spec.tsx +1 -1
  79. package/src/KaizenProvider/KaizenProvider.tsx +6 -1
  80. package/src/Modal/ContextModal/ContextModal.spec.tsx +3 -3
  81. package/src/Modal/ContextModal/ContextModal.tsx +9 -5
  82. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.spec.tsx +33 -0
  83. package/src/Notification/ToastNotification/ToastNotification/ToastNotification.tsx +48 -0
  84. package/src/Notification/ToastNotification/ToastNotification/index.ts +1 -0
  85. package/src/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/ToastNotificationsList.module.scss +1 -1
  86. package/src/Notification/ToastNotification/ToastNotificationsList/ToastNotificationsList.tsx +40 -0
  87. package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/ToastNotificationsMap.tsx +49 -0
  88. package/src/Notification/ToastNotification/ToastNotificationsList/subcomponents/ToastNotificationsMap/index.ts +1 -0
  89. package/src/Notification/ToastNotification/_docs/ToastNotification.mdx +19 -14
  90. package/src/Notification/ToastNotification/_docs/ToastNotification.stickersheet.stories.tsx +33 -70
  91. package/src/Notification/ToastNotification/_docs/ToastNotification.stories.tsx +123 -93
  92. package/src/Notification/ToastNotification/context/ToastNotificationContext.tsx +96 -0
  93. package/src/Notification/ToastNotification/hooks/useToastNotification.ts +9 -0
  94. package/src/Notification/ToastNotification/index.ts +3 -2
  95. package/src/Notification/ToastNotification/types.ts +1 -18
  96. package/src/Notification/index.ts +1 -0
  97. package/src/RichTextEditor/RichTextEditor/RichTextEditor.tsx +6 -1
  98. package/src/RichTextEditor/utils/commands/addMark.spec.ts +0 -1
  99. package/src/Tooltip/Tooltip.spec.tsx +6 -1
  100. package/src/__future__/Select/Select.spec.tsx +78 -2
  101. package/src/__future__/Select/Select.tsx +18 -2
  102. package/src/__future__/Select/_docs/Select.mdx +8 -0
  103. package/src/__future__/Select/_docs/Select.stories.tsx +29 -0
  104. package/src/index.ts +4 -3
  105. package/dist/cjs/dts/Notification/ToastNotification/ToastNotification.d.ts +0 -14
  106. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.d.ts +0 -7
  107. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/index.d.ts +0 -1
  108. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationsList/ToastNotificationsList.d.ts +0 -11
  109. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.d.ts +0 -7
  110. package/dist/cjs/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/index.d.ts +0 -1
  111. package/dist/esm/dts/Notification/ToastNotification/ToastNotification.d.ts +0 -14
  112. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.d.ts +0 -7
  113. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationManager/index.d.ts +0 -1
  114. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationsList/ToastNotificationsList.d.ts +0 -11
  115. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.d.ts +0 -7
  116. package/dist/esm/dts/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/index.d.ts +0 -1
  117. package/src/Notification/ToastNotification/ToastNotification.spec.tsx +0 -31
  118. package/src/Notification/ToastNotification/ToastNotification.tsx +0 -43
  119. package/src/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.spec.tsx +0 -144
  120. package/src/Notification/ToastNotification/subcomponents/ToastNotificationManager/ToastNotificationManager.tsx +0 -135
  121. package/src/Notification/ToastNotification/subcomponents/ToastNotificationManager/index.ts +0 -1
  122. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsList/ToastNotificationsList.tsx +0 -40
  123. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.spec.tsx +0 -73
  124. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/ToastNotificationsListContainer.tsx +0 -31
  125. package/src/Notification/ToastNotification/subcomponents/ToastNotificationsListContainer/index.ts +0 -1
  126. /package/dist/cjs/dts/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/index.d.ts +0 -0
  127. /package/dist/esm/dts/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/index.d.ts +0 -0
  128. /package/src/Notification/ToastNotification/{subcomponents/ToastNotificationsList → ToastNotificationsList}/index.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaizen/components",
3
- "version": "1.35.2",
3
+ "version": "1.37.0",
4
4
  "description": "Kaizen component library",
5
5
  "author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
6
6
  "homepage": "https://cultureamp.design",
@@ -28,7 +28,7 @@
28
28
  "scripts": {
29
29
  "prepublishOnly": "yarn build:components && yarn build:styles && yarn postBuild && yarn dist:clean",
30
30
  "build": "yarn clean && yarn prepublishOnly",
31
- "test": "jest",
31
+ "test": "FORCE_COLOR=1 jest",
32
32
  "test:ci": "yarn test --ci",
33
33
  "test:treeshake": "agadoo ./dist/esm/index.mjs",
34
34
  "clean": "rimraf dist node_modules",
@@ -103,7 +103,7 @@ describe("<DatePicker />", () => {
103
103
  })
104
104
  expect(arrowButton).toHaveFocus()
105
105
  })
106
- })
106
+ }, 6000)
107
107
 
108
108
  it("should validate and close the calendar when the user presses the Enter key while focus is in the input", async () => {
109
109
  render(<DatePickerWrapper disabledDates={[new Date("2022-05-01")]} />)
@@ -1,4 +1,6 @@
1
1
  import React from "react"
2
+ import { ToastNotificationsList } from "~components/Notification"
3
+ import { ToastNotificationProvider } from "~components/Notification/ToastNotification/context/ToastNotificationContext"
2
4
  import { FontDefinitions } from "./subcomponents/FontDefinitions"
3
5
  import { OptionalIntlProvider } from "./subcomponents/OptionalIntlProvider"
4
6
 
@@ -13,7 +15,10 @@ export const KaizenProvider = ({
13
15
  }: KaizenProviderProps): JSX.Element => (
14
16
  <OptionalIntlProvider locale={locale}>
15
17
  <>
16
- {children}
18
+ <ToastNotificationProvider>
19
+ <ToastNotificationsList />
20
+ {children}
21
+ </ToastNotificationProvider>
17
22
  <FontDefinitions />
18
23
  </>
19
24
  </OptionalIntlProvider>
@@ -13,10 +13,10 @@ const ContextModalWrapper = ({
13
13
  <ContextModal
14
14
  isOpen={true}
15
15
  title="Example modal title"
16
- onConfirm={(): void => undefined}
17
- onDismiss={(): void => undefined}
16
+ onConfirm={() => undefined}
17
+ onDismiss={() => undefined}
18
18
  secondaryLabel="Example secondary"
19
- onSecondaryAction={(): void => undefined}
19
+ onSecondaryAction={() => undefined}
20
20
  {...props}
21
21
  >
22
22
  {children}
@@ -18,6 +18,7 @@ export type ContextModalSecondaryActionProps =
18
18
  }
19
19
  | {
20
20
  secondaryLabel?: undefined
21
+ onSecondaryAction?: never
21
22
  }
22
23
 
23
24
  export type ContextModalProps = Readonly<
@@ -56,6 +57,7 @@ export const ContextModal = ({
56
57
  layout = "portrait",
57
58
  title,
58
59
  onConfirm,
60
+ onDismiss: propsOnDismiss,
59
61
  onAfterLeave,
60
62
  confirmLabel = "Confirm",
61
63
  confirmWorking,
@@ -63,9 +65,11 @@ export const ContextModal = ({
63
65
  children,
64
66
  contentHeader,
65
67
  image,
68
+ secondaryLabel,
69
+ onSecondaryAction,
66
70
  ...props
67
71
  }: ContextModalProps): JSX.Element => {
68
- const onDismiss = confirmWorking ? undefined : props.onDismiss
72
+ const onDismiss = confirmWorking ? undefined : propsOnDismiss
69
73
 
70
74
  const footerActions: ButtonProps[] = []
71
75
 
@@ -82,10 +86,10 @@ export const ContextModal = ({
82
86
  footerActions.push({ ...confirmAction, ...workingProps })
83
87
  }
84
88
 
85
- if (props.secondaryLabel) {
89
+ if (secondaryLabel) {
86
90
  footerActions.push({
87
- label: props.secondaryLabel,
88
- onClick: props.onSecondaryAction,
91
+ label: secondaryLabel,
92
+ onClick: onSecondaryAction,
89
93
  disabled: !!confirmWorking,
90
94
  })
91
95
  }
@@ -126,7 +130,7 @@ export const ContextModal = ({
126
130
  {onConfirm != null && (
127
131
  <div
128
132
  className={
129
- props.secondaryLabel
133
+ secondaryLabel
130
134
  ? styles.footerWithSecondaryAction
131
135
  : styles.footer
132
136
  }
@@ -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 { useToastNotification } 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 = {