@elastic/eui-docusaurus-theme 2.8.1 → 2.9.0-snapshot.1794972588750
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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface StorybookItem {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}
|
|
5
|
+
type DocStorybook = string | StorybookItem[] | undefined;
|
|
6
|
+
export declare function getDocStorybook(value: unknown): DocStorybook;
|
|
7
|
+
export declare const DocStorybookContext: import("react").Context<DocStorybook>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import { createContext } from 'react';
|
|
9
|
+
function isStorybookItem(value) {
|
|
10
|
+
return (typeof value === 'object' &&
|
|
11
|
+
value !== null &&
|
|
12
|
+
'id' in value &&
|
|
13
|
+
typeof value.id === 'string' &&
|
|
14
|
+
value.id.trim().length > 0 &&
|
|
15
|
+
'label' in value &&
|
|
16
|
+
typeof value.label === 'string' &&
|
|
17
|
+
value.label.trim().length > 0);
|
|
18
|
+
}
|
|
19
|
+
export function getDocStorybook(value) {
|
|
20
|
+
if (typeof value === 'string')
|
|
21
|
+
return value.trim();
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return value.filter(isStorybookItem);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Only document pages provide this context; other MDX headings remain unchanged.
|
|
27
|
+
export const DocStorybookContext = createContext(undefined);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
4
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
5
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
6
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
7
|
+
* Side Public License, v 1.
|
|
8
|
+
*/
|
|
9
|
+
import { useContext, useState } from 'react';
|
|
10
|
+
import { css } from '@emotion/react';
|
|
11
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
12
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
13
|
+
import { EuiButtonEmpty, EuiContextMenuItem, EuiContextMenuPanel, EuiFlexGroup, EuiFlexItem, EuiPopover, useGeneratedHtmlId, } from '@elastic/eui';
|
|
14
|
+
import { DocStorybookContext } from './context';
|
|
15
|
+
import { getStorybookUrl } from '../../utils/storybook';
|
|
16
|
+
const openInStorybookLabel = 'Open in Storybook';
|
|
17
|
+
const titleStyles = css `
|
|
18
|
+
margin-block: var(--eui-theme-content-vertical-spacing);
|
|
19
|
+
|
|
20
|
+
& h1.heading {
|
|
21
|
+
margin-block: 0;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
export const DocTitle = ({ children }) => {
|
|
25
|
+
const storybook = useContext(DocStorybookContext);
|
|
26
|
+
const { siteConfig } = useDocusaurusContext();
|
|
27
|
+
const baseUrl = siteConfig.customFields?.storybookBaseUrl;
|
|
28
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
29
|
+
const popoverId = useGeneratedHtmlId({ prefix: 'docStorybook' });
|
|
30
|
+
const storyId = typeof storybook === 'string' ? storybook : undefined;
|
|
31
|
+
const stories = Array.isArray(storybook) ? storybook : [];
|
|
32
|
+
if ((!storyId && stories.length === 0) || typeof baseUrl !== 'string') {
|
|
33
|
+
return _jsx(_Fragment, { children: children });
|
|
34
|
+
}
|
|
35
|
+
const popoverButton = (_jsx(EuiButtonEmpty, { iconType: "chevronSingleDown", iconSide: "right", onClick: () => setIsOpen(!isOpen), children: openInStorybookLabel }));
|
|
36
|
+
return (_jsxs(EuiFlexGroup, { css: titleStyles, alignItems: "center", justifyContent: "spaceBetween", wrap: true, children: [_jsx(EuiFlexItem, { children: children }), _jsx(EuiFlexItem, { grow: false, children: storyId ? (_jsx(EuiButtonEmpty, { iconType: "external", href: getStorybookUrl(baseUrl, storyId), target: "_blank", children: openInStorybookLabel })) : (_jsx(BrowserOnly, { fallback: popoverButton, children: () => (_jsx(EuiPopover, { id: popoverId, "aria-label": "Storybook components", isOpen: isOpen, closePopover: () => setIsOpen(false), panelPaddingSize: "none", button: popoverButton, children: _jsx(EuiContextMenuPanel, { initialFocusedItemIndex: 0, items: stories.map(({ id, label }) => (_jsx(EuiContextMenuItem, { href: getStorybookUrl(baseUrl, id), target: "_blank", onClick: () => setIsOpen(false), children: label }, id))) }) })) })) })] }));
|
|
37
|
+
};
|
|
@@ -6,6 +6,7 @@ import { useDoc } from '@docusaurus/plugin-content-docs/client';
|
|
|
6
6
|
import MDXContent from '@theme-original/MDXContent';
|
|
7
7
|
import { EuiHorizontalRule, useEuiMemoizedStyles, } from '@elastic/eui';
|
|
8
8
|
import Heading from '../../MDXComponents/Heading';
|
|
9
|
+
import { DocStorybookContext, getDocStorybook, } from '../../../components/doc_title/context';
|
|
9
10
|
/**
|
|
10
11
|
Title can be declared inside md content or declared through
|
|
11
12
|
front matter and added manually. To make both cases consistent,
|
|
@@ -28,7 +29,7 @@ const getContentStyles = ({ euiTheme }) => {
|
|
|
28
29
|
return {
|
|
29
30
|
header: css `
|
|
30
31
|
// required specificity to override docusaurus styles
|
|
31
|
-
&
|
|
32
|
+
& h1.euiTitle {
|
|
32
33
|
--ifm-h1-font-size: var(--eui-font-size-xxl);
|
|
33
34
|
--ifm-h1-vertical-rhythm-bottom: 1.2;
|
|
34
35
|
|
|
@@ -38,7 +39,11 @@ const getContentStyles = ({ euiTheme }) => {
|
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
41
|
export default function DocItemContent({ children }) {
|
|
42
|
+
const { frontMatter } = useDoc();
|
|
43
|
+
const storybook = 'storybook' in frontMatter
|
|
44
|
+
? getDocStorybook(frontMatter.storybook)
|
|
45
|
+
: undefined;
|
|
41
46
|
const syntheticTitle = useSyntheticTitle();
|
|
42
47
|
const styles = useEuiMemoizedStyles(getContentStyles);
|
|
43
|
-
return (_jsxs("div", { className: clsx(ThemeClassNames.docs.docMarkdown, 'markdown'), children: [syntheticTitle && (_jsxs(_Fragment, { children: [_jsx("header", { css: styles.header, children: _jsx(Heading, { as: "h1", children: syntheticTitle }) }), _jsx(EuiHorizontalRule, {})] })), _jsx(MDXContent, { children: children })] }));
|
|
48
|
+
return (_jsx(DocStorybookContext.Provider, { value: storybook, children: _jsxs("div", { className: clsx(ThemeClassNames.docs.docMarkdown, 'markdown'), children: [syntheticTitle && (_jsxs(_Fragment, { children: [_jsx("header", { css: styles.header, children: _jsx(Heading, { as: "h1", children: syntheticTitle }) }), _jsx(EuiHorizontalRule, {})] })), _jsx(MDXContent, { children: children })] }) }));
|
|
44
49
|
}
|
package/lib/theme/Logo/index.js
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
-
|
|
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
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import Heading from '@theme/Heading';
|
|
3
|
-
|
|
3
|
+
import { DocTitle } from '../../components/doc_title';
|
|
4
|
+
const MDXHeading = (props) => props.as === 'h1' ? (_jsx(DocTitle, { children: _jsx(Heading, { ...props }) })) : (_jsx(Heading, { ...props }));
|
|
4
5
|
export default MDXHeading;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getStorybookUrl: (baseUrl: string, id: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
export const getStorybookUrl = (baseUrl, id) => `${baseUrl.replace(/\/$/, '')}/index.html?path=/story/${encodeURIComponent(id)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/eui-docusaurus-theme",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0-snapshot.1794972588750",
|
|
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.
|
|
44
|
-
"@elastic/eui-theme-borealis": "^8.
|
|
43
|
+
"@elastic/eui": "^123.5.0-snapshot.1794972588750",
|
|
44
|
+
"@elastic/eui-theme-borealis": "^8.2.0-snapshot.1794972588750",
|
|
45
45
|
"@emotion/css": "^11.11.2",
|
|
46
46
|
"@emotion/react": "^11.11.4",
|
|
47
47
|
"clsx": "^2.1.1",
|
|
@@ -55,5 +55,6 @@
|
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": "^18.0.0",
|
|
57
57
|
"react-dom": "^18.0.0"
|
|
58
|
-
}
|
|
58
|
+
},
|
|
59
|
+
"stableVersion": "2.9.0"
|
|
59
60
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { createContext } from 'react';
|
|
10
|
+
|
|
11
|
+
interface StorybookItem {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type DocStorybook = string | StorybookItem[] | undefined;
|
|
17
|
+
|
|
18
|
+
function isStorybookItem(value: unknown): value is StorybookItem {
|
|
19
|
+
return (
|
|
20
|
+
typeof value === 'object' &&
|
|
21
|
+
value !== null &&
|
|
22
|
+
'id' in value &&
|
|
23
|
+
typeof value.id === 'string' &&
|
|
24
|
+
value.id.trim().length > 0 &&
|
|
25
|
+
'label' in value &&
|
|
26
|
+
typeof value.label === 'string' &&
|
|
27
|
+
value.label.trim().length > 0
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getDocStorybook(value: unknown): DocStorybook {
|
|
32
|
+
if (typeof value === 'string') return value.trim();
|
|
33
|
+
if (Array.isArray(value)) return value.filter(isStorybookItem);
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Only document pages provide this context; other MDX headings remain unchanged.
|
|
38
|
+
export const DocStorybookContext = createContext<DocStorybook>(undefined);
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { PropsWithChildren, useContext, useState } from 'react';
|
|
10
|
+
import { css } from '@emotion/react';
|
|
11
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
12
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
13
|
+
import {
|
|
14
|
+
EuiButtonEmpty,
|
|
15
|
+
EuiContextMenuItem,
|
|
16
|
+
EuiContextMenuPanel,
|
|
17
|
+
EuiFlexGroup,
|
|
18
|
+
EuiFlexItem,
|
|
19
|
+
EuiPopover,
|
|
20
|
+
useGeneratedHtmlId,
|
|
21
|
+
} from '@elastic/eui';
|
|
22
|
+
|
|
23
|
+
import { DocStorybookContext } from './context';
|
|
24
|
+
import { getStorybookUrl } from '../../utils/storybook';
|
|
25
|
+
|
|
26
|
+
const openInStorybookLabel = 'Open in Storybook';
|
|
27
|
+
|
|
28
|
+
const titleStyles = css`
|
|
29
|
+
margin-block: var(--eui-theme-content-vertical-spacing);
|
|
30
|
+
|
|
31
|
+
& h1.heading {
|
|
32
|
+
margin-block: 0;
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
export const DocTitle = ({ children }: PropsWithChildren) => {
|
|
37
|
+
const storybook = useContext(DocStorybookContext);
|
|
38
|
+
const { siteConfig } = useDocusaurusContext();
|
|
39
|
+
const baseUrl = siteConfig.customFields?.storybookBaseUrl;
|
|
40
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
41
|
+
const popoverId = useGeneratedHtmlId({ prefix: 'docStorybook' });
|
|
42
|
+
|
|
43
|
+
const storyId = typeof storybook === 'string' ? storybook : undefined;
|
|
44
|
+
const stories = Array.isArray(storybook) ? storybook : [];
|
|
45
|
+
|
|
46
|
+
if ((!storyId && stories.length === 0) || typeof baseUrl !== 'string') {
|
|
47
|
+
return <>{children}</>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const popoverButton = (
|
|
51
|
+
<EuiButtonEmpty
|
|
52
|
+
iconType="chevronSingleDown"
|
|
53
|
+
iconSide="right"
|
|
54
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
55
|
+
>
|
|
56
|
+
{openInStorybookLabel}
|
|
57
|
+
</EuiButtonEmpty>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<EuiFlexGroup
|
|
62
|
+
css={titleStyles}
|
|
63
|
+
alignItems="center"
|
|
64
|
+
justifyContent="spaceBetween"
|
|
65
|
+
wrap
|
|
66
|
+
>
|
|
67
|
+
<EuiFlexItem>{children}</EuiFlexItem>
|
|
68
|
+
<EuiFlexItem grow={false}>
|
|
69
|
+
{storyId ? (
|
|
70
|
+
<EuiButtonEmpty
|
|
71
|
+
iconType="external"
|
|
72
|
+
href={getStorybookUrl(baseUrl, storyId)}
|
|
73
|
+
target="_blank"
|
|
74
|
+
>
|
|
75
|
+
{openInStorybookLabel}
|
|
76
|
+
</EuiButtonEmpty>
|
|
77
|
+
) : (
|
|
78
|
+
<BrowserOnly fallback={popoverButton}>
|
|
79
|
+
{() => (
|
|
80
|
+
<EuiPopover
|
|
81
|
+
id={popoverId}
|
|
82
|
+
aria-label="Storybook components"
|
|
83
|
+
isOpen={isOpen}
|
|
84
|
+
closePopover={() => setIsOpen(false)}
|
|
85
|
+
panelPaddingSize="none"
|
|
86
|
+
button={popoverButton}
|
|
87
|
+
>
|
|
88
|
+
<EuiContextMenuPanel
|
|
89
|
+
initialFocusedItemIndex={0}
|
|
90
|
+
items={stories.map(({ id, label }) => (
|
|
91
|
+
<EuiContextMenuItem
|
|
92
|
+
key={id}
|
|
93
|
+
href={getStorybookUrl(baseUrl, id)}
|
|
94
|
+
target="_blank"
|
|
95
|
+
onClick={() => setIsOpen(false)}
|
|
96
|
+
>
|
|
97
|
+
{label}
|
|
98
|
+
</EuiContextMenuItem>
|
|
99
|
+
))}
|
|
100
|
+
/>
|
|
101
|
+
</EuiPopover>
|
|
102
|
+
)}
|
|
103
|
+
</BrowserOnly>
|
|
104
|
+
)}
|
|
105
|
+
</EuiFlexItem>
|
|
106
|
+
</EuiFlexGroup>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -20,6 +20,10 @@ import {
|
|
|
20
20
|
import { Props } from '@theme-original/DocItem/Content';
|
|
21
21
|
|
|
22
22
|
import Heading from '../../MDXComponents/Heading';
|
|
23
|
+
import {
|
|
24
|
+
DocStorybookContext,
|
|
25
|
+
getDocStorybook,
|
|
26
|
+
} from '../../../components/doc_title/context';
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
Title can be declared inside md content or declared through
|
|
@@ -45,7 +49,7 @@ const getContentStyles = ({ euiTheme }: UseEuiTheme) => {
|
|
|
45
49
|
return {
|
|
46
50
|
header: css`
|
|
47
51
|
// required specificity to override docusaurus styles
|
|
48
|
-
&
|
|
52
|
+
& h1.euiTitle {
|
|
49
53
|
--ifm-h1-font-size: var(--eui-font-size-xxl);
|
|
50
54
|
--ifm-h1-vertical-rhythm-bottom: 1.2;
|
|
51
55
|
|
|
@@ -56,20 +60,27 @@ const getContentStyles = ({ euiTheme }: UseEuiTheme) => {
|
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
export default function DocItemContent({ children }: Props): JSX.Element {
|
|
63
|
+
const { frontMatter } = useDoc();
|
|
64
|
+
const storybook =
|
|
65
|
+
'storybook' in frontMatter
|
|
66
|
+
? getDocStorybook(frontMatter.storybook)
|
|
67
|
+
: undefined;
|
|
59
68
|
const syntheticTitle = useSyntheticTitle();
|
|
60
69
|
const styles = useEuiMemoizedStyles(getContentStyles);
|
|
61
70
|
|
|
62
71
|
return (
|
|
63
|
-
<
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
<DocStorybookContext.Provider value={storybook}>
|
|
73
|
+
<div className={clsx(ThemeClassNames.docs.docMarkdown, 'markdown')}>
|
|
74
|
+
{syntheticTitle && (
|
|
75
|
+
<>
|
|
76
|
+
<header css={styles.header}>
|
|
77
|
+
<Heading as="h1">{syntheticTitle}</Heading>
|
|
78
|
+
</header>
|
|
79
|
+
<EuiHorizontalRule />
|
|
80
|
+
</>
|
|
81
|
+
)}
|
|
82
|
+
<MDXContent>{children}</MDXContent>
|
|
83
|
+
</div>
|
|
84
|
+
</DocStorybookContext.Provider>
|
|
74
85
|
);
|
|
75
86
|
}
|