@elastic/eui-docusaurus-theme 2.8.1 → 2.9.0-snapshot.1794886152078
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/lib/.tsbuildinfo-client +1 -1
- package/lib/components/doc_title/context.d.ts +8 -0
- package/lib/components/doc_title/context.js +27 -0
- package/lib/components/doc_title/index.d.ts +2 -0
- package/lib/components/doc_title/index.js +37 -0
- package/lib/theme/DocItem/Content/index.js +7 -2
- package/lib/theme/Logo/index.js +69 -26
- package/lib/theme/MDXComponents/Heading.js +2 -1
- package/lib/utils/storybook.d.ts +1 -0
- package/lib/utils/storybook.js +8 -0
- package/package.json +5 -4
- package/src/components/doc_title/context.ts +38 -0
- package/src/components/doc_title/index.tsx +108 -0
- package/src/theme/DocItem/Content/index.tsx +23 -12
- package/src/theme/Logo/index.tsx +132 -31
- package/src/theme/MDXComponents/Heading.tsx +9 -3
- package/src/utils/storybook.ts +12 -0
package/src/theme/Logo/index.tsx
CHANGED
|
@@ -6,18 +6,30 @@
|
|
|
6
6
|
* Side Public License, v 1.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
useContext,
|
|
11
|
+
useState,
|
|
12
|
+
type CSSProperties,
|
|
13
|
+
type JSX,
|
|
14
|
+
type MouseEvent,
|
|
15
|
+
type ReactNode,
|
|
16
|
+
} from 'react';
|
|
10
17
|
import { css } from '@emotion/react';
|
|
18
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
11
19
|
import Link from '@docusaurus/Link';
|
|
12
20
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
13
21
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
14
22
|
import { useThemeConfig, type NavbarLogo } from '@docusaurus/theme-common';
|
|
15
23
|
import type { Props } from '@theme-original/Logo';
|
|
16
24
|
import {
|
|
25
|
+
EuiContextMenuItem,
|
|
26
|
+
EuiContextMenuPanel,
|
|
17
27
|
EuiImage,
|
|
28
|
+
EuiPopover,
|
|
18
29
|
euiCanAnimate,
|
|
19
30
|
euiTextTruncate,
|
|
20
31
|
useEuiMemoizedStyles,
|
|
32
|
+
useGeneratedHtmlId,
|
|
21
33
|
UseEuiTheme,
|
|
22
34
|
} from '@elastic/eui';
|
|
23
35
|
|
|
@@ -25,6 +37,10 @@ import { AppThemeContext } from '../../components/theme_context';
|
|
|
25
37
|
|
|
26
38
|
const EUI_LOGO = 'eui_logo.svg';
|
|
27
39
|
const LOGO_DISTANCE = '5px';
|
|
40
|
+
const elasticLinks = [
|
|
41
|
+
{ label: 'Elastic', href: 'https://www.elastic.co' },
|
|
42
|
+
{ label: 'Brand Guide', href: 'https://brand.elastic.co' },
|
|
43
|
+
];
|
|
28
44
|
|
|
29
45
|
const getStyles = ({ euiTheme }: UseEuiTheme) => ({
|
|
30
46
|
wrapper: css`
|
|
@@ -44,6 +60,26 @@ const getStyles = ({ euiTheme }: UseEuiTheme) => ({
|
|
|
44
60
|
@media (min-width: 997px) {
|
|
45
61
|
margin-inline-end: ${euiTheme.size.l};
|
|
46
62
|
}
|
|
63
|
+
|
|
64
|
+
${euiCanAnimate} {
|
|
65
|
+
&:hover {
|
|
66
|
+
.euiNavbarLogo__pink {
|
|
67
|
+
transform: translate(-${LOGO_DISTANCE}, -${LOGO_DISTANCE});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.euiNavbarLogo__yellow {
|
|
71
|
+
transform: translate(${LOGO_DISTANCE}, ${LOGO_DISTANCE});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.euiNavbarLogo__teal {
|
|
75
|
+
transform: translate(${LOGO_DISTANCE}, -${LOGO_DISTANCE});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.euiNavbarLogo__blue {
|
|
79
|
+
transform: translate(-${LOGO_DISTANCE}, ${LOGO_DISTANCE});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
47
83
|
}
|
|
48
84
|
|
|
49
85
|
.navbar__logo {
|
|
@@ -51,10 +87,23 @@ const getStyles = ({ euiTheme }: UseEuiTheme) => ({
|
|
|
51
87
|
height: auto;
|
|
52
88
|
}
|
|
53
89
|
|
|
90
|
+
.euiPopover {
|
|
91
|
+
display: flex;
|
|
92
|
+
min-inline-size: 0;
|
|
93
|
+
max-inline-size: 100%;
|
|
94
|
+
}
|
|
95
|
+
|
|
54
96
|
.navbar__title {
|
|
55
97
|
${euiTextTruncate()}
|
|
56
98
|
}
|
|
57
99
|
`,
|
|
100
|
+
lockup: css`
|
|
101
|
+
display: inline-flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
min-inline-size: 0;
|
|
104
|
+
max-inline-size: 100%;
|
|
105
|
+
user-select: none;
|
|
106
|
+
`,
|
|
58
107
|
imageWrapper: css`
|
|
59
108
|
overflow: visible;
|
|
60
109
|
margin-inline-end: ${euiTheme.size.m};
|
|
@@ -85,30 +134,10 @@ const getStyles = ({ euiTheme }: UseEuiTheme) => ({
|
|
|
85
134
|
transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
|
|
86
135
|
}
|
|
87
136
|
}
|
|
88
|
-
|
|
89
|
-
${euiCanAnimate} {
|
|
90
|
-
&:hover {
|
|
91
|
-
.euiNavbarLogo__pink {
|
|
92
|
-
transform: translate(-${LOGO_DISTANCE}, -${LOGO_DISTANCE});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.euiNavbarLogo__yellow {
|
|
96
|
-
transform: translate(${LOGO_DISTANCE}, ${LOGO_DISTANCE});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.euiNavbarLogo__teal {
|
|
100
|
-
transform: translate(${LOGO_DISTANCE}, -${LOGO_DISTANCE});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
.euiNavbarLogo__blue {
|
|
104
|
-
transform: translate(-${LOGO_DISTANCE}, ${LOGO_DISTANCE});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
137
|
`,
|
|
109
138
|
});
|
|
110
139
|
|
|
111
|
-
function
|
|
140
|
+
function NavbarLogoSvg({
|
|
112
141
|
alt,
|
|
113
142
|
className,
|
|
114
143
|
style,
|
|
@@ -165,6 +194,72 @@ function EuiNavbarLogo({
|
|
|
165
194
|
);
|
|
166
195
|
}
|
|
167
196
|
|
|
197
|
+
function EuiNavbarLogoMenu({ children }: { children: ReactNode }) {
|
|
198
|
+
const styles = useEuiMemoizedStyles(getStyles);
|
|
199
|
+
|
|
200
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
201
|
+
const [offset, setOffset] = useState<number>();
|
|
202
|
+
|
|
203
|
+
const popoverId = useGeneratedHtmlId({ prefix: 'elasticLinks' });
|
|
204
|
+
|
|
205
|
+
const closePopover = () => setIsOpen(false);
|
|
206
|
+
|
|
207
|
+
const openMenu = (event: MouseEvent<HTMLElement>) => {
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
|
|
210
|
+
const anchorBottom = event.currentTarget.getBoundingClientRect().bottom;
|
|
211
|
+
const header = event.currentTarget.closest('.navbar');
|
|
212
|
+
const headerBottom = header?.getBoundingClientRect().bottom ?? anchorBottom;
|
|
213
|
+
|
|
214
|
+
setOffset(headerBottom - anchorBottom);
|
|
215
|
+
setIsOpen(true);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<EuiPopover
|
|
220
|
+
id={popoverId}
|
|
221
|
+
button={
|
|
222
|
+
<span css={styles.lockup} onContextMenu={openMenu}>
|
|
223
|
+
{children}
|
|
224
|
+
</span>
|
|
225
|
+
}
|
|
226
|
+
isOpen={isOpen}
|
|
227
|
+
closePopover={closePopover}
|
|
228
|
+
panelPaddingSize="none"
|
|
229
|
+
offset={offset}
|
|
230
|
+
aria-label="Elastic links"
|
|
231
|
+
>
|
|
232
|
+
<EuiContextMenuPanel
|
|
233
|
+
initialFocusedItemIndex={0}
|
|
234
|
+
items={elasticLinks.map(({ label, href }) => (
|
|
235
|
+
<EuiContextMenuItem
|
|
236
|
+
key={href}
|
|
237
|
+
icon="logoElastic"
|
|
238
|
+
href={href}
|
|
239
|
+
target="_blank"
|
|
240
|
+
onClick={(event) => {
|
|
241
|
+
event.stopPropagation();
|
|
242
|
+
closePopover();
|
|
243
|
+
}}
|
|
244
|
+
>
|
|
245
|
+
{label}
|
|
246
|
+
</EuiContextMenuItem>
|
|
247
|
+
))}
|
|
248
|
+
/>
|
|
249
|
+
</EuiPopover>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function EuiNavbarLogo({ children }: { children: ReactNode }) {
|
|
254
|
+
const styles = useEuiMemoizedStyles(getStyles);
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<BrowserOnly fallback={<span css={styles.lockup}>{children}</span>}>
|
|
258
|
+
{() => <EuiNavbarLogoMenu>{children}</EuiNavbarLogoMenu>}
|
|
259
|
+
</BrowserOnly>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
168
263
|
function LogoThemedImage({
|
|
169
264
|
logo,
|
|
170
265
|
alt,
|
|
@@ -185,7 +280,7 @@ function LogoThemedImage({
|
|
|
185
280
|
: useBaseUrl(logo.src);
|
|
186
281
|
|
|
187
282
|
const themedImage = isEuiLogo ? (
|
|
188
|
-
<
|
|
283
|
+
<NavbarLogoSvg alt={alt} className={logo.className} style={logo.style} />
|
|
189
284
|
) : (
|
|
190
285
|
<EuiImage
|
|
191
286
|
src={src}
|
|
@@ -230,6 +325,19 @@ export default function Logo(props: Props): JSX.Element {
|
|
|
230
325
|
// Use logo alt text if provided (including empty string),
|
|
231
326
|
// and provide a sensible fallback otherwise.
|
|
232
327
|
const alt = logo?.alt ?? fallbackAlt;
|
|
328
|
+
const isEuiLogo = logo?.src.includes(EUI_LOGO);
|
|
329
|
+
const lockup = (
|
|
330
|
+
<>
|
|
331
|
+
{logo && (
|
|
332
|
+
<LogoThemedImage
|
|
333
|
+
logo={logo}
|
|
334
|
+
alt={alt}
|
|
335
|
+
imageClassName={imageClassName}
|
|
336
|
+
/>
|
|
337
|
+
)}
|
|
338
|
+
{navbarTitle != null && <b className={titleClassName}>{navbarTitle}</b>}
|
|
339
|
+
</>
|
|
340
|
+
);
|
|
233
341
|
|
|
234
342
|
return (
|
|
235
343
|
<div css={styles.wrapper}>
|
|
@@ -238,14 +346,7 @@ export default function Logo(props: Props): JSX.Element {
|
|
|
238
346
|
{...propsRest}
|
|
239
347
|
{...(logo?.target && { target: logo.target })}
|
|
240
348
|
>
|
|
241
|
-
{
|
|
242
|
-
<LogoThemedImage
|
|
243
|
-
logo={logo}
|
|
244
|
-
alt={alt}
|
|
245
|
-
imageClassName={imageClassName}
|
|
246
|
-
/>
|
|
247
|
-
)}
|
|
248
|
-
{navbarTitle != null && <b className={titleClassName}>{navbarTitle}</b>}
|
|
349
|
+
{isEuiLogo ? <EuiNavbarLogo>{lockup}</EuiNavbarLogo> : lockup}
|
|
249
350
|
</Link>
|
|
250
351
|
</div>
|
|
251
352
|
);
|
|
@@ -8,9 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
import { JSX } from 'react';
|
|
10
10
|
import Heading, { Props as HeadingProps } from '@theme/Heading';
|
|
11
|
+
import { DocTitle } from '../../components/doc_title';
|
|
11
12
|
|
|
12
|
-
const MDXHeading = (props: HeadingProps): JSX.Element =>
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const MDXHeading = (props: HeadingProps): JSX.Element =>
|
|
14
|
+
props.as === 'h1' ? (
|
|
15
|
+
<DocTitle>
|
|
16
|
+
<Heading {...props} />
|
|
17
|
+
</DocTitle>
|
|
18
|
+
) : (
|
|
19
|
+
<Heading {...props} />
|
|
20
|
+
);
|
|
15
21
|
|
|
16
22
|
export default MDXHeading;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
5
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
6
|
+
* Side Public License, v 1.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const getStorybookUrl = (baseUrl: string, id: string) =>
|
|
10
|
+
`${baseUrl.replace(/\/$/, '')}/index.html?path=/story/${encodeURIComponent(
|
|
11
|
+
id
|
|
12
|
+
)}`;
|