1+ 'strict'
2+
13import {
24 EuiButton ,
35 EuiContextMenu ,
@@ -6,7 +8,12 @@ import {
68 EuiIcon ,
79 EuiPopover ,
810 EuiText ,
11+ EuiPanel ,
12+ EuiLink ,
13+ useEuiOverflowScroll ,
914 useGeneratedHtmlId ,
15+ useEuiTheme ,
16+ useEuiFontSize ,
1017} from '@elastic/eui'
1118import { icon as EuiIconVisualizeApp } from '@elastic/eui/es/components/icon/assets/app_visualize'
1219import { icon as EuiIconArrowDown } from '@elastic/eui/es/components/icon/assets/arrow_down'
@@ -50,12 +57,18 @@ type VersionDropdownItem = {
5057}
5158
5259type VersionDropdownProps = {
53- currentVersion : string
54- items : VersionDropdownItem [ ]
60+ currentVersion ?: string
61+ allVersionsUrl ?: string
62+ items ?: VersionDropdownItem [ ]
5563}
5664
57- const VersionDropdown = ( { currentVersion, items } : VersionDropdownProps ) => {
65+ const VersionDropdown = ( {
66+ allVersionsUrl,
67+ currentVersion,
68+ items,
69+ } : VersionDropdownProps ) => {
5870 const [ isPopoverOpen , setPopover ] = useState ( false )
71+ const { euiTheme } = useEuiTheme ( )
5972
6073 const contextMenuPopoverId = useGeneratedHtmlId ( {
6174 prefix : 'contextMenuPopover' ,
@@ -84,60 +97,112 @@ const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => {
8497 const convertToPanels = (
8598 items : VersionDropdownItem [ ]
8699 ) : EuiContextMenuPanelDescriptor [ ] => {
87- return items . flatMap ( ( item , index ) => {
88- if ( item . children == null ) {
89- return [ ]
90- } else {
91- return {
92- id : index + 1 ,
93- title : item . name ,
94- initialFocusedItemIndex : 0 ,
95- width : WIDTH ,
96- disabled : item . disabled ,
97- size : 's' ,
98- items : item . children ? convertItems ( item . children ) : [ ] ,
99- }
100- }
101- } )
100+ return items == null
101+ ? [ ]
102+ : items . flatMap ( ( item , index ) => {
103+ if ( item . children == null ) {
104+ return [ ]
105+ } else {
106+ return {
107+ id : index + 1 ,
108+ title : item . name ,
109+ initialFocusedItemIndex : 0 ,
110+ width : WIDTH ,
111+ disabled : item . disabled ,
112+ size : 's' ,
113+ items : item . children
114+ ? convertItems ( item . children )
115+ : [ ] ,
116+ }
117+ }
118+ } )
102119 }
103120
104121 const WIDTH = 175
105122
106- const topLevelItems = items . map ( ( item , index ) => {
107- return {
108- name : item . name ,
109- panel : item . children ?. length ? index + 1 : undefined ,
110- href : item . href ,
111- disabled : item . disabled ,
112- }
113- } )
123+ const topLevelItems = ( ) =>
124+ items . map ( ( item , index ) => {
125+ return {
126+ name : item . name ,
127+ panel : item . children ?. length ? index + 1 : undefined ,
128+ href : item . href ,
129+ disabled : item . disabled ,
130+ }
131+ } )
114132
115- const subpanels = convertToPanels ( items )
133+ const subpanels = ( ) => convertToPanels ( items )
116134
117- const panels : EuiContextMenuPanelDescriptor [ ] = [
135+ const panels = ( ) : EuiContextMenuPanelDescriptor [ ] => [
118136 {
119137 id : 0 ,
120138 title : (
121139 < EuiFlexGroup gutterSize = "s" alignItems = "center" >
122140 < EuiFlexItem grow = { 0 } >
123- < EuiIcon type = "check" />
141+ < EuiIcon type = "check" size = "s" />
124142 </ EuiFlexItem >
125143 < EuiFlexItem grow = { 1 } >
126- Current ( { currentVersion } )
144+ < EuiText size = "s" > { currentVersion } </ EuiText >
127145 </ EuiFlexItem >
128146 </ EuiFlexGroup >
129147 ) ,
130148 width : WIDTH ,
131149 size : 's' ,
132150 items : [
133- ...topLevelItems ,
134- {
135- name : 'All versions' ,
136- href : 'https://elastic.co' ,
137- } ,
151+ ...( items == null
152+ ? [
153+ {
154+ renderItem : ( ) => (
155+ < EuiPanel paddingSize = "s" hasShadow = { false } >
156+ < EuiText size = "xs" color = "subdued" >
157+ There are no other versions available
158+ for this page.
159+ </ EuiText >
160+ </ EuiPanel >
161+ ) ,
162+ } ,
163+ ]
164+ : topLevelItems ( ) ) ,
165+ ...( items ?. length === 0
166+ ? [
167+ {
168+ renderItem : ( ) => (
169+ < EuiPanel paddingSize = "s" hasShadow = { false } >
170+ < EuiText size = "xs" color = "subdued" >
171+ This page was fully migrated to the
172+ current version.
173+ </ EuiText >
174+ </ EuiPanel >
175+ ) ,
176+ } ,
177+ ]
178+ : [ ] ) ,
179+ ...( allVersionsUrl != null
180+ ? [
181+ {
182+ renderItem : ( ) => (
183+ < EuiPanel
184+ css = { css `
185+ border-top : 1px solid
186+ ${ euiTheme . border . color } ;
187+ padding : ${ euiTheme . size . s } ;
188+ ` }
189+ >
190+ < EuiLink
191+ href = "/docs/versions"
192+ color = "text"
193+ >
194+ < EuiText size = "s" >
195+ View all versions
196+ </ EuiText >
197+ </ EuiLink >
198+ </ EuiPanel >
199+ ) ,
200+ } ,
201+ ]
202+ : [ ] ) ,
138203 ] ,
139204 } ,
140- ...subpanels ,
205+ ...( items != null ? subpanels ( ) : [ ] ) ,
141206 ]
142207
143208 const button = (
@@ -150,13 +215,12 @@ const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => {
150215 style = { { borderRadius : 9999 } }
151216 >
152217 < EuiText
153- size = "xs"
154218 css = { css `
155- font-weight : 600 ;
156- font-size : 0.875 rem ;
219+ font-weight : ${ euiTheme . font . weight . bold } ;
220+ font-size : ${ useEuiFontSize ( 'xs' ) . fontSize } ;
157221 ` }
158222 >
159- Current ({ currentVersion } )
223+ Current version ({ currentVersion } )
160224 </ EuiText >
161225 </ EuiButton >
162226 )
@@ -168,10 +232,30 @@ const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => {
168232 isOpen = { isPopoverOpen }
169233 closePopover = { closePopover }
170234 panelPaddingSize = "none"
171- anchorPosition = "downLeft "
235+ anchorPosition = "downRight "
172236 repositionOnScroll = { true }
173237 >
174- < EuiContextMenu initialPanelId = { 0 } size = "s" panels = { panels } />
238+ < EuiContextMenu
239+ initialPanelId = { 0 }
240+ size = "s"
241+ panels = { panels ( ) }
242+ css = { css `
243+ max-height : 70vh ;
244+ button {
245+ cursor : pointer;
246+ & : disabled {
247+ cursor : default;
248+ }
249+ }
250+ .euiContextMenuPanel__title {
251+ position : sticky;
252+ top : 0 ;
253+ background-color : ${ euiTheme . colors
254+ . backgroundBasePlain } !important ;
255+ }
256+ ${ useEuiOverflowScroll ( 'y' ) }
257+ ` }
258+ />
175259 </ EuiPopover >
176260 )
177261}
@@ -182,6 +266,7 @@ customElements.define(
182266 props : {
183267 items : 'json' ,
184268 currentVersion : 'string' ,
269+ allVersionsUrl : 'string' ,
185270 } ,
186271 } )
187272)
0 commit comments