@kaizen/components 1.36.0 → 1.37.1
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/dist/cjs/KaizenProvider/KaizenProvider.cjs +15 -1
- package/dist/cjs/KaizenProvider/KaizenProvider.cjs.map +1 -1
- package/dist/cjs/dts/index.d.ts +4 -3
- package/dist/cjs/index.cjs +10 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.css +7 -7
- package/dist/esm/KaizenProvider/KaizenProvider.mjs +16 -2
- package/dist/esm/KaizenProvider/KaizenProvider.mjs.map +1 -1
- package/dist/esm/dts/index.d.ts +4 -3
- package/dist/esm/index.css +8 -8
- package/dist/esm/index.mjs +5 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/index.d.ts +87 -79
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/KaizenProvider/KaizenProvider.tsx +26 -12
- package/src/Modal/GenericModal/GenericModal.spec.tsx +34 -45
- package/src/Notification/ToastNotification/_docs/ToastNotification.mdx +1 -1
- package/src/index.ts +4 -3
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react"
|
|
1
|
+
import React, { useEffect, useState } from "react"
|
|
2
2
|
import { ToastNotificationsList } from "~components/Notification"
|
|
3
3
|
import { ToastNotificationProvider } from "~components/Notification/ToastNotification/context/ToastNotificationContext"
|
|
4
4
|
import { FontDefinitions } from "./subcomponents/FontDefinitions"
|
|
@@ -12,16 +12,30 @@ export type KaizenProviderProps = {
|
|
|
12
12
|
export const KaizenProvider = ({
|
|
13
13
|
children,
|
|
14
14
|
locale = "en",
|
|
15
|
-
}: KaizenProviderProps): JSX.Element =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
}: KaizenProviderProps): JSX.Element => {
|
|
16
|
+
const [documentIsAvailable, setDocumentIsAvailable] = useState<boolean>(false)
|
|
17
|
+
const [notificationsList, setNotificationsList] = useState<JSX.Element>()
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
// SSR does not have a document, which is required for ToastNotificationsList.
|
|
21
|
+
// Await document render before rendering the component.
|
|
22
|
+
if (document !== undefined) {
|
|
23
|
+
setNotificationsList(<ToastNotificationsList />)
|
|
24
|
+
setDocumentIsAvailable(true)
|
|
25
|
+
}
|
|
26
|
+
}, [documentIsAvailable])
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<OptionalIntlProvider locale={locale}>
|
|
30
|
+
<>
|
|
31
|
+
<ToastNotificationProvider>
|
|
32
|
+
{notificationsList}
|
|
33
|
+
{children}
|
|
34
|
+
</ToastNotificationProvider>
|
|
35
|
+
<FontDefinitions />
|
|
36
|
+
</>
|
|
37
|
+
</OptionalIntlProvider>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
26
40
|
|
|
27
41
|
KaizenProvider.displayName = "KaizenProvider"
|
|
@@ -1,59 +1,60 @@
|
|
|
1
1
|
import React from "react"
|
|
2
|
-
import { render, waitFor } from "@testing-library/react"
|
|
2
|
+
import { render, screen, waitFor } from "@testing-library/react"
|
|
3
3
|
import userEvent from "@testing-library/user-event"
|
|
4
|
-
import { GenericModal } from "./GenericModal"
|
|
4
|
+
import { GenericModal, GenericModalProps } from "./GenericModal"
|
|
5
|
+
import { ModalAccessibleLabel } from "./subcomponents/ModalAccessibleLabel"
|
|
6
|
+
import { ModalBody } from "./subcomponents/ModalBody"
|
|
7
|
+
import { ModalHeader } from "./subcomponents/ModalHeader"
|
|
5
8
|
|
|
6
9
|
const user = userEvent.setup()
|
|
7
10
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
setIsOpen(false)
|
|
16
|
-
props.onEscapeKeyup?.()
|
|
17
|
-
}
|
|
11
|
+
const GenericModalWrapper = ({
|
|
12
|
+
isOpen: propsIsOpen,
|
|
13
|
+
onOutsideModalClick,
|
|
14
|
+
onEscapeKeyup,
|
|
15
|
+
...props
|
|
16
|
+
}: Partial<GenericModalProps>): JSX.Element => {
|
|
17
|
+
const [isOpen, setIsOpen] = React.useState<boolean>(propsIsOpen ?? true)
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
20
|
<GenericModal
|
|
21
21
|
isOpen={isOpen}
|
|
22
|
-
onOutsideModalClick={
|
|
23
|
-
|
|
22
|
+
onOutsideModalClick={e => {
|
|
23
|
+
setIsOpen(false)
|
|
24
|
+
onOutsideModalClick?.(e)
|
|
25
|
+
}}
|
|
26
|
+
onEscapeKeyup={e => {
|
|
27
|
+
setIsOpen(false)
|
|
28
|
+
onEscapeKeyup?.(e)
|
|
29
|
+
}}
|
|
24
30
|
onAfterLeave={props.onAfterLeave}
|
|
25
31
|
id="GenericModalTestId"
|
|
26
32
|
>
|
|
27
|
-
|
|
33
|
+
<ModalHeader>
|
|
34
|
+
<ModalAccessibleLabel>Example</ModalAccessibleLabel>
|
|
35
|
+
</ModalHeader>
|
|
36
|
+
<ModalBody>Body contents here</ModalBody>
|
|
28
37
|
</GenericModal>
|
|
29
38
|
)
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
describe("<GenericModal />", () => {
|
|
33
42
|
it("renders an open modal with the provided content", () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
expect(getByText("Example")).toBeTruthy()
|
|
43
|
+
render(<GenericModalWrapper />)
|
|
44
|
+
expect(screen.getByText("Example")).toBeVisible()
|
|
38
45
|
})
|
|
39
46
|
|
|
40
47
|
it("does not render a closed modal with the provided content", () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
expect(() => getByText("Example")).toThrow()
|
|
48
|
+
render(<GenericModalWrapper isOpen={false} />)
|
|
49
|
+
expect(screen.queryByText("Example")).not.toBeInTheDocument()
|
|
45
50
|
})
|
|
46
51
|
|
|
47
52
|
it("closes the modal when escape key is pressed", async () => {
|
|
48
53
|
const handleDismiss = jest.fn()
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
<ExampleModalWithState onEscapeKeyup={handleDismiss}>
|
|
52
|
-
Example
|
|
53
|
-
</ExampleModalWithState>
|
|
54
|
-
)
|
|
55
|
+
render(<GenericModalWrapper onEscapeKeyup={handleDismiss} />)
|
|
55
56
|
|
|
56
|
-
const modal = getByTestId("GenericModalTestId")
|
|
57
|
+
const modal = screen.getByTestId("GenericModalTestId")
|
|
57
58
|
|
|
58
59
|
await waitFor(() => {
|
|
59
60
|
expect(modal).toBeVisible()
|
|
@@ -70,17 +71,9 @@ describe("<GenericModal />", () => {
|
|
|
70
71
|
|
|
71
72
|
it("closes the modal when a click is outside of the modal content", async () => {
|
|
72
73
|
const handleDismiss = jest.fn()
|
|
73
|
-
|
|
74
|
-
<GenericModal
|
|
75
|
-
isOpen={true}
|
|
76
|
-
onOutsideModalClick={handleDismiss}
|
|
77
|
-
id="GenericModalTestId"
|
|
78
|
-
>
|
|
79
|
-
Example
|
|
80
|
-
</GenericModal>
|
|
81
|
-
)
|
|
74
|
+
render(<GenericModalWrapper onOutsideModalClick={handleDismiss} />)
|
|
82
75
|
|
|
83
|
-
await user.click(getByTestId("GenericModalTestId-scrollLayer"))
|
|
76
|
+
await user.click(screen.getByTestId("GenericModalTestId-scrollLayer"))
|
|
84
77
|
await waitFor(() => {
|
|
85
78
|
expect(handleDismiss).toHaveBeenCalledTimes(1)
|
|
86
79
|
})
|
|
@@ -88,13 +81,9 @@ describe("<GenericModal />", () => {
|
|
|
88
81
|
|
|
89
82
|
it("calls onAfterLeave after it closes", async () => {
|
|
90
83
|
const mockOnAfterLeave = jest.fn()
|
|
84
|
+
render(<GenericModalWrapper onAfterLeave={mockOnAfterLeave} />)
|
|
91
85
|
|
|
92
|
-
|
|
93
|
-
<ExampleModalWithState onAfterLeave={mockOnAfterLeave}>
|
|
94
|
-
Catch me if you can
|
|
95
|
-
</ExampleModalWithState>
|
|
96
|
-
)
|
|
97
|
-
await user.click(getByTestId("GenericModalTestId-scrollLayer"))
|
|
86
|
+
await user.click(screen.getByTestId("GenericModalTestId-scrollLayer"))
|
|
98
87
|
await waitFor(() => expect(mockOnAfterLeave).toHaveBeenCalledTimes(1))
|
|
99
88
|
})
|
|
100
89
|
})
|
|
@@ -17,7 +17,7 @@ import * as ToastNotificationStories from "./ToastNotification.stories"
|
|
|
17
17
|
|
|
18
18
|
<Installation
|
|
19
19
|
installCommand="yarn add @kaizen/components"
|
|
20
|
-
importStatement='import {
|
|
20
|
+
importStatement='import { useToastNotification } from "@kaizen/components"'
|
|
21
21
|
/>
|
|
22
22
|
|
|
23
23
|
## Overview
|
package/src/index.ts
CHANGED
|
@@ -48,13 +48,14 @@ export * from "./Table"
|
|
|
48
48
|
export * from "./Tabs"
|
|
49
49
|
export * from "./Tag"
|
|
50
50
|
export * from "./Text"
|
|
51
|
-
export * from "./TextField"
|
|
52
51
|
export * from "./TextArea"
|
|
53
52
|
export * from "./TextAreaField"
|
|
53
|
+
export * from "./TextField"
|
|
54
54
|
export * from "./Tile"
|
|
55
55
|
export * from "./TimeField"
|
|
56
|
+
export * from "./TitleBlockZen"
|
|
56
57
|
export * from "./ToggleSwitch"
|
|
57
58
|
export * from "./Tooltip"
|
|
58
|
-
export * from "./
|
|
59
|
-
export * from "./Workflow"
|
|
59
|
+
export * from "./VisuallyHidden"
|
|
60
60
|
export * from "./Well"
|
|
61
|
+
export * from "./Workflow"
|