@hashicorp/react-components 0.0.0-nightly.48bfabb → 0.0.0-nightly.52c0d39
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 +4 -3
- package/src/components/actions/index.tsx +5 -5
- package/src/components/call-to-action/index.tsx +7 -7
- package/src/components/card/index.test.tsx +1 -1
- package/src/components/card/newsroom-card/index.test.tsx +1 -1
- package/src/components/card/partner-card/index.tsx +3 -3
- package/src/components/card/person-card/index.tsx +1 -1
- package/src/components/card/primitives.tsx +16 -15
- package/src/components/card/resource-card/index.test.tsx +1 -1
- package/src/components/card/resource-card/index.tsx +3 -0
- package/src/components/card/types.ts +2 -2
- package/src/components/card/unified-card/index.spec.tsx +40 -0
- package/src/components/card/unified-card/index.tsx +5 -11
- package/src/components/marketo-form/contexts/FormMetadata.ts +2 -0
- package/src/components/marketo-form/form/index.tsx +4 -2
- package/src/components/marketo-form/partials/fields/checkbox-field/index.tsx +1 -1
- package/src/components/marketo-form/partials/fields/email-field/index.tsx +1 -1
- package/src/components/marketo-form/partials/fields/form-page-url-field/index.tsx +12 -1
- package/src/components/marketo-form/partials/fields/hidden-field/index.tsx +1 -0
- package/src/components/marketo-form/partials/fields/radio-buttons-field/index.tsx +1 -1
- package/src/components/marketo-form/partials/fields/select-field/index.tsx +1 -1
- package/src/components/marketo-form/partials/fields/telephone-field/index.tsx +1 -1
- package/src/components/marketo-form/partials/fields/text-field/index.tsx +1 -1
- package/src/components/marketo-form/partials/fields/textarea-field/index.tsx +1 -1
- package/src/components/marketo-form/types.ts +5 -11
- package/src/components/nav-panel/components/link-list/index.tsx +15 -9
- package/src/components/nav-panel/components/promo/index.tsx +12 -9
- package/src/components/nav-panel/product-panel/index.tsx +12 -7
- package/src/components/nav-panel/standard-panel/index.tsx +3 -0
- package/src/components/next-steps/index.tsx +3 -2
- package/src/components/product-badge/index.tsx +1 -1
- package/src/components/subnav/index.tsx +13 -3
- package/src/components/subnav/partials/CtaLinks/github-stars-link/style.module.css +8 -12
- package/src/components/subnav/partials/CtaLinks/index.tsx +9 -8
- package/src/components/subnav/partials/CtaLinks/style.module.css +4 -4
- package/src/components/subnav/partials/DropdownTrigger/index.tsx +2 -2
- package/src/components/subnav/partials/DropdownTrigger/style.module.css +7 -4
- package/src/components/subnav/partials/MenuItemsDefault/index.tsx +30 -8
- package/src/components/subnav/partials/MenuItemsDefault/style.module.css +37 -24
- package/src/components/subnav/partials/MenuItemsOverflow/index.tsx +20 -4
- package/src/components/subnav/partials/MenuItemsOverflow/style.module.css +22 -16
- package/src/components/subnav/partials/TitleLink/index.tsx +6 -4
- package/src/components/subnav/partials/TitleLink/style.module.css +1 -1
- package/src/components/subnav/partials/nav-item-text/style.module.css +2 -4
- package/src/components/subnav/style.module.css +4 -6
- package/src/lib/get-localized-link-props/index.test.ts +30 -0
- package/src/lib/get-localized-link-props/index.ts +46 -0
- package/src/lib/parse-url/index.test.ts +40 -1
- package/src/lib/parse-url/index.ts +83 -11
- package/src/lib/supported-locales/index.ts +1 -0
- package/src/lib/v/index.ts +4 -5
- package/src/components/consent-manager/README.md +0 -73
- package/src/components/consent-manager/components/banner/banner.module.css +0 -23
- package/src/components/consent-manager/components/banner/banner.test.tsx +0 -31
- package/src/components/consent-manager/components/banner/banner.tsx +0 -73
- package/src/components/consent-manager/components/dialog/dialog.module.css +0 -145
- package/src/components/consent-manager/components/dialog/dialog.test.tsx +0 -194
- package/src/components/consent-manager/components/dialog/dialog.tsx +0 -339
- package/src/components/consent-manager/img/icn_close.tsx +0 -19
- package/src/components/consent-manager/index.test.tsx +0 -334
- package/src/components/consent-manager/index.tsx +0 -186
- package/src/components/consent-manager/loader/README.md +0 -29
- package/src/components/consent-manager/loader/categories.ts +0 -22
- package/src/components/consent-manager/loader/index.tsx +0 -94
- package/src/components/consent-manager/loader/presets/enterprise.ts +0 -12
- package/src/components/consent-manager/loader/presets/oss.ts +0 -10
- package/src/components/consent-manager/loader/services.ts +0 -45
- package/src/components/consent-manager/scripts/custom.tsx +0 -59
- package/src/components/consent-manager/scripts/segment.tsx +0 -87
- package/src/components/consent-manager/style.module.css +0 -9
- package/src/components/consent-manager/types.ts +0 -55
- package/src/components/consent-manager/util/cookies.test.ts +0 -75
- package/src/components/consent-manager/util/cookies.ts +0 -70
- package/src/components/consent-manager/util/integrations.test.ts +0 -115
- package/src/components/consent-manager/util/integrations.ts +0 -110
- package/src/components/subnav/theme.module.css +0 -50
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import React from 'react'
|
|
7
|
-
import {
|
|
7
|
+
import { vercelSplit } from '../../../../lib/v'
|
|
8
8
|
import Link from 'next/link'
|
|
9
9
|
import type { Products } from '@hashicorp/platform-product-meta'
|
|
10
10
|
import CtaLinks, { type CtaLinkProps } from '../CtaLinks'
|
|
@@ -12,6 +12,8 @@ import DropdownTrigger from '../DropdownTrigger'
|
|
|
12
12
|
import * as NavigationMenu from '@radix-ui/react-navigation-menu'
|
|
13
13
|
import classNames from 'classnames'
|
|
14
14
|
import s from './style.module.css'
|
|
15
|
+
import FlightIcon from '@hashicorp/react-hds/src/components/flight-icon'
|
|
16
|
+
import { getLocalizedLinkProps } from '../../../../lib/get-localized-link-props'
|
|
15
17
|
|
|
16
18
|
interface MenuItemsOverflowProps {
|
|
17
19
|
menuItems: (
|
|
@@ -19,7 +21,7 @@ interface MenuItemsOverflowProps {
|
|
|
19
21
|
| {
|
|
20
22
|
text: string
|
|
21
23
|
url: string
|
|
22
|
-
submenu: { url: string; text: string }[]
|
|
24
|
+
submenu: { icon: string; url: string; text: string }[]
|
|
23
25
|
}
|
|
24
26
|
)[]
|
|
25
27
|
ctaLinks: CtaLinkProps
|
|
@@ -28,6 +30,7 @@ interface MenuItemsOverflowProps {
|
|
|
28
30
|
menuText: string
|
|
29
31
|
constrainWidth?: boolean
|
|
30
32
|
activatePanel: (panel: string) => void
|
|
33
|
+
locale?: string
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
interface MenuItemsOverflowState {
|
|
@@ -47,6 +50,7 @@ class MenuItemsOverflow extends React.Component<
|
|
|
47
50
|
menuText,
|
|
48
51
|
constrainWidth,
|
|
49
52
|
activatePanel,
|
|
53
|
+
locale,
|
|
50
54
|
} = this.props
|
|
51
55
|
|
|
52
56
|
const handleFocusOutside = () => {
|
|
@@ -89,6 +93,9 @@ class MenuItemsOverflow extends React.Component<
|
|
|
89
93
|
key={subStableIdx}
|
|
90
94
|
url={subItem.url}
|
|
91
95
|
text={subItem.text}
|
|
96
|
+
icon={subItem.icon}
|
|
97
|
+
locale={locale}
|
|
98
|
+
product={product}
|
|
92
99
|
/>
|
|
93
100
|
))}
|
|
94
101
|
<hr className={s.divider} />
|
|
@@ -101,6 +108,7 @@ class MenuItemsOverflow extends React.Component<
|
|
|
101
108
|
key={stableIdx}
|
|
102
109
|
url={url}
|
|
103
110
|
text={text}
|
|
111
|
+
product={product}
|
|
104
112
|
/>
|
|
105
113
|
)
|
|
106
114
|
}
|
|
@@ -120,15 +128,23 @@ class MenuItemsOverflow extends React.Component<
|
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
interface SubmenuItemProps {
|
|
131
|
+
icon?: string
|
|
123
132
|
url: string
|
|
124
133
|
text: string
|
|
134
|
+
locale?: string
|
|
135
|
+
product?: string
|
|
125
136
|
}
|
|
126
137
|
|
|
127
|
-
function SubmenuItem({ url, text }: SubmenuItemProps) {
|
|
138
|
+
function SubmenuItem({ icon, url, text, locale, product }: SubmenuItemProps) {
|
|
128
139
|
return (
|
|
129
140
|
<li>
|
|
130
141
|
<NavigationMenu.Link asChild>
|
|
131
|
-
<Link
|
|
142
|
+
<Link
|
|
143
|
+
className={s.submenuItem}
|
|
144
|
+
title={vercelSplit(text)}
|
|
145
|
+
{...getLocalizedLinkProps(url, locale, Boolean(product))}
|
|
146
|
+
>
|
|
147
|
+
{icon ? <FlightIcon name={icon} /> : null}
|
|
132
148
|
{text}
|
|
133
149
|
</Link>
|
|
134
150
|
</NavigationMenu.Link>
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/* Note: consumes from theme.module.css, as marked */
|
|
7
|
-
|
|
8
6
|
.root {
|
|
9
7
|
position: relative;
|
|
10
8
|
display: flex;
|
|
@@ -12,14 +10,14 @@
|
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
.dropdown {
|
|
15
|
-
background: var(--
|
|
16
|
-
border-radius:
|
|
13
|
+
background: var(--token-color-surface-primary);
|
|
14
|
+
border-radius: var(--hdsplus-spacing-03);
|
|
17
15
|
box-shadow: var(--token-elevation-high-box-shadow);
|
|
18
|
-
border: 1px solid var(--border-
|
|
16
|
+
border: 1px solid var(--token-color-border-primary);
|
|
19
17
|
margin-top: 8px;
|
|
20
18
|
max-height: calc(100vh - 300%);
|
|
21
19
|
overflow-y: auto;
|
|
22
|
-
padding: var(--hdsplus-spacing-04)
|
|
20
|
+
padding: var(--hdsplus-spacing-04);
|
|
23
21
|
position: absolute;
|
|
24
22
|
right: 0;
|
|
25
23
|
top: 100%;
|
|
@@ -52,27 +50,35 @@
|
|
|
52
50
|
|
|
53
51
|
.submenuTitle {
|
|
54
52
|
composes: g-type-label from global;
|
|
55
|
-
margin:
|
|
56
|
-
color: var(--
|
|
53
|
+
margin: var(--hdsplus-spacing-04) var(--hdsplus-spacing-03) 8px;
|
|
54
|
+
color: var(--token-color-foreground-faint);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
.divider {
|
|
60
|
-
margin:
|
|
58
|
+
margin: var(--hdsplus-spacing-04) var(--hdsplus-spacing-03);
|
|
61
59
|
border: 0;
|
|
62
60
|
padding: 0;
|
|
63
61
|
height: 1px;
|
|
64
|
-
background: var(--border-
|
|
62
|
+
background: var(--token-color-border-primary);
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
.submenuItem {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
composes: hds-typography-body-300 from global;
|
|
67
|
+
composes: hds-font-weight-semibold from global;
|
|
68
|
+
display: flex;
|
|
69
|
+
gap: var(--hdsplus-spacing-04);
|
|
70
|
+
padding: var(--hdsplus-spacing-02) var(--hdsplus-spacing-03);
|
|
71
|
+
color: var(--token-color-foreground-primary);
|
|
72
|
+
border-radius: var(--hdsplus-spacing-01);
|
|
73
|
+
align-items: center;
|
|
73
74
|
|
|
74
75
|
&:hover {
|
|
75
|
-
|
|
76
|
+
background-color: var(--token-color-surface-interactive-hover);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&:focus {
|
|
80
|
+
outline: 2px solid var(--token-color-focus-action-internal);
|
|
81
|
+
outline-style: auto;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
|
|
@@ -7,7 +7,7 @@ import { forwardRef } from 'react'
|
|
|
7
7
|
import { camelCase } from 'camel-case'
|
|
8
8
|
import Link from 'next/link'
|
|
9
9
|
import Image from 'next/image'
|
|
10
|
-
import {
|
|
10
|
+
import { vercelSplit } from '../../../../lib/v'
|
|
11
11
|
import classNames from 'classnames'
|
|
12
12
|
import * as CommunityProductLogosOnDark from './mktg-logos/all-community-product-logos_on-dark'
|
|
13
13
|
import * as CommunityProductLogosOnLight from './mktg-logos/all-community-product-logos_on-light'
|
|
@@ -22,6 +22,7 @@ import WaypointLogoAttrOnDark from '@hashicorp/web-mktg-logos/src/waypoint/hashi
|
|
|
22
22
|
import HCPTerraformLogoOnLight from '@hashicorp/web-mktg-logos/src/terraform/hcp-terraform/hcp-terraform_on-light.svg'
|
|
23
23
|
import HCPTerraformLogoOnDark from '@hashicorp/web-mktg-logos/src/terraform/hcp-terraform/hcp-terraform_on-dark.svg'
|
|
24
24
|
import s from './style.module.css'
|
|
25
|
+
import { getLocalizedLinkProps } from '../../../../lib/get-localized-link-props'
|
|
25
26
|
|
|
26
27
|
const logoDict = {
|
|
27
28
|
light: {
|
|
@@ -41,6 +42,7 @@ const logoDict = {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
interface TitleLinkProps {
|
|
45
|
+
locale?: string
|
|
44
46
|
text: string
|
|
45
47
|
url: string
|
|
46
48
|
product?: string
|
|
@@ -80,8 +82,8 @@ function getLogo(
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
const TitleLink = forwardRef<HTMLAnchorElement, TitleLinkProps>(
|
|
83
|
-
({ text, url, product, theme }, ref) => {
|
|
84
|
-
const parsedText =
|
|
85
|
+
({ text, url, product, theme, locale }, ref) => {
|
|
86
|
+
const parsedText = vercelSplit(text)
|
|
85
87
|
const Logo = getLogo(parsedText, theme)
|
|
86
88
|
|
|
87
89
|
return (
|
|
@@ -91,9 +93,9 @@ const TitleLink = forwardRef<HTMLAnchorElement, TitleLinkProps>(
|
|
|
91
93
|
s[`brand-${product}`],
|
|
92
94
|
s[camelCase(parsedText)]
|
|
93
95
|
)}
|
|
94
|
-
href={url}
|
|
95
96
|
title={parsedText}
|
|
96
97
|
ref={ref}
|
|
98
|
+
{...getLocalizedLinkProps(url, locale)}
|
|
97
99
|
>
|
|
98
100
|
{Logo ? (
|
|
99
101
|
<Image
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
display: inline-flex;
|
|
11
11
|
padding-block: var(--hdsplus-spacing-04);
|
|
12
12
|
font-weight: var(--font-weight-bold);
|
|
13
|
-
color: var(--
|
|
13
|
+
color: var(--token-color-foreground-primary); /* from theme.module.css */
|
|
14
14
|
font-size: 1.25rem;
|
|
15
15
|
line-height: 1.35rem;
|
|
16
16
|
|
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/* Note: consumes from theme.module.css, as marked */
|
|
7
|
-
|
|
8
6
|
.root {
|
|
9
|
-
color: var(--
|
|
7
|
+
color: var(--token-color-foreground-primary);
|
|
10
8
|
position: relative;
|
|
11
9
|
|
|
12
10
|
&.isActive {
|
|
13
|
-
color: var(--
|
|
11
|
+
color: var(--token-color-foreground-strong);
|
|
14
12
|
}
|
|
15
13
|
}
|
|
@@ -3,19 +3,17 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MPL-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/* Note: consumes from theme.module.css, as marked */
|
|
7
|
-
|
|
8
6
|
.root {
|
|
9
7
|
position: sticky;
|
|
10
8
|
top: -1px;
|
|
11
9
|
z-index: 900;
|
|
12
|
-
background: var(--
|
|
13
|
-
border-top: 1px solid var(--border-
|
|
10
|
+
background: var(--token-color-surface-primary);
|
|
11
|
+
border-top: 1px solid var(--token-color-border-faint);
|
|
14
12
|
border-bottom: 1px solid transparent;
|
|
15
13
|
transition: border-bottom-color 0.8s;
|
|
16
14
|
|
|
17
15
|
&.isSticky {
|
|
18
|
-
border-bottom-color: var(--border-
|
|
16
|
+
border-bottom-color: var(--token-color-border-faint);
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/*
|
|
@@ -46,7 +44,7 @@
|
|
|
46
44
|
|
|
47
45
|
.subnavInner {
|
|
48
46
|
display: grid;
|
|
49
|
-
grid-template-columns:
|
|
47
|
+
grid-template-columns: max-content min-content;
|
|
50
48
|
align-items: center;
|
|
51
49
|
justify-content: space-between;
|
|
52
50
|
min-height: 62px;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getLocalizedLinkProps } from '.'
|
|
2
|
+
|
|
3
|
+
describe('getLocalizedLinkProps', () => {
|
|
4
|
+
it('does not format localized homepage', () => {
|
|
5
|
+
const localizedLinkProps = getLocalizedLinkProps('/en', 'ja')
|
|
6
|
+
expect(localizedLinkProps.href).toBe('/en')
|
|
7
|
+
expect(localizedLinkProps.hrefLang).toBe('en')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('does not format localized path hrefs', () => {
|
|
11
|
+
const localizedLinkProps = getLocalizedLinkProps('/ja/solutions', 'de')
|
|
12
|
+
expect(localizedLinkProps.href).toBe('/ja/solutions')
|
|
13
|
+
expect(localizedLinkProps.hrefLang).toBe('ja')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('does format paths that start with a locale string', () => {
|
|
17
|
+
const localizedLinkProps = getLocalizedLinkProps(
|
|
18
|
+
'/deconstructing-cloud',
|
|
19
|
+
'en'
|
|
20
|
+
)
|
|
21
|
+
expect(localizedLinkProps.href).toBe('/en/deconstructing-cloud')
|
|
22
|
+
expect(localizedLinkProps.hrefLang).toBe('en')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('does not format external paths', () => {
|
|
26
|
+
const localizedLinkProps = getLocalizedLinkProps('https://google.com', 'ja')
|
|
27
|
+
expect(localizedLinkProps.href).toBe('https://google.com')
|
|
28
|
+
expect(localizedLinkProps.hrefLang).toBe(undefined)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseUrl } from '../parse-url'
|
|
2
|
+
import { allSupportedLocales } from '../supported-locales'
|
|
3
|
+
|
|
4
|
+
export const getLocalizedLinkProps = (
|
|
5
|
+
url: string,
|
|
6
|
+
locale?: string,
|
|
7
|
+
forceExternal?: boolean
|
|
8
|
+
): {
|
|
9
|
+
href: string
|
|
10
|
+
hrefLang: string | undefined
|
|
11
|
+
} => {
|
|
12
|
+
const parsedHref = parseUrl(url, forceExternal).href
|
|
13
|
+
|
|
14
|
+
// example: /en
|
|
15
|
+
const hrefIsLocalizedHomepage = allSupportedLocales.includes(
|
|
16
|
+
parsedHref.substring(1)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
// true example: /en/solutions
|
|
20
|
+
// false example: /entry-point
|
|
21
|
+
const hrefIsLocalized =
|
|
22
|
+
allSupportedLocales.includes(parsedHref.substring(1, 3)) &&
|
|
23
|
+
parsedHref[3] === '/'
|
|
24
|
+
|
|
25
|
+
// If the href is already localized:
|
|
26
|
+
// - do not format the href
|
|
27
|
+
// - use the locale from the href for the hrefLang
|
|
28
|
+
if (hrefIsLocalizedHomepage || hrefIsLocalized) {
|
|
29
|
+
return {
|
|
30
|
+
href: parsedHref,
|
|
31
|
+
hrefLang: parsedHref.substring(1, 3),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (parsedHref.startsWith('/') && locale) {
|
|
36
|
+
return {
|
|
37
|
+
href: `/${locale}${parsedHref}`,
|
|
38
|
+
hrefLang: locale,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
href: parsedHref,
|
|
44
|
+
hrefLang: undefined,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseUrl } from '.'
|
|
1
|
+
import { parseUrl, hasHashiCorpDestination } from '.'
|
|
2
2
|
|
|
3
3
|
describe('parseUrl', () => {
|
|
4
4
|
it('detects hashicorp.com URLs as internal', () => {
|
|
@@ -7,6 +7,12 @@ describe('parseUrl', () => {
|
|
|
7
7
|
expect(url.linkType).toBe('inbound')
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
+
it('detects www.hashicorp.com URLs as internal', () => {
|
|
11
|
+
const url = parseUrl('https://hashicorp.com/foo')
|
|
12
|
+
expect(url.href).toBe('/foo')
|
|
13
|
+
expect(url.linkType).toBe('inbound')
|
|
14
|
+
})
|
|
15
|
+
|
|
10
16
|
it('detects URLs not containing hashicorp.com as external', () => {
|
|
11
17
|
const externalUrl = 'https://google.com/example'
|
|
12
18
|
const url = parseUrl(externalUrl)
|
|
@@ -27,4 +33,37 @@ describe('parseUrl', () => {
|
|
|
27
33
|
)
|
|
28
34
|
expect(url.href).toBe('/resources?type=case-study&products=terraform')
|
|
29
35
|
})
|
|
36
|
+
|
|
37
|
+
it('leaves URL hash intact', () => {
|
|
38
|
+
const url = parseUrl('https://hashicorp.com/about#leadership')
|
|
39
|
+
expect(url.href).toBe('/about#leadership')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('leaves HashiCorp subdomain URLs intact', () => {
|
|
43
|
+
const url = parseUrl('https://developer.hashicorp.com/terraform')
|
|
44
|
+
expect(url.href).toBe('https://developer.hashicorp.com/terraform')
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
describe('hasHashiCorpDestination', () => {
|
|
49
|
+
it('returns true for supported hashicorp domains', () => {
|
|
50
|
+
const isHashiCorpDestination = hasHashiCorpDestination(
|
|
51
|
+
'https://portal.cloud.hashicorp.com/foo'
|
|
52
|
+
)
|
|
53
|
+
expect(isHashiCorpDestination).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
it('returns false for external domains', () => {
|
|
56
|
+
const isHashiCorpDestination = hasHashiCorpDestination(
|
|
57
|
+
'https://foo.com/bar'
|
|
58
|
+
)
|
|
59
|
+
expect(isHashiCorpDestination).toBe(false)
|
|
60
|
+
})
|
|
61
|
+
it('returns true for relative links', () => {
|
|
62
|
+
const isHashiCorpDestination = hasHashiCorpDestination('/bar')
|
|
63
|
+
expect(isHashiCorpDestination).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
it('returns true for hashes', () => {
|
|
66
|
+
const isHashiCorpDestination = hasHashiCorpDestination('#someHash')
|
|
67
|
+
expect(isHashiCorpDestination).toBe(true)
|
|
68
|
+
})
|
|
30
69
|
})
|
|
@@ -1,32 +1,104 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export const hashicorpDestinations: string[] = [
|
|
2
|
+
'app.terraform.io',
|
|
3
|
+
'boundaryproject.io',
|
|
4
|
+
'cloud.hashicorp.com',
|
|
5
|
+
'consul.io',
|
|
6
|
+
'developer.hashicorp.com',
|
|
7
|
+
'hashicorp.com',
|
|
8
|
+
'nomadproject.io',
|
|
9
|
+
'packer.io',
|
|
10
|
+
'portal.cloud.hashicorp.com',
|
|
11
|
+
'registry.terraform.io',
|
|
12
|
+
'terraform.io',
|
|
13
|
+
'vagrantup.com',
|
|
14
|
+
'vaultproject.io',
|
|
15
|
+
'waypointproject.io',
|
|
16
|
+
] as const
|
|
17
|
+
|
|
18
|
+
const containsHashiCorpDestination = (str: string): boolean =>
|
|
19
|
+
hashicorpDestinations.some(function (destination) {
|
|
20
|
+
return str.indexOf(destination) >= 0
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* This function determines if a `url` is a HashiCorp link (relative URLs, hashes,
|
|
25
|
+
* or a url with a HashiCorp domain) or a non-HashiCorp link.
|
|
26
|
+
*
|
|
27
|
+
* @param {string | undefined} url - The URL to be parsed. It may be a relative URL, an anchor, or a full external/internal URL.
|
|
28
|
+
*
|
|
29
|
+
* @returns {{ linkType: 'inbound' | 'outbound', href: string }}
|
|
30
|
+
* An object with two properties:
|
|
31
|
+
* - `linkType`: Indicates whether the URL is 'inbound' or 'outbound'. Can be used to conditionally
|
|
32
|
+
* render the value of the target attribute.
|
|
33
|
+
* - `href`: The parsed href (may include pathname, search, and hash for internal URLs).
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} Throws an error if the URL is undefined or invalid.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
// @TODO: delete forceExternal when io sites are shutdown
|
|
39
|
+
|
|
40
|
+
export function parseUrl(
|
|
41
|
+
url: string | undefined,
|
|
42
|
+
forceExternal?: boolean
|
|
43
|
+
): {
|
|
44
|
+
linkType: 'inbound' | 'outbound' | ''
|
|
3
45
|
href: string
|
|
4
46
|
} {
|
|
5
47
|
if (!url) {
|
|
6
|
-
|
|
48
|
+
console.log('No url to parse, returning empty string')
|
|
49
|
+
return { linkType: '', href: '' }
|
|
7
50
|
}
|
|
8
51
|
|
|
9
52
|
if (isRelative(url) || isAnchor(url)) {
|
|
10
53
|
return { linkType: 'inbound', href: url }
|
|
11
54
|
}
|
|
12
55
|
|
|
13
|
-
if (isInternal(url)) {
|
|
56
|
+
if (!forceExternal && isInternal(url)) {
|
|
14
57
|
try {
|
|
15
|
-
const { pathname, search } = new URL(url)
|
|
16
|
-
const href = pathname + search
|
|
58
|
+
const { pathname, search, hash } = new URL(url)
|
|
59
|
+
const href = pathname + search + hash
|
|
17
60
|
return { linkType: 'inbound', href }
|
|
18
61
|
} catch (error) {
|
|
19
|
-
|
|
62
|
+
console.log(`Invalid href: ${url}`)
|
|
63
|
+
return { linkType: '', href: '' }
|
|
20
64
|
}
|
|
21
65
|
}
|
|
22
66
|
|
|
23
67
|
return { linkType: 'outbound', href: url }
|
|
24
68
|
}
|
|
25
69
|
|
|
26
|
-
const isRelative = (url) => url.startsWith('/')
|
|
27
|
-
const isAnchor = (url) => url.startsWith('#')
|
|
70
|
+
const isRelative = (url: string) => url.startsWith('/')
|
|
71
|
+
const isAnchor = (url: string) => url.startsWith('#')
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Determines whether the provided url uses hashicorp.com or www.hashicorp.com as the hostname.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} url - The URL to check.
|
|
77
|
+
* @returns {boolean} - Returns true if the link uses a HashiCorp domain, otherwise false.
|
|
78
|
+
*/
|
|
28
79
|
|
|
29
|
-
export const isInternal = (url) => {
|
|
80
|
+
export const isInternal = (url: string): boolean => {
|
|
30
81
|
const hostname = new URL(url).hostname
|
|
31
|
-
return hostname === 'hashicorp.com'
|
|
82
|
+
return hostname === 'hashicorp.com' || hostname === 'www.hashicorp.com'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Determines whether the provided url uses a HashiCorp hostname. This is used in several
|
|
87
|
+
* components to open a new tab for non-HashiCorp links.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} url - The URL to check.
|
|
90
|
+
* @returns {boolean} - Returns true if the link uses a HashiCorp domain, otherwise false.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
export const hasHashiCorpDestination = (url: string): boolean => {
|
|
94
|
+
// Fast return in case a relative URL or anchor is passed in
|
|
95
|
+
if (isRelative(url) || isAnchor(url)) return true
|
|
96
|
+
try {
|
|
97
|
+
const hostname = new URL(url).hostname
|
|
98
|
+
const isHashiCorpDestination = containsHashiCorpDestination(hostname)
|
|
99
|
+
return isHashiCorpDestination
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error('Error: `url` is not a valid URL', e)
|
|
102
|
+
return false
|
|
103
|
+
}
|
|
32
104
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const allSupportedLocales = ['en', 'de', 'es', 'fr', 'ja', 'ko', 'pt']
|
package/src/lib/v/index.ts
CHANGED
|
@@ -3,9 +3,8 @@ import { vercelStegaSplit } from '@vercel/stega'
|
|
|
3
3
|
/**
|
|
4
4
|
* Takes in a Vercel Visual Editing string and returns the string without
|
|
5
5
|
* hidden data.
|
|
6
|
+
*
|
|
6
7
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
):
|
|
10
|
-
return vercelStegaSplit(s).cleaned as VercelVEString
|
|
11
|
-
}
|
|
8
|
+
export const vercelSplit = <VercelString>(
|
|
9
|
+
original: VercelString
|
|
10
|
+
): VercelString => vercelStegaSplit(original as string).cleaned as VercelString
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# Consent Manager
|
|
2
|
-
|
|
3
|
-
A GDPR-compliant consent manager.
|
|
4
|
-
|
|
5
|
-
### Props
|
|
6
|
-
|
|
7
|
-
- `version` (integer) - version number, bump up to override previous consent preferences
|
|
8
|
-
- `container` (string) - id of container where the consent manager should live
|
|
9
|
-
- `companyName` (string) - your company name to be inserted in various copy
|
|
10
|
-
- `privacyPolicyLink` (string) - link to your company's privacy policy
|
|
11
|
-
- `segmentWriteKey` (string) - your production segment write key
|
|
12
|
-
- `segmentServices` (array of objects) - use this to override the category or description of a service provided by Segment
|
|
13
|
-
- `name` - name of the Segment integration, must match the integration you are overriding
|
|
14
|
-
- `category` _[optional]_ - new category name
|
|
15
|
-
- `description` _[optional]_ - new description
|
|
16
|
-
- `categories` (array) - State of toggle
|
|
17
|
-
- `name` - name of category
|
|
18
|
-
- `description` - description for the category
|
|
19
|
-
- `additionalServices` (array of objects) - additional integrations outside of Segment that you wish to include in the consent manager
|
|
20
|
-
- `name` - name of service
|
|
21
|
-
- `description` - description of service
|
|
22
|
-
- `category` - category of service
|
|
23
|
-
- `body` _[optional]_ - javascript body associated with service _If present, overrides `url` below_
|
|
24
|
-
- `url` _[optional]_ - url of js file associated with service
|
|
25
|
-
- `async` (bool) _[optional]_ - add `async` property to script element
|
|
26
|
-
- `addToBody` (bool) _[optional]_ - inject script before closing `<body>` tag
|
|
27
|
-
- `dataAttrs` (arr) _[optional]_ - array of `data-` attributes to add to script tag
|
|
28
|
-
- `name` (str) - name of data attribute (`data-name`)
|
|
29
|
-
- `value` (str) - value of `data` attribute to set
|
|
30
|
-
- `showDialog` (bool) - whether or not the dialog `open` attribute is true
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## `SegmentPreloadScript`
|
|
34
|
-
|
|
35
|
-
In `v9.0.0`, ConsentManager now exports a `SegmentPreloadScript` component. Why? ConsentManager uses a very similar Segment script to the current preloading script that we use in our `_document.tsx/js` files.
|
|
36
|
-
|
|
37
|
-
Now that we're updating both with a custom Segment AJS URL and CDN hostname, it makes sense for the two to be co-located.
|
|
38
|
-
|
|
39
|
-
Expect the new change to look like the following:
|
|
40
|
-
|
|
41
|
-
```diff
|
|
42
|
-
// pages/_document.tsx
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
|
46
|
-
import HashiHead from '@hashicorp/react-head'
|
|
47
|
-
+ import { SegmentPreloadScript } from '@web/react-components/src/components/consent-manager/scripts/segment'
|
|
48
|
-
// other imports
|
|
49
|
-
|
|
50
|
-
export default class MyDocument extends Document {
|
|
51
|
-
static async getInitialProps(ctx) {
|
|
52
|
-
const initialProps = await Document.getInitialProps(ctx)
|
|
53
|
-
return { ...initialProps }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
render() {
|
|
57
|
-
return (
|
|
58
|
-
<Html lang="en">
|
|
59
|
-
<Head>
|
|
60
|
-
<HashiHead />
|
|
61
|
-
</Head>
|
|
62
|
-
<body>
|
|
63
|
-
- <script
|
|
64
|
-
- dangerouslySetInnerHTML={{
|
|
65
|
-
- __html: `!function(){var analytics=window... ... ...`
|
|
66
|
-
- }}
|
|
67
|
-
- />
|
|
68
|
-
+ <SegmentPreloadScript />
|
|
69
|
-
|
|
70
|
-
// etc...
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
No additional updates are necessary!
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
.root {
|
|
2
|
-
background-color: var(--token-color-surface-strong);
|
|
3
|
-
width: 100%;
|
|
4
|
-
padding: 10px 15px;
|
|
5
|
-
position: fixed;
|
|
6
|
-
bottom: 0;
|
|
7
|
-
left: 0;
|
|
8
|
-
z-index: 10;
|
|
9
|
-
font-size: 0.9rem;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.innerContainer {
|
|
13
|
-
composes: g-grid-container from global;
|
|
14
|
-
display: flex;
|
|
15
|
-
justify-content: space-between;
|
|
16
|
-
align-items: center;
|
|
17
|
-
gap: var(--hdsplus-spacing-01);
|
|
18
|
-
flex-direction: column;
|
|
19
|
-
|
|
20
|
-
@media (min-width: 1350px) {
|
|
21
|
-
flex-direction: row;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { render, screen, fireEvent } from '@testing-library/react'
|
|
2
|
-
import ConsentBanner from './banner'
|
|
3
|
-
|
|
4
|
-
test('should display the correct privacy policy url', () => {
|
|
5
|
-
const testValue = 'test'
|
|
6
|
-
render(<ConsentBanner privacyPolicyLink={testValue} />)
|
|
7
|
-
expect(screen.getByTestId('privacy-policy')).toHaveAttribute(
|
|
8
|
-
'href',
|
|
9
|
-
testValue
|
|
10
|
-
)
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('should display the correct cookie policy url', () => {
|
|
14
|
-
const testValue = 'test'
|
|
15
|
-
render(<ConsentBanner cookiePolicyLink={testValue} />)
|
|
16
|
-
expect(screen.getByTestId('cookie-policy')).toHaveAttribute('href', testValue)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('should run the onManagePreferences function when the correct button is clicked', () => {
|
|
20
|
-
const mock = vi.fn()
|
|
21
|
-
render(<ConsentBanner onManagePreferences={mock} />)
|
|
22
|
-
fireEvent.click(screen.getByTestId('manage-preferences'))
|
|
23
|
-
expect(mock).toHaveBeenCalled()
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test('should run the onAccept function when the correct button is clicked', () => {
|
|
27
|
-
const mock = vi.fn()
|
|
28
|
-
render(<ConsentBanner onAccept={mock} />)
|
|
29
|
-
fireEvent.click(screen.getByTestId('accept'))
|
|
30
|
-
expect(mock).toHaveBeenCalled()
|
|
31
|
-
})
|