-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add header badge for PR staging instances (#7347)
- Loading branch information
Showing
2 changed files
with
110 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState, useMemo } from 'react'; | ||
import { FixedSizeList } from 'react-window'; | ||
|
||
import { | ||
EuiBadge, | ||
EuiPopover, | ||
EuiListGroupItem, | ||
} from '../../../../src/components'; | ||
|
||
const { euiVersions } = require('./versions.json'); | ||
const currentVersion = require('../../../../package.json').version; | ||
|
||
const pronounceVersion = (version: string) => { | ||
return `version ${version.replaceAll('.', ' point ')}`; // NVDA pronounciation issue | ||
}; | ||
|
||
export const VersionSwitcher = () => { | ||
const [isVersionPopoverOpen, setIsVersionPopoverOpen] = useState(false); | ||
|
||
const versionBadge = useMemo(() => { | ||
return ( | ||
<EuiBadge | ||
onClick={() => setIsVersionPopoverOpen((isOpen) => !isOpen)} | ||
onClickAriaLabel={`${pronounceVersion( | ||
currentVersion | ||
)}. Click to switch versions`} | ||
color="default" | ||
> | ||
v{currentVersion} | ||
</EuiBadge> | ||
); | ||
}, []); | ||
|
||
return ( | ||
<EuiPopover | ||
isOpen={isVersionPopoverOpen} | ||
closePopover={() => setIsVersionPopoverOpen(false)} | ||
button={versionBadge} | ||
repositionOnScroll | ||
panelPaddingSize="xs" | ||
> | ||
<FixedSizeList | ||
className="eui-yScroll" | ||
itemCount={euiVersions.length} | ||
itemSize={24} | ||
height={200} | ||
width={120} | ||
innerElementType="ul" | ||
> | ||
{({ index, style }) => { | ||
const version = euiVersions[index]; | ||
const screenReaderVersion = pronounceVersion(version); | ||
return ( | ||
<EuiListGroupItem | ||
style={style} | ||
size="xs" | ||
label={`v${version}`} | ||
aria-label={screenReaderVersion} | ||
href={`https://eui.elastic.co/v${version}/`} | ||
extraAction={{ | ||
'aria-label': `View release notes for ${screenReaderVersion}`, | ||
title: 'View release', | ||
iconType: 'package', | ||
iconSize: 's', | ||
// @ts-ignore - this is valid | ||
href: `https://github.com/elastic/eui/releases/tag/v${version}`, | ||
target: '_blank', | ||
}} | ||
isActive={version === currentVersion} | ||
color={version === currentVersion ? 'primary' : 'text'} | ||
/> | ||
); | ||
}} | ||
</FixedSizeList> | ||
</EuiPopover> | ||
); | ||
}; |