@windstream/react-shared-components 0.1.22 → 0.1.24

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": "@windstream/react-shared-components",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "type": "module",
5
5
  "description": "Shared React components for Kinetic applications",
6
6
  "main": "dist/index.js",
@@ -1,171 +1,164 @@
1
- "use client";
2
-
3
- import React, { useEffect, useMemo, useState } from "react";
4
- import useBodyScrollLock from "../../hooks/use-body-scroll-lock";
5
- import { cx } from "../../utils";
6
- import { Button } from "../button";
7
- import { MaterialIcon } from "../material-icon";
8
- import { Animation, ModalProps, Shape, Size } from "./types";
9
- import ReactModal from "react-modal";
10
- import { Transition } from "react-transition-group";
11
-
12
- type ExtendedModalProps = ModalProps & {
13
- bodyAttributes?: React.HTMLAttributes<HTMLDivElement>;
14
- };
15
-
16
- const Modal: React.FC<ExtendedModalProps> = ({
17
- size = "md",
18
- shape = "default",
19
- animation = "popper",
20
- centered,
21
- title,
22
- isOpen,
23
- children,
24
- bodyStyle,
25
- className,
26
- bodyClassName,
27
- portalClassName,
28
- overlayClassName,
29
- closeButtonClassName,
30
- closeWrapperClassName,
31
- onRequestClose,
32
- parentSelector,
33
- hideScrollOnIsOpenFalse = true,
34
- hideCloseButton = false,
35
- bodyAttributes,
36
- ...modalProps
37
- }: ExtendedModalProps) => {
38
- // Use the custom hook to lock/unlock the body scroll when the modal is open/closed.
39
- useBodyScrollLock(isOpen, hideScrollOnIsOpenFalse);
40
-
41
- // Animation cannot run at the same time as the modal opening
42
- const [isTransitioning, setIsTransitioning] = useState(false);
43
-
44
- useEffect(() => {
45
- // Run animation one frame after rendering the modal
46
- setIsTransitioning(isOpen);
47
- }, [isOpen]);
48
-
49
- const parent = useMemo(() => {
50
- /* istanbul ignore next */ if (typeof document === "undefined") return null;
51
- let parent = document.querySelector("main") || document.body;
52
- if (parentSelector)
53
- parent = document.querySelector(parentSelector) || document.body;
54
-
55
- return parent;
56
- }, [parentSelector]);
57
-
58
- if (!parent) return null;
59
-
60
- // Don't render anything when modal is closed
61
- if (!isOpen) {
62
- return null;
63
- }
64
-
65
- const getSizeClasses = (size: Size) => {
66
- const sizeMap = {
67
- xl: "inset-[5%] min-h-fit",
68
- lg: "inset-[10%] min-h-fit",
69
- md: "inset-[15%] min-h-fit",
70
- sm: "top-[18%] w-[640px]",
71
- xs: "w-[calc(100%-30px)]",
72
- };
73
- return sizeMap[size];
74
- };
75
-
76
- const getAnimationClasses = (animation: Animation, state: string) => {
77
- if (animation === "popper") {
78
- const baseClasses = "transition-transform duration-300";
79
- if (state === "entering" || state === "entered") {
80
- return `${baseClasses} opacity-100 ${state === "entered" ? "translate-y-0 pointer-events-auto" : ""}`;
81
- }
82
- if (state === "exiting" || state === "exited") {
83
- return `${baseClasses} opacity-0 translate-y-[-18px] duration-[180ms]`;
84
- }
85
- return `${baseClasses} opacity-0 translate-y-[-18px]`;
86
- }
87
- if (animation === "bottomSheet") {
88
- const baseClasses = "transition-transform duration-200 ease-in-out";
89
- if (state === "entering" || state === "entered") {
90
- return `${baseClasses} opacity-100 ${state === "entered" ? "translate-y-0 pointer-events-auto" : ""}`;
91
- }
92
- if (state === "exiting" || state === "exited") {
93
- return `${baseClasses} opacity-0 translate-y-full duration-[180ms]`;
94
- }
95
- return `${baseClasses} opacity-0 translate-y-full`;
96
- }
97
- return "";
98
- };
99
-
100
- return (
101
- <Transition enter={true} exit={true} in={isTransitioning} timeout={0}>
102
- {(state: string) => (
103
- <ReactModal
104
- ariaHideApp={false}
105
- isOpen={isOpen}
106
- onRequestClose={onRequestClose}
107
- closeTimeoutMS={0}
108
- parentSelector={() => parent}
109
- className={cx(
110
- "absolute min-w-[150px] max-w-[calc(100vw-30px)] overflow-auto rounded-lg bg-white outline-none",
111
- getSizeClasses(size),
112
- shape === "rounded" && "rounded-3xl",
113
- centered && "top-0 translate-y-[calc(50vh-50%)]",
114
- getAnimationClasses(animation, state),
115
- className
116
- )}
117
- portalClassName={cx("z-80", portalClassName)}
118
- overlayClassName={cx(
119
- "z-80 fixed inset-0 bg-black/50 flex items-center justify-center pb-[300px]",
120
- overlayClassName
121
- )}
122
- {...modalProps}
123
- >
124
- <div {...bodyAttributes}>
125
- {!hideCloseButton && (
126
- <div className={cx(closeWrapperClassName)}>
127
- <Button
128
- className={cx(
129
- "absolute right-0 top-0 float-right h-6 cursor-pointer p-5 text-text",
130
- closeButtonClassName
131
- )}
132
- onClick={onRequestClose as () => void}
133
- data-testid="close-button"
134
- data-track-element-name="modal_close_button"
135
- data-track-click-text="Close Modal"
136
- data-track-element-clicked="modal"
137
- >
138
- <MaterialIcon name="close" size={24} />
139
- </Button>
140
- </div>
141
- )}
142
-
143
- {title ? (
144
- <div
145
- className={cx(
146
- "border-b border-border-secondary-on-bg-fill px-[7px] py-[7px] text-text"
147
- )}
148
- >
149
- {title}
150
- </div>
151
- ) : null}
152
- <div
153
- className={cx("p-5", bodyClassName)}
154
- style={bodyStyle}
155
- data-testid={modalProps["data-testid"]}
156
- data-cy={modalProps["data-cy"]}
157
- >
158
- {children}
159
- </div>
160
- </div>
161
- </ReactModal>
162
- )}
163
- </Transition>
164
- );
165
- };
166
-
167
- export { Modal };
168
-
169
- Modal.displayName = "Modal";
170
-
171
- export type { ModalProps, Size, Shape, Animation };
1
+ "use client";
2
+
3
+ import React, { useEffect, useMemo, useState } from "react";
4
+ import useBodyScrollLock from "../../hooks/use-body-scroll-lock";
5
+ import { cx } from "../../utils";
6
+ import { Button } from "../button";
7
+ import { MaterialIcon } from "../material-icon";
8
+ import { Animation, ModalProps, Shape, Size } from "./types";
9
+ import ReactModal from "react-modal";
10
+ import { Transition } from "react-transition-group";
11
+
12
+ const Modal: React.FC<ModalProps> = ({
13
+ size = "md",
14
+ shape = "default",
15
+ animation = "popper",
16
+ centered,
17
+ title,
18
+ isOpen,
19
+ children,
20
+ bodyStyle,
21
+ className,
22
+ bodyClassName,
23
+ portalClassName,
24
+ overlayClassName,
25
+ closeButtonClassName,
26
+ closeWrapperClassName,
27
+ onRequestClose,
28
+ parentSelector,
29
+ hideScrollOnIsOpenFalse = true,
30
+ hideCloseButton = false,
31
+ ...modalProps
32
+ }: ModalProps) => {
33
+ // Use the custom hook to lock/unlock the body scroll when the modal is open/closed.
34
+ useBodyScrollLock(isOpen, hideScrollOnIsOpenFalse);
35
+
36
+ // Animation cannot run at the same time as the modal opening
37
+ const [isTransitioning, setIsTransitioning] = useState(false);
38
+
39
+ useEffect(() => {
40
+ // Run animation one frame after rendering the modal
41
+ setIsTransitioning(isOpen);
42
+ }, [isOpen]);
43
+
44
+ const parent = useMemo(() => {
45
+ /* istanbul ignore next */ if (typeof document === "undefined") return null;
46
+ let parent = document.querySelector("main") || document.body;
47
+ if (parentSelector)
48
+ parent = document.querySelector(parentSelector) || document.body;
49
+
50
+ return parent;
51
+ }, [parentSelector]);
52
+
53
+ if (!parent) return null;
54
+
55
+ // Don't render anything when modal is closed
56
+ if (!isOpen) {
57
+ return null;
58
+ }
59
+
60
+ const getSizeClasses = (size: Size) => {
61
+ const sizeMap = {
62
+ xl: "inset-[5%] min-h-fit",
63
+ lg: "inset-[10%] min-h-fit",
64
+ md: "inset-[15%] min-h-fit",
65
+ sm: "top-[18%] w-[640px]",
66
+ xs: "w-[calc(100%-30px)]",
67
+ };
68
+ return sizeMap[size];
69
+ };
70
+
71
+ const getAnimationClasses = (animation: Animation, state: string) => {
72
+ if (animation === "popper") {
73
+ const baseClasses = "transition-transform duration-300";
74
+ if (state === "entering" || state === "entered") {
75
+ return `${baseClasses} opacity-100 ${state === "entered" ? "translate-y-0 pointer-events-auto" : ""}`;
76
+ }
77
+ if (state === "exiting" || state === "exited") {
78
+ return `${baseClasses} opacity-0 translate-y-[-18px] duration-[180ms]`;
79
+ }
80
+ return `${baseClasses} opacity-0 translate-y-[-18px]`;
81
+ }
82
+ if (animation === "bottomSheet") {
83
+ const baseClasses = "transition-transform duration-200 ease-in-out";
84
+ if (state === "entering" || state === "entered") {
85
+ return `${baseClasses} opacity-100 ${state === "entered" ? "translate-y-0 pointer-events-auto" : ""}`;
86
+ }
87
+ if (state === "exiting" || state === "exited") {
88
+ return `${baseClasses} opacity-0 translate-y-full duration-[180ms]`;
89
+ }
90
+ return `${baseClasses} opacity-0 translate-y-full`;
91
+ }
92
+ return "";
93
+ };
94
+
95
+ return (
96
+ <Transition enter exit in={isTransitioning} timeout={0}>
97
+ {(state: string) => (
98
+ <ReactModal
99
+ ariaHideApp={false}
100
+ isOpen={isOpen}
101
+ onRequestClose={onRequestClose}
102
+ closeTimeoutMS={0}
103
+ parentSelector={() => parent}
104
+ className={cx(
105
+ "absolute min-w-[150px] max-w-[calc(100vw-30px)] overflow-auto rounded-lg bg-white outline-none",
106
+ getSizeClasses(size),
107
+ shape === "rounded" && "rounded-3xl",
108
+ centered && "top-0 translate-y-[calc(50vh-50%)]",
109
+ getAnimationClasses(animation, state),
110
+ className
111
+ )}
112
+ portalClassName={cx("z-80", portalClassName)}
113
+ overlayClassName={cx(
114
+ "z-80 fixed inset-0 bg-black/50 flex items-center justify-center pb-[300px]",
115
+ overlayClassName
116
+ )}
117
+ {...modalProps}
118
+ >
119
+ {!hideCloseButton && (
120
+ <div className={cx(closeWrapperClassName)}>
121
+ <Button
122
+ className={cx(
123
+ "absolute right-0 top-0 float-right h-6 cursor-pointer p-5 text-text",
124
+ closeButtonClassName
125
+ )}
126
+ onClick={onRequestClose as () => void}
127
+ data-testid="close-button"
128
+ data-track-element-name="modal_close_button"
129
+ data-track-click-text="Close Modal"
130
+ data-track-element-clicked="modal"
131
+ >
132
+ <MaterialIcon name="close" size={24} />
133
+ </Button>
134
+ </div>
135
+ )}
136
+
137
+ {title ? (
138
+ <div
139
+ className={cx(
140
+ "border-b border-border-secondary-on-bg-fill px-[7px] py-[7px] text-text"
141
+ )}
142
+ >
143
+ {title}
144
+ </div>
145
+ ) : null}
146
+ <div
147
+ className={cx("p-5", bodyClassName)}
148
+ style={bodyStyle}
149
+ data-testid={modalProps["data-testid"]}
150
+ data-cy={modalProps["data-cy"]}
151
+ >
152
+ {children}
153
+ </div>
154
+ </ReactModal>
155
+ )}
156
+ </Transition>
157
+ );
158
+ };
159
+
160
+ export { Modal };
161
+
162
+ Modal.displayName = "Modal";
163
+
164
+ export type { ModalProps, Size, Shape, Animation };
@@ -15,7 +15,10 @@ import { Text } from "@shared/components/text";
15
15
  import { Button } from "@shared/contentful/blocks/button";
16
16
  import { cx } from "@shared/utils";
17
17
 
18
- export const Modal: React.FC<ModalProps> = props => {
18
+ type ExtendedModalProps = ModalProps & {
19
+ containerAttributes?: React.HTMLAttributes<HTMLDivElement>;
20
+ };
21
+ export const Modal: React.FC<ExtendedModalProps> = props => {
19
22
  const {
20
23
  isOpen,
21
24
  onRequestClose,
@@ -25,6 +28,7 @@ export const Modal: React.FC<ModalProps> = props => {
25
28
  description,
26
29
  children,
27
30
  bodyClassName,
31
+ containerAttributes,
28
32
  } = props;
29
33
 
30
34
  return (
@@ -56,32 +60,34 @@ export const Modal: React.FC<ModalProps> = props => {
56
60
  )}
57
61
  style={{ maxWidth: sizeToPixel[size || "lg"] }}
58
62
  >
59
- <Dialog.Close asChild={true}>
60
- <Button
61
- showButtonAs="unstyled"
62
- buttonClassName="absolute right-0 top-0 mr-2 mt-2 bg-bg"
63
- >
64
- <MaterialIcon name="close" />
65
- </Button>
66
- </Dialog.Close>
67
- <div className="custom-modal-body max-h-[85vh] overflow-visible">
68
- {title ? (
69
- <Text
70
- className={cx(
71
- "mx-auto mb-3 mt-5 text-center",
72
- "heading5 md:max-w-[80%] md:pt-0",
73
- "mb-5 md:mb-[60px]"
74
- )}
75
- as="h2"
63
+ <div {...containerAttributes}>
64
+ <Dialog.Close asChild={true}>
65
+ <Button
66
+ showButtonAs="unstyled"
67
+ buttonClassName="absolute right-0 top-0 mr-2 mt-2 bg-bg"
76
68
  >
77
- {title}
78
- </Text>
79
- ) : null}
69
+ <MaterialIcon name="close" />
70
+ </Button>
71
+ </Dialog.Close>
72
+ <div className="custom-modal-body max-h-[85vh] overflow-visible">
73
+ {title ? (
74
+ <Text
75
+ className={cx(
76
+ "mx-auto mb-3 mt-5 text-center",
77
+ "heading5 md:max-w-[80%] md:pt-0",
78
+ "mb-5 md:mb-[60px]"
79
+ )}
80
+ as="h2"
81
+ >
82
+ {title}
83
+ </Text>
84
+ ) : null}
80
85
 
81
- {description ? <Text as="div">{description}</Text> : null}
86
+ {description ? <Text as="div">{description}</Text> : null}
82
87
 
83
- {content}
84
- {children ? children : null}
88
+ {content}
89
+ {children ? children : null}
90
+ </div>
85
91
  </div>
86
92
  </Dialog.Content>
87
93
  </motion.div>