@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.
- package/dist/contentful/index.esm.js +3 -3
- package/dist/contentful/index.esm.js.map +1 -1
- package/dist/contentful/index.js +3 -3
- package/dist/contentful/index.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +13 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/next/index.esm.js +2 -2
- package/dist/next/index.esm.js.map +1 -1
- package/dist/next/index.js +2 -2
- package/dist/next/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utils/index.esm.js +1 -1
- package/dist/utils/index.esm.js.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/contentful/blocks/navigation/desktop-link-groups.tsx/index.tsx +139 -141
- package/src/contentful/blocks/navigation/index.tsx +571 -569
- package/src/contentful/blocks/navigation/mobile-link-groups.tsx/index.tsx +82 -82
|
@@ -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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
};
|