@elastic/eui-docusaurus-theme 2.4.0 → 2.5.0-snapshot.1783954480414

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.
@@ -21,6 +21,7 @@ import {
21
21
  UseEuiTheme,
22
22
  useEuiTheme,
23
23
  EuiPaddingSize,
24
+ EuiThemeProvider,
24
25
  euiPaddingSize,
25
26
  } from '@elastic/eui';
26
27
 
@@ -65,9 +66,14 @@ export const DemoPreview = ({
65
66
  )}
66
67
  >
67
68
  <div css={styles.previewWrapper} style={style}>
68
- <WrapperComponent>
69
- <LivePreview />
70
- </WrapperComponent>
69
+ {/* Use the theme's actual default instead of docs global `lineHeightMultiplier` override */}
70
+ <EuiThemeProvider
71
+ modify={{ font: { lineHeightMultiplier: 1.5 } }}
72
+ >
73
+ <WrapperComponent>
74
+ <LivePreview />
75
+ </WrapperComponent>
76
+ </EuiThemeProvider>
71
77
  </div>
72
78
  </ErrorBoundary>
73
79
  </>
@@ -12,9 +12,9 @@ import useIsBrowser from '@docusaurus/useIsBrowser';
12
12
  import {
13
13
  CommonProps,
14
14
  EuiIcon,
15
+ EuiToolTip,
15
16
  ExclusiveUnion,
16
17
  IconType,
17
- mathWithUnits,
18
18
  PropsForAnchor,
19
19
  PropsForButton,
20
20
  useEuiMemoizedStyles,
@@ -22,6 +22,7 @@ import {
22
22
  } from '@elastic/eui';
23
23
 
24
24
  import { AppThemeContext } from '../theme_context';
25
+ import { getNavbarBreakpoint } from '../../theme/Navbar/breakpoint';
25
26
 
26
27
  type SharedProps = {
27
28
  icon: IconType;
@@ -36,55 +37,63 @@ type Props = ExclusiveUnion<
36
37
  >;
37
38
 
38
39
  // converted from css modules to Emotion
39
- export const getStyles = ({ euiTheme }: UseEuiTheme) => ({
40
- item: css`
41
- display: flex;
42
- align-items: center;
43
- flex-shrink: 0;
44
-
45
- -webkit-tap-highlight-color: transparent;
46
- transition: background var(--ifm-transition-fast);
47
-
48
- &:hover {
49
- background-color: ${euiTheme.components.buttons.backgroundTextHover};
50
- color: currentColor;
51
- }
52
- `,
53
- navItem: css`
54
- justify-content: center;
55
- width: ${euiTheme.size.xl};
56
- height: ${euiTheme.size.xl};
57
- border-radius: 50%;
58
- `,
59
- menuItem: css`
60
- justify-content: flex-start;
61
- gap: ${euiTheme.size.s};
62
-
63
- @media (min-width: 997px) {
40
+ export const getStyles = (euiThemeContext: UseEuiTheme) => {
41
+ const { euiTheme } = euiThemeContext;
42
+ const { desktopMediaQuery } = getNavbarBreakpoint(euiThemeContext);
43
+
44
+ return {
45
+ item: css`
46
+ display: flex;
47
+ align-items: center;
48
+ flex-shrink: 0;
49
+
50
+ -webkit-tap-highlight-color: transparent;
51
+ transition: background var(--ifm-transition-fast);
52
+
53
+ &:hover {
54
+ background-color: ${euiTheme.components.buttons.backgroundTextHover};
55
+ color: currentColor;
56
+ }
57
+ `,
58
+ navItem: css`
64
59
  justify-content: center;
65
60
  width: ${euiTheme.size.xl};
66
61
  height: ${euiTheme.size.xl};
67
62
  border-radius: 50%;
68
- }
69
- `,
70
- darkMode: css`
71
- &:hover {
72
- color: currentColor;
73
- }
74
- `,
75
- disabled: css`
76
- cursor: not-allowed;
77
- `,
78
- selected: css`
79
- background-color: ${euiTheme.colors.backgroundFilledText};
80
- color: ${euiTheme.colors.textInverse};
81
- `,
82
- title: css`
83
- @media (min-width: 997px) {
84
- display: none;
85
- }
86
- `,
87
- });
63
+ `,
64
+ menuItem: css`
65
+ justify-content: flex-start;
66
+ gap: ${euiTheme.size.s};
67
+
68
+ ${desktopMediaQuery} {
69
+ justify-content: center;
70
+ width: ${euiTheme.size.xl};
71
+ height: ${euiTheme.size.xl};
72
+ border-radius: 50%;
73
+ }
74
+ `,
75
+ darkMode: css`
76
+ &:hover {
77
+ color: currentColor;
78
+ }
79
+ `,
80
+ disabled: css`
81
+ cursor: not-allowed;
82
+ `,
83
+ selected: css`
84
+ background-color: ${euiTheme.colors.backgroundFilledText};
85
+ color: ${euiTheme.colors.textInverse};
86
+ `,
87
+ title: css`
88
+ ${desktopMediaQuery} {
89
+ display: none;
90
+ }
91
+ `,
92
+ tooltipAnchor: css`
93
+ display: inline-flex;
94
+ `,
95
+ };
96
+ };
88
97
 
89
98
  // using a type guard to ensure proper typing from ExclusiveUnion
90
99
  const isAnchorClick = (
@@ -118,6 +127,7 @@ export const NavbarItem = (props: Props) => {
118
127
  !isBrowser && styles.disabled,
119
128
  isSelected && styles.selected,
120
129
  isDarkMode && styles.darkMode,
130
+ css,
121
131
  ];
122
132
 
123
133
  const content = showLabel ? (
@@ -129,31 +139,25 @@ export const NavbarItem = (props: Props) => {
129
139
  <EuiIcon type={icon} />
130
140
  );
131
141
 
132
- if (isAnchorClick(onClick, href)) {
133
- return (
134
- <a
135
- href={href}
136
- target={target ?? '_blank'}
137
- title={title}
138
- className={className}
139
- css={cssStyles}
140
- onClick={onClick}
141
- aria-label={title}
142
- aria-live="polite"
143
- >
144
- {content}
145
- </a>
146
- );
147
- }
148
-
149
- return (
142
+ const control = isAnchorClick(onClick, href) ? (
143
+ <a
144
+ href={href}
145
+ target={target ?? '_blank'}
146
+ className={className}
147
+ css={cssStyles}
148
+ onClick={onClick}
149
+ aria-label={title}
150
+ aria-live="polite"
151
+ >
152
+ {content}
153
+ </a>
154
+ ) : (
150
155
  <button
151
156
  type="button"
152
157
  disabled={!isBrowser}
153
158
  className={className}
154
159
  css={cssStyles}
155
160
  onClick={onClick}
156
- title={title}
157
161
  aria-label={title}
158
162
  aria-live="polite"
159
163
  aria-pressed={isSelected != null ? isSelected : undefined}
@@ -161,4 +165,19 @@ export const NavbarItem = (props: Props) => {
161
165
  {content}
162
166
  </button>
163
167
  );
168
+
169
+ if (!title) {
170
+ return control;
171
+ }
172
+
173
+ return (
174
+ <EuiToolTip
175
+ content={title}
176
+ disableScreenReaderOutput
177
+ repositionOnScroll
178
+ anchorProps={{ css: styles.tooltipAnchor }}
179
+ >
180
+ {control}
181
+ </EuiToolTip>
182
+ );
164
183
  };
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { css } from '@emotion/react';
10
- import { EuiCallOut, EuiText } from '@elastic/eui';
10
+ import { EuiCallOut } from '@elastic/eui';
11
11
  import type { Props } from '@theme-original/Admonition';
12
12
  import type AdmonitionTypes from '@theme-original/Admonition/Types';
13
13
 
@@ -22,13 +22,13 @@ type CalloutVariant =
22
22
  | 'important'
23
23
  | 'success'
24
24
  | 'caution';
25
- type VariantColor = 'accent' | 'primary' | 'success' | 'warning' | 'danger';
25
+ type VariantColor = 'primary' | 'success' | 'warning' | 'danger';
26
26
 
27
27
  const VARIANT_TO_PROPS_MAP: Record<
28
28
  CalloutVariant,
29
29
  { iconType?: string; color?: VariantColor }
30
30
  > = {
31
- note: { iconType: 'paperClip', color: 'accent' },
31
+ note: { iconType: 'paperClip', color: 'primary' },
32
32
  tip: { iconType: 'faceHappy', color: 'success' },
33
33
  info: { iconType: 'info', color: 'primary' },
34
34
  accessibility: { iconType: 'accessibility', color: 'primary' },
@@ -56,7 +56,6 @@ const Callout = ({ title, type, children }: Props) => {
56
56
  return (
57
57
  <EuiCallOut
58
58
  title={title}
59
- iconType="info"
60
59
  color="primary"
61
60
  {...variantProps}
62
61
  css={css`
@@ -8,11 +8,18 @@
8
8
 
9
9
  import React, { isValidElement, type ReactNode, JSX } from 'react';
10
10
  import { css } from '@emotion/react';
11
- import { EuiCodeBlock } from '@elastic/eui';
11
+ import { EuiCodeBlock, useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui';
12
12
  import type { Props } from '@theme/CodeBlock';
13
13
 
14
14
  import { Demo } from '../../components/demo';
15
15
 
16
+ const getStyles = ({ euiTheme }: UseEuiTheme) => ({
17
+ codeBlock: css`
18
+ margin-block: ${euiTheme.size.base};
19
+ word-break: break-word;
20
+ `,
21
+ });
22
+
16
23
  /**
17
24
  * Best attempt to make the children a plain string so it is copyable. If there
18
25
  * are react elements, we will not be able to copy the content, and it will
@@ -35,21 +42,24 @@ export default function CodeBlock({
35
42
  }: Props): JSX.Element {
36
43
  const children = maybeStringifyChildren(rawChildren);
37
44
  const language = className?.replace('language-', '') || undefined;
45
+ const styles = useEuiMemoizedStyles(getStyles);
38
46
 
39
47
  if (metastring?.startsWith('interactive')) {
40
48
  return <Demo {...props}>{children}</Demo>;
41
49
  }
42
50
 
51
+ // Don't show the fullscreen button for one-liner snippets
52
+ const isOneLiner =
53
+ typeof children === 'string' && !children.trim().includes('\n');
54
+
43
55
  return (
44
56
  <EuiCodeBlock
45
57
  {...props}
46
58
  fontSize="m"
47
- overflowHeight={450}
59
+ overflowHeight={isOneLiner ? undefined : 450}
48
60
  language={language}
49
61
  isCopyable
50
- css={css`
51
- word-break: break-word;
52
- `}
62
+ css={styles.codeBlock}
53
63
  >
54
64
  {children}
55
65
  </EuiCodeBlock>
@@ -11,6 +11,7 @@ import { Props as HeadingProps } from '@theme/Heading';
11
11
  import {
12
12
  EuiTitle,
13
13
  EuiButtonIcon,
14
+ EuiToolTip,
14
15
  UseEuiTheme,
15
16
  EuiTitleProps,
16
17
  useEuiMemoizedStyles,
@@ -76,15 +77,16 @@ const Heading = ({
76
77
  >
77
78
  {children}
78
79
  {shouldShowSectionLink && (
79
- <EuiButtonIcon
80
- css={styles.anchor}
81
- href={`#${id}`}
82
- aria-label={anchorTitle}
83
- title={anchorTitle}
84
- iconType="link"
85
- color="text"
86
- size="xs"
87
- />
80
+ <EuiToolTip content={anchorTitle} disableScreenReaderOutput>
81
+ <EuiButtonIcon
82
+ css={styles.anchor}
83
+ href={`#${id}`}
84
+ aria-label={anchorTitle}
85
+ iconType="link"
86
+ color="text"
87
+ size="xs"
88
+ />
89
+ </EuiToolTip>
88
90
  )}
89
91
  </Component>
90
92
  </EuiTitle>
@@ -40,6 +40,7 @@ import {
40
40
  VersionSwitcherProps,
41
41
  } from '../../../components/version_switcher';
42
42
  import { HighContrastModeToggle } from '../../../components/high_contrast_mode_toggle';
43
+ import { getNavbarBreakpoint } from '../breakpoint';
43
44
 
44
45
  const DOCS_PATH = '/docs';
45
46
 
@@ -54,6 +55,8 @@ const getStyles = (euiThemeContext: UseEuiTheme) => {
54
55
  const { euiTheme } = euiThemeContext;
55
56
  const form = euiFormVariables(euiThemeContext);
56
57
  const iconColor = encodeURIComponent(euiTheme.colors.text);
58
+ const { desktopMediaQuery, mobileMediaQuery } =
59
+ getNavbarBreakpoint(euiThemeContext);
57
60
 
58
61
  return {
59
62
  navbarItems: css`
@@ -62,7 +65,7 @@ const getStyles = (euiThemeContext: UseEuiTheme) => {
62
65
 
63
66
  .navbar__item,
64
67
  [class*='colorModeToggle'] {
65
- @media (max-width: 996px) {
68
+ ${mobileMediaQuery} {
66
69
  display: none;
67
70
  }
68
71
  }
@@ -74,12 +77,16 @@ const getStyles = (euiThemeContext: UseEuiTheme) => {
74
77
  background-color: var(--ifm-color-emphasis-200);
75
78
  color: currentColor;
76
79
  }
80
+
81
+ ${mobileMediaQuery} {
82
+ display: inherit;
83
+ }
77
84
  }
78
85
  `,
79
86
  navbarItemsLeft: css`
80
87
  gap: ${euiTheme.size.s};
81
88
 
82
- @media (min-width: 997px) {
89
+ ${desktopMediaQuery} {
83
90
  gap: ${euiTheme.size.l};
84
91
  }
85
92
 
@@ -91,7 +98,7 @@ const getStyles = (euiThemeContext: UseEuiTheme) => {
91
98
  gap: ${euiTheme.size.s};
92
99
  `,
93
100
  actions: css`
94
- @media (max-width: 996px) {
101
+ ${mobileMediaQuery} {
95
102
  display: none;
96
103
  }
97
104
  `,
@@ -130,22 +137,18 @@ const getStyles = (euiThemeContext: UseEuiTheme) => {
130
137
  max-inline-size: 25rem;
131
138
  }
132
139
 
133
- @media (min-width: 997px) {
140
+ ${desktopMediaQuery} {
134
141
  min-inline-size: 15rem;
135
142
  }
136
-
137
- @media (min-width: 1200px) {
138
- min-inline-size: 25rem;
139
- }
140
143
  }
141
144
  `,
142
145
  versionSwitcher: css`
143
- @media (max-width: 996px) {
146
+ ${mobileMediaQuery} {
144
147
  display: none;
145
148
  }
146
149
  `,
147
150
  themeSwitcher: css`
148
- @media (max-width: 996px) {
151
+ ${mobileMediaQuery} {
149
152
  display: none;
150
153
  }
151
154
  `,
@@ -6,7 +6,8 @@
6
6
  * Side Public License, v 1.
7
7
  */
8
8
 
9
- import { type ReactNode } from 'react';
9
+ import { type ReactNode, useEffect } from 'react';
10
+ import { useWindowSize } from '@docusaurus/theme-common';
10
11
  import {
11
12
  useLockBodyScroll,
12
13
  useNavbarMobileSidebar,
@@ -15,8 +16,10 @@ import NavbarMobileSidebarLayout from '@theme-original/Navbar/MobileSidebar/Layo
15
16
  import NavbarMobileSidebarHeader from './Header';
16
17
  import NavbarMobileSidebarPrimaryMenu from '@theme-original/Navbar/MobileSidebar/PrimaryMenu';
17
18
  import NavbarMobileSidebarSecondaryMenu from '@theme-original/Navbar/MobileSidebar/SecondaryMenu';
19
+ import { useEuiTheme } from '@elastic/eui';
18
20
 
19
21
  import { VersionSwitcherProps } from '../../../components/version_switcher';
22
+ import { getNavbarBreakpoint } from '../breakpoint';
20
23
 
21
24
  type Props = {
22
25
  versionSwitcherOptions?: VersionSwitcherProps;
@@ -26,9 +29,29 @@ export default function NavbarMobileSidebar({
26
29
  versionSwitcherOptions,
27
30
  }: Props): ReactNode {
28
31
  const mobileSidebar = useNavbarMobileSidebar();
29
- useLockBodyScroll(mobileSidebar.shown);
32
+ const {
33
+ disabled,
34
+ shouldRender: shouldRenderDefault,
35
+ shown,
36
+ toggle,
37
+ } = mobileSidebar;
38
+ const euiThemeContext = useEuiTheme();
39
+ const { mobileBreakpoint } = getNavbarBreakpoint(euiThemeContext);
40
+ const windowSize = useWindowSize({
41
+ desktopBreakpoint: mobileBreakpoint,
42
+ });
43
+ const shouldRender =
44
+ shouldRenderDefault || (!disabled && windowSize === 'mobile');
30
45
 
31
- if (!mobileSidebar.shouldRender) {
46
+ useLockBodyScroll(shouldRender && shown);
47
+
48
+ useEffect(() => {
49
+ if (windowSize === 'desktop' && shown) {
50
+ toggle();
51
+ }
52
+ }, [shown, toggle, windowSize]);
53
+
54
+ if (!shouldRender) {
32
55
  return null;
33
56
  }
34
57
 
@@ -0,0 +1,23 @@
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
+ import type { UseEuiTheme } from '@elastic/eui';
10
+
11
+ const NAVBAR_MOBILE_BREAKPOINT_KEY = 'xl';
12
+
13
+ export const getNavbarBreakpoint = ({ euiTheme }: UseEuiTheme) => {
14
+ const mobileBreakpoint = euiTheme.breakpoint[NAVBAR_MOBILE_BREAKPOINT_KEY];
15
+ const desktopBreakpoint = mobileBreakpoint + 1;
16
+
17
+ return {
18
+ desktopBreakpoint,
19
+ desktopMediaQuery: `@media (min-width: ${desktopBreakpoint}px)`,
20
+ mobileBreakpoint,
21
+ mobileMediaQuery: `@media (max-width: ${mobileBreakpoint}px)`,
22
+ };
23
+ };