Skip to content

Commit 2b7280d

Browse files
authored
feat: get product attribute to set demo link
1 parent e297fd4 commit 2b7280d

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

public/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
<meta name="theme-color" content="#000000" />
77
<meta name="description" content="Traefik Header Web Component to use in any framework" />
88
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
9+
<!--
10+
point this script src to the local build
11+
-->
12+
<script
13+
type="text/javascript"
14+
src="/build/static/js/"
15+
></script>
916
<!--
1017
manifest.json provides metadata used when your web app is installed on a
1118
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import FontGlobalStyle from 'components/nav/FontGlobalStyle'
88

99
const FaencyProvider = Provider as React.FC<ComponentProps<typeof Provider> & { children: ReactNode }>
1010

11-
function App() {
11+
function App({ product }: { product?: string }) {
1212
return (
1313
<SWRConfig
1414
value={{
@@ -19,7 +19,7 @@ function App() {
1919
<FaencyProvider>
2020
<DrawerGlobalStyle />
2121
<FontGlobalStyle />
22-
<Header />
22+
<Header product={product} />
2323
</FaencyProvider>
2424
</SWRConfig>
2525
)

src/components/nav/Header.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react'
1+
import React, { useState, useEffect, useMemo } from 'react'
22
import { Nav as FaencyNav, NavContainer as FaencyNavContainer, theme, Flex, Box } from '@containous/faency'
33
import styled, { createGlobalStyle } from 'styled-components'
44
import Logo from 'components/Logo'
@@ -113,10 +113,16 @@ const Hamburger = styled.div`
113113
}
114114
`
115115

116-
const Header = () => {
116+
const Header = ({ product }: { product?: string }) => {
117117
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
118118
const [isHeaderScrolled, setHeaderScrolled] = useState(false)
119119

120+
const demoLink = useMemo(() => {
121+
if (product === 'hub') return 'https://info.traefik.io/traefik-hub-signup'
122+
123+
return 'https://info.traefik.io/en/request-demo-traefik-enterprise'
124+
}, [product])
125+
120126
useEffect(() => {
121127
const adjustHeaderHeight = function () {
122128
const breakpoint = 40
@@ -179,7 +185,7 @@ const Header = () => {
179185
</svg>
180186
</NavIconButton>
181187
<NavButton href="https://info.traefik.io/speak-with-an-expert">Speak with an expert</NavButton>
182-
<NavButtonPrimary href="https://info.traefik.io/en/request-demo-traefik-enterprise">
188+
<NavButtonPrimary href={demoLink}>
183189
Get a Demo
184190
</NavButtonPrimary>
185191
</Flex>

src/utils/register-custom-element.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ type Args<P extends BaseProps> = {
1515
* Register a custom element that wraps a React component.
1616
*
1717
* @param name - the name of the custom element
18-
* @param attributes - the names of the custom element's attributes
1918
* @param component - the React component
2019
*/
2120
export default function registerCustomElement<P extends BaseProps>({
2221
name,
2322
component: Component,
24-
attributes = [],
2523
}: Args<P>) {
2624
const webComponentClass = class extends HTMLElement {
2725
private readonly styleHost: HTMLElement
@@ -37,13 +35,7 @@ export default function registerCustomElement<P extends BaseProps>({
3735

3836
connectedCallback() {
3937
if (this.isConnected) {
40-
const attrs = attributes?.reduce(
41-
(acc, key) =>
42-
Object.assign(acc, {
43-
[key]: this.getAttribute(key) ?? undefined,
44-
}),
45-
{} as P,
46-
)
38+
const attrs = Object.assign({}, ...Array.from(this.attributes, ({ name, value }) => ({ [name]: value })))
4739

4840
this.shadowRoot?.appendChild(this.styleHost)
4941
this.shadowRoot?.appendChild(this.mountPoint)

0 commit comments

Comments
 (0)