@windstream/react-shared-components 0.1.21 → 0.1.22

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.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "description": "Shared React components for Kinetic applications",
6
6
  "main": "dist/index.js",
@@ -1,164 +1,171 @@
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 };
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 };
@@ -46,7 +46,11 @@ export function BlogGrid({
46
46
  }
47
47
 
48
48
  return (
49
- <section aria-label="Blog articles">
49
+ <section
50
+ aria-label="Blog articles"
51
+ data-section-type={"blogs-grid"}
52
+ data-section-index={"0"}
53
+ >
50
54
  {/* Controls bar */}
51
55
  <div className="mx-auto flex max-w-[1200px] flex-wrap items-center justify-between gap-3 px-6 pb-6">
52
56
  <Text className="w-full text-center text-heading5 font-black lowercase text-text-secondary md:w-auto md:text-left">
@@ -80,7 +84,7 @@ export function BlogGrid({
80
84
  {/* Articles grid */}
81
85
  {paginatedArticles.length > 0 ? (
82
86
  <div className="mx-auto grid max-w-[1200px] grid-cols-1 gap-6 px-5 pb-16 sm:grid-cols-2 lg:grid-cols-3">
83
- {paginatedArticles.map(article => {
87
+ {paginatedArticles.map((article, index) => {
84
88
  const href = article.slug.startsWith("/")
85
89
  ? article.slug
86
90
  : `/${article.slug}`;
@@ -105,6 +109,7 @@ export function BlogGrid({
105
109
  date={article.blogCreationDate}
106
110
  category={article.category}
107
111
  image={coverImage}
112
+ index={index}
108
113
  />
109
114
  );
110
115
  })}
@@ -16,13 +16,18 @@ export const BlogCard: React.FC<BlogCardProps> = ({
16
16
  image,
17
17
  readMoreText = "Read more",
18
18
  asGrid = true,
19
+ index,
19
20
  }: BlogCardProps) => {
20
21
  const parentClassName = asGrid
21
22
  ? "flex h-full flex-col overflow-hidden rounded-xl bg-white shadow-[0_1px_4px_rgba(0,0,0,0.08),0_4px_16px_rgba(0,0,0,0.06)] transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_4px_12px_rgba(0,0,0,0.12),0_8px_24px_rgba(0,0,0,0.10)]"
22
23
  : "callout-card lg:w-[calc(33.3333%-1rem)] md:w-[calc(50%-1rem)] w-full overflow-hidden rounded-xl bg-white shadow-[0_1px_4px_rgba(0,0,0,0.08),0_4px_16px_rgba(0,0,0,0.06)] transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_4px_12px_rgba(0,0,0,0.12),0_8px_24px_rgba(0,0,0,0.10)]";
23
24
 
24
25
  return (
25
- <article className={parentClassName}>
26
+ <article
27
+ className={parentClassName}
28
+ data-section-type={"blog-card"}
29
+ data-section-index={index}
30
+ >
26
31
  {/* Image */}
27
32
  <Link href={href} tabIndex={-1} aria-hidden="true" className="block">
28
33
  <div className="aspect-video w-full flex-shrink-0 overflow-hidden bg-gray-100">
@@ -12,4 +12,5 @@ export interface BlogCardProps {
12
12
  };
13
13
  readMoreText?: string;
14
14
  asGrid?: boolean;
15
+ index?: number;
15
16
  }