Coreectly setting current version for a doc page in version picker
This commit is contained in:
committed by
fabioberger
parent
2cbdd76aa3
commit
1985fec892
@@ -13,33 +13,38 @@ interface IVersionPickerProps extends RouteComponentProps<IMatchParams> {
|
||||
interface IMatchParams {
|
||||
page?: string;
|
||||
type?: string;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
const VersionSelect: React.FC<IVersionPickerProps> = ({ history, location, match, versions }) => {
|
||||
const { page, type, version: versionParam } = match.params;
|
||||
|
||||
const onChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
const { type, page } = match.params;
|
||||
const version = e.target.value;
|
||||
const url = `/docs/${type}/${page}/${version}`;
|
||||
history.push(url);
|
||||
window.scrollTo(0, 0);
|
||||
};
|
||||
|
||||
const getNumericVersion = (version: string) => version.replace(/^v/, '');
|
||||
|
||||
return (
|
||||
<VersionPickerWrapper>
|
||||
<Paragraph color="#999" size={17} lineHeight={1.6} marginBottom="0">
|
||||
Version
|
||||
</Paragraph>
|
||||
<Container>
|
||||
<StyledSelect onChange={onChange}>
|
||||
{versions.map((version: string) => {
|
||||
const numericVersion = version.replace(/^v/, '');
|
||||
|
||||
return (
|
||||
<option key={version} value={version}>
|
||||
{numericVersion}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
<StyledSelect defaultValue={versionParam} onChange={onChange}>
|
||||
{versionParam && (
|
||||
<option hidden={true} value="">
|
||||
{getNumericVersion(versionParam)}
|
||||
</option>
|
||||
)}
|
||||
{versions.map((version: string) => (
|
||||
<option key={version} value={version}>
|
||||
{getNumericVersion(version)}
|
||||
</option>
|
||||
))}
|
||||
</StyledSelect>
|
||||
<svg width="12" height="8" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M1 7l5-5 5 5" stroke={colors.brandDark} strokeWidth="1.5" />
|
||||
|
||||
Reference in New Issue
Block a user