@windstream/react-shared-components 0.1.98 → 0.1.99

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.
@@ -1,141 +1,139 @@
1
- import React, { CSSProperties } from "react";
2
-
3
- import { MaterialIcon } from "@shared/components/material-icon";
4
- import { Text } from "@shared/components/text";
5
- import { Button } from "@shared/contentful/blocks/button";
6
- import { ButtonProps as ContentfulButtonProps } from "@shared/contentful/blocks/button/types";
7
- import { useOutsideClick } from "@shared/hooks/use-outside-click";
8
- import { cx } from "@shared/utils";
9
-
10
- type ComponentButtonGroup = {
11
- anchorId?: string | null;
12
- title?: string | null;
13
- items?: { items?: ContentfulButtonProps[] | null } | null;
14
- };
15
-
16
- type Link = ContentfulButtonProps | ComponentButtonGroup;
17
-
18
- type LinkGroupsProps = {
19
- link?: Link;
20
- anchorName: string;
21
- /**
22
- * Tailwind text-color class to apply to the top-level link/group
23
- * label. Lets the parent navbar invert text color (e.g. `text-white`)
24
- * when rendered on a dark background. Submenu items keep their
25
- * default `text-text-link` so they remain readable on the white
26
- * popover background.
27
- */
28
- linkColorClassName?: string;
29
- };
30
-
31
- const isButton = (link: Link): link is ContentfulButtonProps => {
32
- // If your group never has `href`, this is a simple and effective guard
33
- return typeof (link as ContentfulButtonProps).href === "string";
34
- };
35
-
36
- export const DesktopLinkGroups: React.FC<LinkGroupsProps> = ({
37
- link,
38
- anchorName,
39
- linkColorClassName,
40
- }) => {
41
- const [isOpen, setIsOpen] = React.useState(false);
42
-
43
- const ref = React.useRef<HTMLDivElement>(null);
44
- useOutsideClick(ref, () => setIsOpen(false));
45
-
46
- if (!link) return null;
47
-
48
- // Single button
49
- if (isButton(link)) {
50
- return (
51
- <Button
52
- key={`submenu-link-btn-${link.anchorId}`}
53
- {...link}
54
- showButtonAs="text"
55
- linkClassName={cx(
56
- "body3 inline-flex items-center no-underline hover:underline",
57
- linkColorClassName || "text-text"
58
- )}
59
- />
60
- );
61
- }
62
-
63
-
64
- // Group
65
- const { anchorId, title, items } = link;
66
- const subMenu = Array.isArray(items?.items) ? items!.items! : [];
67
- const fullAnchorName = `--link-anchor-${anchorName}`;
68
-
69
- return (
70
- <div
71
- className="relative h-full"
72
- style={{ anchorName: fullAnchorName } as CSSProperties}
73
- ref={ref}
74
- >
75
- <Button
76
- onClick={() => setIsOpen(prev => !prev)}
77
- aria-expanded={isOpen}
78
- buttonClassName={cx(
79
- "group body3 flex items-center h-full",
80
- linkColorClassName || "text-text"
81
- )}
82
- key={anchorId}
83
- showButtonAs="unstyled"
84
- >
85
-
86
- <Text as="span" className="group-hover:underline leading-none">
87
- {title ?? null}
88
- </Text>
89
- <MaterialIcon
90
- weight="200"
91
- size={24}
92
- className="text-icon-secondary group-hover:opacity-50 mt-[1px]"
93
- name={isOpen ? "keyboard_arrow_up" : "keyboard_arrow_down"}
94
- />
95
- </Button>
96
-
97
- <div
98
- className={cx(
99
- "shadow-navDrop fixed z-[1001] min-w-44 rounded-input-poppers border border-border bg-bg",
100
- "transition-[opacity,transform] ease-out",
101
- isOpen && subMenu.length > 0
102
- ? "pointer-events-auto translate-y-0 opacity-100 duration-75"
103
- : "pointer-events-none -translate-y-2 opacity-0 duration-0"
104
- )}
105
- style={
106
- {
107
- positionAnchor: fullAnchorName,
108
- top: "anchor(bottom)",
109
- left: "calc((anchor(left) + anchor(right)) / 2)",
110
- translate: "-50% 0",
111
- } as CSSProperties
112
- }
113
- >
114
- <ul
115
- className="flex flex-col gap-2 py-2"
116
- onClick={event => {
117
- // Close the popup when a submenu link is clicked.
118
- // Required for Pages Router where this component persists across
119
- // client-side navigations and `isOpen` would otherwise stay true.
120
- const target = event.target as HTMLElement | null;
121
- if (target?.closest("a")) {
122
- setIsOpen(false);
123
- }
124
- }}
125
- >
126
- {subMenu.map((site, index) => {
127
- return (
128
- <li key={`submenu-link-${index}`} className="submenu-link">
129
- <Button
130
- {...site}
131
- showButtonAs="text"
132
- linkClassName="body3 px-3 flex items-center text-text-link no-underline hover:underline hover:bg-bg-surface-hover"
133
- />
134
- </li>
135
- );
136
- })}
137
- </ul>
138
- </div>
139
- </div>
140
- );
141
- };
1
+ import React, { CSSProperties } from "react";
2
+
3
+ import { MaterialIcon } from "@shared/components/material-icon";
4
+ import { Text } from "@shared/components/text";
5
+ import { Button } from "@shared/contentful/blocks/button";
6
+ import { ButtonProps as ContentfulButtonProps } from "@shared/contentful/blocks/button/types";
7
+ import { useOutsideClick } from "@shared/hooks/use-outside-click";
8
+ import { cx } from "@shared/utils";
9
+
10
+ type ComponentButtonGroup = {
11
+ anchorId?: string | null;
12
+ title?: string | null;
13
+ items?: { items?: ContentfulButtonProps[] | null } | null;
14
+ };
15
+
16
+ type Link = ContentfulButtonProps | ComponentButtonGroup;
17
+
18
+ type LinkGroupsProps = {
19
+ link?: Link;
20
+ anchorName: string;
21
+ /**
22
+ * Tailwind text-color class to apply to the top-level link/group
23
+ * label. Lets the parent navbar invert text color (e.g. `text-white`)
24
+ * when rendered on a dark background. Submenu items keep their
25
+ * default `text-text-link` so they remain readable on the white
26
+ * popover background.
27
+ */
28
+ linkColorClassName?: string;
29
+ };
30
+
31
+ const isButton = (link: Link): link is ContentfulButtonProps => {
32
+ // If your group never has `href`, this is a simple and effective guard
33
+ return typeof (link as ContentfulButtonProps).href === "string";
34
+ };
35
+
36
+ export const DesktopLinkGroups: React.FC<LinkGroupsProps> = ({
37
+ link,
38
+ anchorName,
39
+ linkColorClassName,
40
+ }) => {
41
+ const [isOpen, setIsOpen] = React.useState(false);
42
+
43
+ const ref = React.useRef<HTMLDivElement>(null);
44
+ useOutsideClick(ref, () => setIsOpen(false));
45
+
46
+ if (!link) return null;
47
+
48
+ // Single button
49
+ if (isButton(link)) {
50
+ return (
51
+ <Button
52
+ key={`submenu-link-btn-${link.anchorId}`}
53
+ {...link}
54
+ linkClassName={cx(
55
+ "body3 flex items-center h-full",
56
+ linkColorClassName || "text-text"
57
+ )}
58
+ linkVariant="unstyled"
59
+ />
60
+ );
61
+ }
62
+
63
+ // Group
64
+ const { anchorId, title, items } = link;
65
+ const subMenu = Array.isArray(items?.items) ? items!.items! : [];
66
+ const fullAnchorName = `--link-anchor-${anchorName}`;
67
+
68
+ return (
69
+ <div
70
+ className="relative h-full"
71
+ style={{ anchorName: fullAnchorName } as CSSProperties}
72
+ ref={ref}
73
+ >
74
+ <Button
75
+ onClick={() => setIsOpen(prev => !prev)}
76
+ aria-expanded={isOpen}
77
+ buttonClassName={cx(
78
+ "group body3 flex items-center h-full",
79
+ linkColorClassName || "text-text"
80
+ )}
81
+ key={anchorId}
82
+ showButtonAs="unstyled"
83
+ >
84
+ <Text as="span" className="group-hover:underline">
85
+ {title ?? null}
86
+ </Text>
87
+ <MaterialIcon
88
+ weight="200"
89
+ size={24}
90
+ className="group-hover:opacity-50 text-icon-secondary"
91
+ name={isOpen ? "keyboard_arrow_up" : "keyboard_arrow_down"}
92
+ />
93
+ </Button>
94
+
95
+ <div
96
+ className={cx(
97
+ "shadow-navDrop fixed z-[1001] min-w-44 rounded-input-poppers border border-border bg-bg",
98
+ "transition-[opacity,transform] ease-out",
99
+ isOpen && subMenu.length > 0
100
+ ? "pointer-events-auto translate-y-0 opacity-100 duration-75"
101
+ : "pointer-events-none -translate-y-2 opacity-0 duration-0"
102
+ )}
103
+ style={
104
+ {
105
+ positionAnchor: fullAnchorName,
106
+ top: "anchor(bottom)",
107
+ left: "calc((anchor(left) + anchor(right)) / 2)",
108
+ translate: "-50% 0",
109
+ } as CSSProperties
110
+ }
111
+ >
112
+ <ul
113
+ className="flex flex-col gap-2 py-2"
114
+ onClick={event => {
115
+ // Close the popup when a submenu link is clicked.
116
+ // Required for Pages Router where this component persists across
117
+ // client-side navigations and `isOpen` would otherwise stay true.
118
+ const target = event.target as HTMLElement | null;
119
+ if (target?.closest("a")) {
120
+ setIsOpen(false);
121
+ }
122
+ }}
123
+ >
124
+ {subMenu.map((site, index) => {
125
+ return (
126
+ <li key={`submenu-link-${index}`} className="submenu-link type1">
127
+ <Button
128
+ {...site}
129
+ linkVariant="unstyled"
130
+ linkClassName="body3 px-4 hover:bg-bg-surface-hover flex items-center w-full h-11 text-text-link"
131
+ />
132
+ </li>
133
+ );
134
+ })}
135
+ </ul>
136
+ </div>
137
+ </div>
138
+ );
139
+ };