@hashicorp/react-components 0.0.0-nightly.ad81ac2 → 0.0.0-nightly.b5f9cca
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 +1 -1
- package/src/components/nav-panel/components/link-list/index.tsx +18 -2
- package/src/components/nav-panel/standard-panel/index.tsx +3 -0
- package/src/components/subnav/index.tsx +6 -1
- package/src/components/subnav/partials/MenuItemsDefault/index.tsx +19 -5
- package/src/components/subnav/partials/MenuItemsOverflow/index.tsx +12 -2
- package/src/components/subnav/partials/TitleLink/index.tsx +3 -1
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import * as NavigationMenu from '@radix-ui/react-navigation-menu'
|
|
|
6
6
|
import s from './style.module.css'
|
|
7
7
|
|
|
8
8
|
export interface LinkListProps {
|
|
9
|
+
locale?: string
|
|
9
10
|
links: {
|
|
10
11
|
title: string
|
|
11
12
|
url: string
|
|
@@ -37,7 +38,21 @@ const GRADIENT_VALUE_MAP = new Map([
|
|
|
37
38
|
],
|
|
38
39
|
])
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
function getLocalizedHref(url: string, locale?: string): string {
|
|
42
|
+
const parsedHref = parseUrl(url).href
|
|
43
|
+
|
|
44
|
+
if (parsedHref.startsWith('/') && locale) {
|
|
45
|
+
return `/${locale}${parsedHref}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return parsedHref
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default function LinkList({
|
|
52
|
+
locale,
|
|
53
|
+
links,
|
|
54
|
+
linkClickHandler,
|
|
55
|
+
}: LinkListProps) {
|
|
41
56
|
return (
|
|
42
57
|
<ul className={s.linkList}>
|
|
43
58
|
{links.map((link) => {
|
|
@@ -53,8 +68,9 @@ export default function LinkList({ links, linkClickHandler }: LinkListProps) {
|
|
|
53
68
|
<li key={link.title}>
|
|
54
69
|
<NavigationMenu.Link asChild>
|
|
55
70
|
<Link
|
|
71
|
+
hrefLang={locale ? locale : undefined}
|
|
56
72
|
className={s.link}
|
|
57
|
-
href={
|
|
73
|
+
href={getLocalizedHref(link.url, locale)}
|
|
58
74
|
onClickCapture={() => {
|
|
59
75
|
linkClickHandler && linkClickHandler(link.title, link.url)
|
|
60
76
|
}}
|
|
@@ -12,12 +12,14 @@ interface StandardPanelProps {
|
|
|
12
12
|
navData: NavItem[]
|
|
13
13
|
promo?: PromoProps
|
|
14
14
|
sectionName?: string
|
|
15
|
+
locale?: any
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const StandardPanel = ({
|
|
18
19
|
navData,
|
|
19
20
|
promo,
|
|
20
21
|
sectionName = '',
|
|
22
|
+
locale,
|
|
21
23
|
}: StandardPanelProps) => {
|
|
22
24
|
return (
|
|
23
25
|
<NavPanel.Root>
|
|
@@ -26,6 +28,7 @@ const StandardPanel = ({
|
|
|
26
28
|
return (
|
|
27
29
|
<NavPanel.Column key={stableIdx}>
|
|
28
30
|
<LinkList
|
|
31
|
+
locale={locale}
|
|
29
32
|
links={navItems}
|
|
30
33
|
linkClickHandler={(text, href) => {
|
|
31
34
|
trackNavClickEvent(text, href, sectionName)
|
|
@@ -18,6 +18,7 @@ import traverse, { isObject } from './helpers/traverse'
|
|
|
18
18
|
import { areBasePathsMatching } from './helpers/areBasePathsMatching'
|
|
19
19
|
import * as NavigationMenu from '@radix-ui/react-navigation-menu'
|
|
20
20
|
import s from './style.module.css'
|
|
21
|
+
import { getLocalizedHref } from '@web/utils/get-localized-href'
|
|
21
22
|
|
|
22
23
|
const productAllowList = {
|
|
23
24
|
consul: 'consul',
|
|
@@ -46,6 +47,7 @@ type SubnavDropdown = {
|
|
|
46
47
|
type MenuItem = SubnavLink | SubnavDropdown | 'divider'
|
|
47
48
|
|
|
48
49
|
export interface SubnavInnerProps {
|
|
50
|
+
locale?: string
|
|
49
51
|
hasOverflow?: boolean
|
|
50
52
|
titleLink: { text: string; url: string }
|
|
51
53
|
product?: Products
|
|
@@ -61,6 +63,7 @@ export interface SubnavInnerProps {
|
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
function SubnavInner({
|
|
66
|
+
locale,
|
|
64
67
|
hasOverflow,
|
|
65
68
|
titleLink,
|
|
66
69
|
product,
|
|
@@ -109,8 +112,9 @@ function SubnavInner({
|
|
|
109
112
|
>
|
|
110
113
|
<NavigationMenu.Link asChild>
|
|
111
114
|
<TitleLink
|
|
115
|
+
locale={locale}
|
|
112
116
|
text={titleLink.text}
|
|
113
|
-
url={titleLink.url}
|
|
117
|
+
url={getLocalizedHref(titleLink.url)}
|
|
114
118
|
product={product}
|
|
115
119
|
theme={theme}
|
|
116
120
|
/>
|
|
@@ -121,6 +125,7 @@ function SubnavInner({
|
|
|
121
125
|
<MenuItemsDefault
|
|
122
126
|
menuItems={menuItemsWithActive}
|
|
123
127
|
activatePanel={activatePanel}
|
|
128
|
+
locale={locale}
|
|
124
129
|
/>
|
|
125
130
|
{ctaLinks?.length > 0 && (
|
|
126
131
|
<CtaLinks
|
|
@@ -10,6 +10,7 @@ import DropdownTrigger from '../DropdownTrigger'
|
|
|
10
10
|
import * as NavigationMenu from '@radix-ui/react-navigation-menu'
|
|
11
11
|
import s from './style.module.css'
|
|
12
12
|
import FlightIcon from '@hashicorp/react-hds/src/components/flight-icon'
|
|
13
|
+
import { getLocalizedHref } from '@web/utils/get-localized-href'
|
|
13
14
|
|
|
14
15
|
interface MenuItemsDefaultProps {
|
|
15
16
|
menuItems: (
|
|
@@ -27,10 +28,11 @@ interface MenuItemsDefaultProps {
|
|
|
27
28
|
| 'divider'
|
|
28
29
|
)[]
|
|
29
30
|
activatePanel: (panel: string) => void
|
|
31
|
+
locale?: string
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
function MenuItemsDefault(props: MenuItemsDefaultProps) {
|
|
33
|
-
const { menuItems, activatePanel } = props
|
|
35
|
+
const { menuItems, activatePanel, locale } = props
|
|
34
36
|
return (
|
|
35
37
|
<NavigationMenu.List className={s.root}>
|
|
36
38
|
{menuItems.map((menuItem, stableIdx) => {
|
|
@@ -47,6 +49,7 @@ function MenuItemsDefault(props: MenuItemsDefaultProps) {
|
|
|
47
49
|
text={text}
|
|
48
50
|
submenu={submenu}
|
|
49
51
|
activatePanel={activatePanel}
|
|
52
|
+
locale={locale}
|
|
50
53
|
/>
|
|
51
54
|
) : (
|
|
52
55
|
<NavLink
|
|
@@ -56,6 +59,7 @@ function MenuItemsDefault(props: MenuItemsDefaultProps) {
|
|
|
56
59
|
text={text}
|
|
57
60
|
url={url}
|
|
58
61
|
isActive={_isActiveUrl}
|
|
62
|
+
locale={locale}
|
|
59
63
|
/>
|
|
60
64
|
)
|
|
61
65
|
})}
|
|
@@ -75,14 +79,19 @@ interface NavLinkProps {
|
|
|
75
79
|
text: string
|
|
76
80
|
url: string
|
|
77
81
|
isActive: boolean
|
|
82
|
+
locale?: string
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
function NavLink(props: NavLinkProps) {
|
|
81
|
-
const { text, url, isActive } = props
|
|
86
|
+
const { text, url, isActive, locale } = props
|
|
82
87
|
return (
|
|
83
88
|
<NavigationMenu.Item className={s.listItem}>
|
|
84
89
|
<NavigationMenu.Link asChild>
|
|
85
|
-
<Link
|
|
90
|
+
<Link
|
|
91
|
+
className={s.navLink}
|
|
92
|
+
href={getLocalizedHref(url, locale)}
|
|
93
|
+
hrefLang={props.locale ? props.locale : undefined}
|
|
94
|
+
>
|
|
86
95
|
<NavItemText isActive={isActive} text={text} />
|
|
87
96
|
</Link>
|
|
88
97
|
</NavigationMenu.Link>
|
|
@@ -94,6 +103,7 @@ interface NavLinkWithDropdownProps {
|
|
|
94
103
|
text: string
|
|
95
104
|
submenu: { icon: string; text: string; url: string; _isActiveUrl: string }[]
|
|
96
105
|
activatePanel: (panel: string) => void
|
|
106
|
+
locale?: string
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
interface NavLinkWithDropdownState {
|
|
@@ -105,7 +115,7 @@ class NavLinkWithDropdown extends React.Component<
|
|
|
105
115
|
NavLinkWithDropdownState
|
|
106
116
|
> {
|
|
107
117
|
render() {
|
|
108
|
-
const { text, submenu, activatePanel } = this.props
|
|
118
|
+
const { text, submenu, activatePanel, locale } = this.props
|
|
109
119
|
const hasActiveChild = submenu.some((s) => s._isActiveUrl)
|
|
110
120
|
|
|
111
121
|
const handleFocusOutside = () => {
|
|
@@ -139,7 +149,11 @@ class NavLinkWithDropdown extends React.Component<
|
|
|
139
149
|
// eslint-disable-next-line react/no-array-index-key
|
|
140
150
|
<NavigationMenu.Item key={stableIdx}>
|
|
141
151
|
<NavigationMenu.Link asChild>
|
|
142
|
-
<Link
|
|
152
|
+
<Link
|
|
153
|
+
className={s.submenuItem}
|
|
154
|
+
href={getLocalizedHref(url, locale)}
|
|
155
|
+
hrefLang={locale ? locale : undefined}
|
|
156
|
+
>
|
|
143
157
|
{icon ? <FlightIcon name={icon} /> : null}
|
|
144
158
|
{text}
|
|
145
159
|
</Link>
|
|
@@ -13,6 +13,7 @@ import * as NavigationMenu from '@radix-ui/react-navigation-menu'
|
|
|
13
13
|
import classNames from 'classnames'
|
|
14
14
|
import s from './style.module.css'
|
|
15
15
|
import FlightIcon from '@hashicorp/react-hds/src/components/flight-icon'
|
|
16
|
+
import { getLocalizedHref } from '@web/utils/get-localized-href'
|
|
16
17
|
|
|
17
18
|
interface MenuItemsOverflowProps {
|
|
18
19
|
menuItems: (
|
|
@@ -29,6 +30,7 @@ interface MenuItemsOverflowProps {
|
|
|
29
30
|
menuText: string
|
|
30
31
|
constrainWidth?: boolean
|
|
31
32
|
activatePanel: (panel: string) => void
|
|
33
|
+
locale?: string
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
interface MenuItemsOverflowState {
|
|
@@ -48,6 +50,7 @@ class MenuItemsOverflow extends React.Component<
|
|
|
48
50
|
menuText,
|
|
49
51
|
constrainWidth,
|
|
50
52
|
activatePanel,
|
|
53
|
+
locale,
|
|
51
54
|
} = this.props
|
|
52
55
|
|
|
53
56
|
const handleFocusOutside = () => {
|
|
@@ -91,6 +94,7 @@ class MenuItemsOverflow extends React.Component<
|
|
|
91
94
|
url={subItem.url}
|
|
92
95
|
text={subItem.text}
|
|
93
96
|
icon={subItem.icon}
|
|
97
|
+
locale={locale}
|
|
94
98
|
/>
|
|
95
99
|
))}
|
|
96
100
|
<hr className={s.divider} />
|
|
@@ -125,13 +129,19 @@ interface SubmenuItemProps {
|
|
|
125
129
|
icon?: string
|
|
126
130
|
url: string
|
|
127
131
|
text: string
|
|
132
|
+
locale?: string
|
|
128
133
|
}
|
|
129
134
|
|
|
130
|
-
function SubmenuItem({ icon, url, text }: SubmenuItemProps) {
|
|
135
|
+
function SubmenuItem({ icon, url, text, locale }: SubmenuItemProps) {
|
|
131
136
|
return (
|
|
132
137
|
<li>
|
|
133
138
|
<NavigationMenu.Link asChild>
|
|
134
|
-
<Link
|
|
139
|
+
<Link
|
|
140
|
+
className={s.submenuItem}
|
|
141
|
+
href={getLocalizedHref(url, locale)}
|
|
142
|
+
title={vercelSplit(text)}
|
|
143
|
+
hrefLang={locale ? locale : undefined}
|
|
144
|
+
>
|
|
135
145
|
{icon ? <FlightIcon name={icon} /> : null}
|
|
136
146
|
{text}
|
|
137
147
|
</Link>
|
|
@@ -41,6 +41,7 @@ const logoDict = {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
interface TitleLinkProps {
|
|
44
|
+
locale?: string
|
|
44
45
|
text: string
|
|
45
46
|
url: string
|
|
46
47
|
product?: string
|
|
@@ -80,7 +81,7 @@ function getLogo(
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
const TitleLink = forwardRef<HTMLAnchorElement, TitleLinkProps>(
|
|
83
|
-
({ text, url, product, theme }, ref) => {
|
|
84
|
+
({ text, url, product, theme, locale }, ref) => {
|
|
84
85
|
const parsedText = vercelSplit(text)
|
|
85
86
|
const Logo = getLogo(parsedText, theme)
|
|
86
87
|
|
|
@@ -94,6 +95,7 @@ const TitleLink = forwardRef<HTMLAnchorElement, TitleLinkProps>(
|
|
|
94
95
|
href={url}
|
|
95
96
|
title={parsedText}
|
|
96
97
|
ref={ref}
|
|
98
|
+
hrefLang={locale ? locale : undefined}
|
|
97
99
|
>
|
|
98
100
|
{Logo ? (
|
|
99
101
|
<Image
|