@elastic/eui-docusaurus-theme 2.8.1-snapshot.1794825855066 → 2.9.0

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.
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
2
  /*
3
3
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
4
  * or more contributor license agreements. Licensed under the Elastic License
@@ -6,16 +6,21 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
6
6
  * in compliance with, at your election, the Elastic License 2.0 or the Server
7
7
  * Side Public License, v 1.
8
8
  */
9
- import { useContext } from 'react';
9
+ import { useContext, useState, } from 'react';
10
10
  import { css } from '@emotion/react';
11
+ import BrowserOnly from '@docusaurus/BrowserOnly';
11
12
  import Link from '@docusaurus/Link';
12
13
  import useBaseUrl from '@docusaurus/useBaseUrl';
13
14
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
14
15
  import { useThemeConfig } from '@docusaurus/theme-common';
15
- import { EuiImage, euiCanAnimate, euiTextTruncate, useEuiMemoizedStyles, } from '@elastic/eui';
16
+ import { EuiContextMenuItem, EuiContextMenuPanel, EuiImage, EuiPopover, euiCanAnimate, euiTextTruncate, useEuiMemoizedStyles, useGeneratedHtmlId, } from '@elastic/eui';
16
17
  import { AppThemeContext } from '../../components/theme_context';
17
18
  const EUI_LOGO = 'eui_logo.svg';
18
19
  const LOGO_DISTANCE = '5px';
20
+ const elasticLinks = [
21
+ { label: 'Elastic', href: 'https://www.elastic.co' },
22
+ { label: 'Brand Guide', href: 'https://brand.elastic.co' },
23
+ ];
19
24
  const getStyles = ({ euiTheme }) => ({
20
25
  wrapper: css `
21
26
  // create space to prevent focus outline from being cut off
@@ -34,6 +39,26 @@ const getStyles = ({ euiTheme }) => ({
34
39
  @media (min-width: 997px) {
35
40
  margin-inline-end: ${euiTheme.size.l};
36
41
  }
42
+
43
+ ${euiCanAnimate} {
44
+ &:hover {
45
+ .euiNavbarLogo__pink {
46
+ transform: translate(-${LOGO_DISTANCE}, -${LOGO_DISTANCE});
47
+ }
48
+
49
+ .euiNavbarLogo__yellow {
50
+ transform: translate(${LOGO_DISTANCE}, ${LOGO_DISTANCE});
51
+ }
52
+
53
+ .euiNavbarLogo__teal {
54
+ transform: translate(${LOGO_DISTANCE}, -${LOGO_DISTANCE});
55
+ }
56
+
57
+ .euiNavbarLogo__blue {
58
+ transform: translate(-${LOGO_DISTANCE}, ${LOGO_DISTANCE});
59
+ }
60
+ }
61
+ }
37
62
  }
38
63
 
39
64
  .navbar__logo {
@@ -41,9 +66,22 @@ const getStyles = ({ euiTheme }) => ({
41
66
  height: auto;
42
67
  }
43
68
 
69
+ .euiPopover {
70
+ display: flex;
71
+ min-inline-size: 0;
72
+ max-inline-size: 100%;
73
+ }
74
+
44
75
  .navbar__title {
45
76
  ${euiTextTruncate()}
46
77
  }
78
+ `,
79
+ lockup: css `
80
+ display: inline-flex;
81
+ align-items: center;
82
+ min-inline-size: 0;
83
+ max-inline-size: 100%;
84
+ user-select: none;
47
85
  `,
48
86
  imageWrapper: css `
49
87
  overflow: visible;
@@ -75,33 +113,36 @@ const getStyles = ({ euiTheme }) => ({
75
113
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
76
114
  }
77
115
  }
78
-
79
- ${euiCanAnimate} {
80
- &:hover {
81
- .euiNavbarLogo__pink {
82
- transform: translate(-${LOGO_DISTANCE}, -${LOGO_DISTANCE});
83
- }
84
-
85
- .euiNavbarLogo__yellow {
86
- transform: translate(${LOGO_DISTANCE}, ${LOGO_DISTANCE});
87
- }
88
-
89
- .euiNavbarLogo__teal {
90
- transform: translate(${LOGO_DISTANCE}, -${LOGO_DISTANCE});
91
- }
92
-
93
- .euiNavbarLogo__blue {
94
- transform: translate(-${LOGO_DISTANCE}, ${LOGO_DISTANCE});
95
- }
96
- }
97
- }
98
116
  `,
99
117
  });
100
- function EuiNavbarLogo({ alt, className, style, }) {
118
+ function NavbarLogoSvg({ alt, className, style, }) {
101
119
  const styles = useEuiMemoizedStyles(getStyles);
102
120
  const isDecorative = alt === '';
103
121
  return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 32 32", fill: "none", overflow: "visible", className: className, style: style, css: styles.logo, "aria-hidden": isDecorative ? true : undefined, role: isDecorative ? undefined : 'img', "aria-label": isDecorative ? undefined : alt, children: [_jsx("path", { fill: "#FF957D", d: "M18 25c-.5-5.5-5.5-10.5-11-11l7-7c.5 5.5 5.5 10.5 11 11l-7 7z" }), _jsx("circle", { className: "euiNavbarLogo__piece euiNavbarLogo__pink", cx: "7", cy: "7", r: "7", fill: "#F04E98" }), _jsx("circle", { className: "euiNavbarLogo__piece euiNavbarLogo__yellow", cx: "25", cy: "25", r: "7", fill: "#FEC514" }), _jsx("path", { className: "euiNavbarLogo__piece euiNavbarLogo__teal", fill: "#00BFB3", d: "M31 14c-7.18 0-13-5.82-13-13h13v13z" }), _jsx("path", { className: "euiNavbarLogo__piece euiNavbarLogo__blue", fill: "#1BA9F5", d: "M1 18c7.18 0 13 5.82 13 13H1V18z" })] }));
104
122
  }
123
+ function EuiNavbarLogoMenu({ children }) {
124
+ const styles = useEuiMemoizedStyles(getStyles);
125
+ const [isOpen, setIsOpen] = useState(false);
126
+ const [offset, setOffset] = useState();
127
+ const popoverId = useGeneratedHtmlId({ prefix: 'elasticLinks' });
128
+ const closePopover = () => setIsOpen(false);
129
+ const openMenu = (event) => {
130
+ event.preventDefault();
131
+ const anchorBottom = event.currentTarget.getBoundingClientRect().bottom;
132
+ const header = event.currentTarget.closest('.navbar');
133
+ const headerBottom = header?.getBoundingClientRect().bottom ?? anchorBottom;
134
+ setOffset(headerBottom - anchorBottom);
135
+ setIsOpen(true);
136
+ };
137
+ return (_jsx(EuiPopover, { id: popoverId, button: _jsx("span", { css: styles.lockup, onContextMenu: openMenu, children: children }), isOpen: isOpen, closePopover: closePopover, panelPaddingSize: "none", offset: offset, "aria-label": "Elastic links", children: _jsx(EuiContextMenuPanel, { initialFocusedItemIndex: 0, items: elasticLinks.map(({ label, href }) => (_jsx(EuiContextMenuItem, { icon: "logoElastic", href: href, target: "_blank", onClick: (event) => {
138
+ event.stopPropagation();
139
+ closePopover();
140
+ }, children: label }, href))) }) }));
141
+ }
142
+ function EuiNavbarLogo({ children }) {
143
+ const styles = useEuiMemoizedStyles(getStyles);
144
+ return (_jsx(BrowserOnly, { fallback: _jsx("span", { css: styles.lockup, children: children }), children: () => _jsx(EuiNavbarLogoMenu, { children: children }) }));
145
+ }
105
146
  function LogoThemedImage({ logo, alt, imageClassName, }) {
106
147
  const { colorMode } = useContext(AppThemeContext);
107
148
  const isDarkMode = colorMode === 'dark';
@@ -110,7 +151,7 @@ function LogoThemedImage({ logo, alt, imageClassName, }) {
110
151
  const src = isDarkMode
111
152
  ? useBaseUrl(logo.srcDark || logo.src)
112
153
  : useBaseUrl(logo.src);
113
- const themedImage = isEuiLogo ? (_jsx(EuiNavbarLogo, { alt: alt, className: logo.className, style: logo.style })) : (_jsx(EuiImage, { src: src, size: "fullWidth", alt: alt, className: logo.className, wrapperProps: {
154
+ const themedImage = isEuiLogo ? (_jsx(NavbarLogoSvg, { alt: alt, className: logo.className, style: logo.style })) : (_jsx(EuiImage, { src: src, size: "fullWidth", alt: alt, className: logo.className, wrapperProps: {
114
155
  style: logo.style,
115
156
  css: styles.image,
116
157
  } }));
@@ -130,5 +171,7 @@ export default function Logo(props) {
130
171
  // Use logo alt text if provided (including empty string),
131
172
  // and provide a sensible fallback otherwise.
132
173
  const alt = logo?.alt ?? fallbackAlt;
133
- return (_jsx("div", { css: styles.wrapper, children: _jsxs(Link, { to: logoLink, ...propsRest, ...(logo?.target && { target: logo.target }), children: [logo && (_jsx(LogoThemedImage, { logo: logo, alt: alt, imageClassName: imageClassName })), navbarTitle != null && _jsx("b", { className: titleClassName, children: navbarTitle })] }) }));
174
+ const isEuiLogo = logo?.src.includes(EUI_LOGO);
175
+ const lockup = (_jsxs(_Fragment, { children: [logo && (_jsx(LogoThemedImage, { logo: logo, alt: alt, imageClassName: imageClassName })), navbarTitle != null && _jsx("b", { className: titleClassName, children: navbarTitle })] }));
176
+ return (_jsx("div", { css: styles.wrapper, children: _jsx(Link, { to: logoLink, ...propsRest, ...(logo?.target && { target: logo.target }), children: isEuiLogo ? _jsx(EuiNavbarLogo, { children: lockup }) : lockup }) }));
134
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/eui-docusaurus-theme",
3
- "version": "2.8.1-snapshot.1794825855066",
3
+ "version": "2.9.0",
4
4
  "description": "EUI theme for Docusaurus",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "scripts": {
@@ -40,8 +40,8 @@
40
40
  "@docusaurus/theme-common": "^3.7.0",
41
41
  "@docusaurus/utils-validation": "^3.7.0",
42
42
  "@elastic/datemath": "^5.0.3",
43
- "@elastic/eui": "^123.4.0-snapshot.1794825855066",
44
- "@elastic/eui-theme-borealis": "^8.2.0-snapshot.1794825855066",
43
+ "@elastic/eui": "^123.5.0",
44
+ "@elastic/eui-theme-borealis": "^8.2.0",
45
45
  "@emotion/css": "^11.11.2",
46
46
  "@emotion/react": "^11.11.4",
47
47
  "clsx": "^2.1.1",
@@ -55,6 +55,5 @@
55
55
  "peerDependencies": {
56
56
  "react": "^18.0.0",
57
57
  "react-dom": "^18.0.0"
58
- },
59
- "stableVersion": "2.8.1"
58
+ }
60
59
  }
@@ -6,18 +6,30 @@
6
6
  * Side Public License, v 1.
7
7
  */
8
8
 
9
- import { useContext, type CSSProperties, type JSX } from 'react';
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 EuiNavbarLogo({
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
- <EuiNavbarLogo alt={alt} className={logo.className} style={logo.style} />
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
- {logo && (
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
  );