-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathHeader.tsx
More file actions
146 lines (142 loc) · 5.42 KB
/
Header.tsx
File metadata and controls
146 lines (142 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
142
143
144
145
146
import '../../eui-icons-cache'
import { useHtmxContainer } from '../shared/htmx/useHtmxContainer'
import { DeploymentInfo, headerButtonCss } from './DeploymentInfo'
import {
EuiHeader,
EuiHeaderLogo,
EuiIcon,
EuiProvider,
useEuiTheme,
} from '@elastic/eui'
import { css } from '@emotion/react'
import r2wc from '@r2wc/react-to-web-component'
import { useRef } from 'react'
interface Props {
title: string
logoHref: string
githubRepository: string
githubLink: string
gitBranch: string
gitCommit: string
/** Full ref from GitHub Actions (e.g. refs/pull/123/merge). */
githubRef?: string
/** When true, deployment info is hidden (not relevant in air-gapped environments). */
airGapped?: boolean
}
export const Header = ({
title,
logoHref,
githubRepository,
githubLink,
gitBranch,
gitCommit,
githubRef,
airGapped = false,
}: Props) => {
const { euiTheme } = useEuiTheme()
const containerRef = useRef<HTMLSpanElement>(null)
useHtmxContainer(containerRef)
return (
<EuiProvider
colorMode="light"
globalStyles={false}
utilityClasses={false}
>
<EuiHeader
css={css`
background: linear-gradient(
to bottom,
#ffffff 0%,
#f5f7fa 100%
);
border-bottom: 1px solid ${euiTheme.colors.lightShade};
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
`}
sections={[
{
items: [
<span ref={containerRef}>
<EuiHeaderLogo
href={logoHref}
css={css`
padding-block: 7px;
height: auto;
line-height: normal;
border-radius: ${euiTheme.border.radius
.small};
&:hover {
background: rgba(
0,
0,
0,
0.06
) !important;
}
& > span {
color: ${euiTheme.colors.textInk};
}
`}
>
{title}
</EuiHeaderLogo>
</span>,
],
},
...(!airGapped
? [
{
items: [
...(githubLink
? [
<a
href={githubLink}
target="_blank"
rel="noopener noreferrer"
css={css`
${headerButtonCss(
euiTheme
)};
margin-inline: ${euiTheme
.size.s};
`}
>
<EuiIcon
type="logoGithub"
color="inherit"
/>
GitHub
</a>,
]
: []),
<DeploymentInfo
gitBranch={gitBranch}
gitCommit={gitCommit}
githubRepository={
'elastic/' + githubRepository
}
githubRef={githubRef}
/>,
],
},
]
: []),
]}
/>
</EuiProvider>
)
}
customElements.define(
'elastic-docs-header',
r2wc(Header, {
props: {
title: 'string',
logoHref: 'string',
githubRepository: 'string',
githubLink: 'string',
gitBranch: 'string',
gitCommit: 'string',
githubRef: 'string',
airGapped: 'boolean',
},
})
)