@kaizen/components 1.70.4 → 1.70.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaizen/components",
3
- "version": "1.70.4",
3
+ "version": "1.70.6",
4
4
  "description": "Kaizen component library",
5
5
  "author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
6
6
  "homepage": "https://cultureamp.design",
@@ -11,21 +11,19 @@ export type KaizenProviderProps = {
11
11
 
12
12
  export const KaizenProvider = ({ children, locale = 'en' }: KaizenProviderProps): JSX.Element => {
13
13
  const [documentIsAvailable, setDocumentIsAvailable] = useState<boolean>(false)
14
- const [notificationsList, setNotificationsList] = useState<JSX.Element>()
15
14
 
16
15
  useEffect(() => {
17
16
  // SSR does not have a document, which is required for ToastNotificationsList.
18
17
  // Await document render before rendering the component.
19
18
  if (document !== undefined) {
20
- setNotificationsList(<ToastNotificationsList />)
21
19
  setDocumentIsAvailable(true)
22
20
  }
23
- }, [documentIsAvailable])
21
+ }, [])
24
22
 
25
23
  return (
26
24
  <OptionalIntlProvider locale={locale}>
27
25
  <ToastNotificationProvider>
28
- {notificationsList}
26
+ {documentIsAvailable && <ToastNotificationsList />}
29
27
  {children}
30
28
  </ToastNotificationProvider>
31
29
  <FontDefinitions />
@@ -1,36 +1,35 @@
1
- import React from 'react'
2
- import { createPortal } from 'react-dom'
1
+ import React, { useEffect, useState } from 'react'
3
2
  import { useToastNotificationContext } from '../context/ToastNotificationContext'
4
3
  import { ToastNotificationsMap } from './subcomponents/ToastNotificationsMap'
5
4
  import styles from './ToastNotificationsList.module.scss'
6
5
 
6
+ const toastNotificationListId = 'toast-notifications-list'
7
+
7
8
  export const ToastNotificationsList = (): JSX.Element => {
8
9
  const { notifications, removeToastNotification } = useToastNotificationContext()
10
+ const [toastContainer, setToastContainer] = useState<Element | null>(null)
9
11
 
10
- const containers = document.querySelectorAll('[data-testid="toast-notifications-list"')
11
-
12
- if (containers) {
13
- // Remove any duplicate instances
14
- // (eg. Storybook docs page has multiple stories each with their own context)
15
- containers.forEach((c, i) => {
16
- if (i === 0) return
17
- c.remove()
18
- })
19
- }
12
+ useEffect(() => {
13
+ // this is to ensure that the container is created only once. Regardless of how many KaizenProvider is set up, they will also reuse the same container.
14
+ let container = document.querySelector(`[id="${toastNotificationListId}"]`)
15
+ if (!container) {
16
+ container = document.createElement('div')
17
+ container.setAttribute('id', toastNotificationListId)
18
+ container.setAttribute('role', 'status')
19
+ container.className = styles.toastNotificationsList
20
+ document.body.appendChild(container)
21
+ }
22
+ setToastContainer(container)
23
+ }, [])
20
24
 
21
- return createPortal(
22
- <div
23
- data-testid="toast-notifications-list"
24
- role="status"
25
- className={styles.toastNotificationsList}
26
- >
27
- <ToastNotificationsMap
28
- notifications={notifications}
29
- onHide={removeToastNotification}
30
- container={containers[0]}
31
- />
32
- </div>,
33
- document.body,
25
+ return toastContainer ? (
26
+ <ToastNotificationsMap
27
+ notifications={notifications}
28
+ onHide={removeToastNotification}
29
+ container={toastContainer}
30
+ />
31
+ ) : (
32
+ <></>
34
33
  )
35
34
  }
36
35
 
@@ -5,7 +5,7 @@
5
5
  letter-spacing: var(--typography-paragraph-body-letter-spacing);
6
6
  font-weight: var(--typography-paragraph-body-font-weight);
7
7
  line-height: var(--typography-paragraph-body-line-height);
8
- color: rgba(var(--color-purple-800-rgb), 0.7);
8
+ color: var(--color-purple-800);
9
9
  padding: var(--spacing-6) var(--spacing-8);
10
10
  border: var(--border-focus-ring-border-width) var(--border-focus-ring-border-style) transparent;
11
11
  border-radius: 4px;