@elastic/eui-docusaurus-theme 2.2.0 → 2.3.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.
|
@@ -19,5 +19,12 @@ export type VersionSwitcherProps = {
|
|
|
19
19
|
* List of available versions to switch to
|
|
20
20
|
*/
|
|
21
21
|
versions: string[];
|
|
22
|
+
/**
|
|
23
|
+
* URL to fetch the latest list of versions from.
|
|
24
|
+
* When provided, versions are fetched client-side from this URL,
|
|
25
|
+
* falling back to the static `versions` prop if the fetch fails.
|
|
26
|
+
* This ensures all deployed versions are always visible in the switcher.
|
|
27
|
+
*/
|
|
28
|
+
versionsUrl?: string;
|
|
22
29
|
};
|
|
23
|
-
export declare const VersionSwitcher: ({ ariaLabel, currentVersion, extraAction, previousVersionUrl, versions, }: VersionSwitcherProps) => import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
30
|
+
export declare const VersionSwitcher: ({ ariaLabel, currentVersion, extraAction, previousVersionUrl, versions, versionsUrl, }: VersionSwitcherProps) => import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
@@ -6,7 +6,7 @@ import { jsxs as _jsxs, jsx as _jsx } 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 { useState } from 'react';
|
|
9
|
+
import { useEffect, useState } from 'react';
|
|
10
10
|
import { css } from '@emotion/react';
|
|
11
11
|
import { FixedSizeList } from 'react-window';
|
|
12
12
|
import { EuiButtonEmpty, euiFocusRing, EuiListGroupItem, EuiPopover, useEuiMemoizedStyles, } from '@elastic/eui';
|
|
@@ -33,18 +33,46 @@ const getStyles = (euiThemeContext) => {
|
|
|
33
33
|
const pronounceVersion = (version) => {
|
|
34
34
|
return `version ${version.replaceAll('.', ' point ')}`;
|
|
35
35
|
};
|
|
36
|
-
export const VersionSwitcher = ({ ariaLabel, currentVersion, extraAction, previousVersionUrl, versions, }) => {
|
|
36
|
+
export const VersionSwitcher = ({ ariaLabel, currentVersion, extraAction, previousVersionUrl, versions, versionsUrl, }) => {
|
|
37
37
|
const [isPopoverOpen, setPopoverOpen] = useState(false);
|
|
38
|
+
const [allVersions, setAllVersions] = useState(versions);
|
|
38
39
|
const styles = useEuiMemoizedStyles(getStyles);
|
|
39
|
-
|
|
40
|
+
// Fetch the latest versions list from the main deployment
|
|
41
|
+
// to ensure the switcher always shows all available versions,
|
|
42
|
+
// even on older documentation deployments
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!versionsUrl)
|
|
45
|
+
return;
|
|
46
|
+
fetch(versionsUrl)
|
|
47
|
+
.then((response) => {
|
|
48
|
+
if (!response.ok)
|
|
49
|
+
throw new Error('Failed to fetch versions');
|
|
50
|
+
return response.json();
|
|
51
|
+
})
|
|
52
|
+
.then((data) => {
|
|
53
|
+
if (data?.euiVersions?.length) {
|
|
54
|
+
// Ensure the current version is always included
|
|
55
|
+
const fetchedVersions = data.euiVersions;
|
|
56
|
+
if (!fetchedVersions.includes(currentVersion)) {
|
|
57
|
+
fetchedVersions.push(currentVersion);
|
|
58
|
+
}
|
|
59
|
+
setAllVersions(fetchedVersions);
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.catch(() => {
|
|
63
|
+
// Silently fall back to statically bundled versions
|
|
64
|
+
});
|
|
65
|
+
}, [versionsUrl, currentVersion]);
|
|
66
|
+
if (!allVersions?.length)
|
|
40
67
|
return null;
|
|
68
|
+
const latestVersion = allVersions[0];
|
|
41
69
|
const button = (_jsxs(EuiButtonEmpty, { size: "s", color: "text", iconType: "arrowDown", iconSide: "right", css: styles.button, onClick: () => setPopoverOpen((isOpen) => !isOpen), "aria-label": `${pronounceVersion(currentVersion)}. Click to switch versions`, children: ["v", currentVersion] }));
|
|
42
|
-
return (_jsx(EuiPopover, { isOpen: isPopoverOpen, closePopover: () => setPopoverOpen(false), button: button, repositionOnScroll: true, panelPaddingSize: "xs", "aria-label": ariaLabel, children: _jsx(FixedSizeList, { className: "eui-yScroll", itemCount:
|
|
43
|
-
const version =
|
|
70
|
+
return (_jsx(EuiPopover, { isOpen: isPopoverOpen, closePopover: () => setPopoverOpen(false), button: button, repositionOnScroll: true, panelPaddingSize: "xs", "aria-label": ariaLabel, children: _jsx(FixedSizeList, { className: "eui-yScroll", itemCount: allVersions.length, itemSize: 24, height: 200, width: 120, innerElementType: "ul", children: ({ index, style }) => {
|
|
71
|
+
const version = allVersions[index];
|
|
44
72
|
const isCurrentVersion = version === currentVersion;
|
|
45
73
|
const screenReaderVersion = pronounceVersion(version);
|
|
46
|
-
const url =
|
|
47
|
-
?
|
|
74
|
+
const url = version === latestVersion
|
|
75
|
+
? `${previousVersionUrl}/`
|
|
48
76
|
: `${previousVersionUrl}/v${version}/`;
|
|
49
77
|
return (_jsx(EuiListGroupItem, { css: styles.listItem, style: style, size: "xs", label: `v${version}`, "aria-label": screenReaderVersion, href: url, isActive: isCurrentVersion, color: isCurrentVersion ? 'primary' : 'text', extraAction: extraAction?.(version) }));
|
|
50
78
|
} }) }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/eui-docusaurus-theme",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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": "^
|
|
44
|
-
"@elastic/eui-theme-borealis": "^
|
|
43
|
+
"@elastic/eui": "^113.0.0",
|
|
44
|
+
"@elastic/eui-theme-borealis": "^6.0.0",
|
|
45
45
|
"@emotion/css": "^11.11.2",
|
|
46
46
|
"@emotion/react": "^11.11.4",
|
|
47
47
|
"@types/react-window": "^1.8.8",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Side Public License, v 1.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { ComponentProps, useState } from 'react';
|
|
9
|
+
import { ComponentProps, useEffect, useState } from 'react';
|
|
10
10
|
import { css } from '@emotion/react';
|
|
11
11
|
import { FixedSizeList } from 'react-window';
|
|
12
12
|
import {
|
|
@@ -68,6 +68,13 @@ export type VersionSwitcherProps = {
|
|
|
68
68
|
* List of available versions to switch to
|
|
69
69
|
*/
|
|
70
70
|
versions: string[];
|
|
71
|
+
/**
|
|
72
|
+
* URL to fetch the latest list of versions from.
|
|
73
|
+
* When provided, versions are fetched client-side from this URL,
|
|
74
|
+
* falling back to the static `versions` prop if the fetch fails.
|
|
75
|
+
* This ensures all deployed versions are always visible in the switcher.
|
|
76
|
+
*/
|
|
77
|
+
versionsUrl?: string;
|
|
71
78
|
};
|
|
72
79
|
|
|
73
80
|
export const VersionSwitcher = ({
|
|
@@ -76,11 +83,41 @@ export const VersionSwitcher = ({
|
|
|
76
83
|
extraAction,
|
|
77
84
|
previousVersionUrl,
|
|
78
85
|
versions,
|
|
86
|
+
versionsUrl,
|
|
79
87
|
}: VersionSwitcherProps) => {
|
|
80
88
|
const [isPopoverOpen, setPopoverOpen] = useState(false);
|
|
89
|
+
const [allVersions, setAllVersions] = useState(versions);
|
|
81
90
|
const styles = useEuiMemoizedStyles(getStyles);
|
|
82
91
|
|
|
83
|
-
|
|
92
|
+
// Fetch the latest versions list from the main deployment
|
|
93
|
+
// to ensure the switcher always shows all available versions,
|
|
94
|
+
// even on older documentation deployments
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!versionsUrl) return;
|
|
97
|
+
|
|
98
|
+
fetch(versionsUrl)
|
|
99
|
+
.then((response) => {
|
|
100
|
+
if (!response.ok) throw new Error('Failed to fetch versions');
|
|
101
|
+
return response.json();
|
|
102
|
+
})
|
|
103
|
+
.then((data) => {
|
|
104
|
+
if (data?.euiVersions?.length) {
|
|
105
|
+
// Ensure the current version is always included
|
|
106
|
+
const fetchedVersions: string[] = data.euiVersions;
|
|
107
|
+
if (!fetchedVersions.includes(currentVersion)) {
|
|
108
|
+
fetchedVersions.push(currentVersion);
|
|
109
|
+
}
|
|
110
|
+
setAllVersions(fetchedVersions);
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
.catch(() => {
|
|
114
|
+
// Silently fall back to statically bundled versions
|
|
115
|
+
});
|
|
116
|
+
}, [versionsUrl, currentVersion]);
|
|
117
|
+
|
|
118
|
+
if (!allVersions?.length) return null;
|
|
119
|
+
|
|
120
|
+
const latestVersion = allVersions[0];
|
|
84
121
|
|
|
85
122
|
const button = (
|
|
86
123
|
<EuiButtonEmpty
|
|
@@ -109,19 +146,19 @@ export const VersionSwitcher = ({
|
|
|
109
146
|
>
|
|
110
147
|
<FixedSizeList
|
|
111
148
|
className="eui-yScroll"
|
|
112
|
-
itemCount={
|
|
149
|
+
itemCount={allVersions.length}
|
|
113
150
|
itemSize={24}
|
|
114
151
|
height={200}
|
|
115
152
|
width={120}
|
|
116
153
|
innerElementType="ul"
|
|
117
154
|
>
|
|
118
155
|
{({ index, style }) => {
|
|
119
|
-
const version =
|
|
156
|
+
const version = allVersions[index];
|
|
120
157
|
const isCurrentVersion = version === currentVersion;
|
|
121
158
|
const screenReaderVersion = pronounceVersion(version!);
|
|
122
159
|
|
|
123
|
-
const url =
|
|
124
|
-
?
|
|
160
|
+
const url = version === latestVersion
|
|
161
|
+
? `${previousVersionUrl}/`
|
|
125
162
|
: `${previousVersionUrl}/v${version}/`;
|
|
126
163
|
|
|
127
164
|
return (
|