Make version switcher more obvious

This commit is contained in:
Misode
2022-06-12 20:51:54 +02:00
parent 01a95dd9d4
commit f944f4b617
11 changed files with 85 additions and 32 deletions

View File

@@ -0,0 +1,31 @@
import { useMemo } from 'preact/hooks'
import config from '../../config.json'
import { useLocale } from '../contexts'
import type { VersionId } from '../services'
import { Store } from '../Store'
import { Btn } from './Btn'
import { BtnMenu } from './BtnMenu'
interface Props {
value?: VersionId,
allowed?: VersionId[],
hasAny?: boolean,
onChange: (version: VersionId) => void,
onAny?: () => void,
}
export function VersionSwitcher({ value, allowed, hasAny, onChange, onAny }: Props) {
const { locale } = useLocale()
const versions = useMemo(() => {
if (allowed) return allowed
return config.versions
.map(v => v.id as VersionId)
.reverse()
}, [allowed])
return <BtnMenu class={`version-switcher${Store.getVersion() === null ? ' attention' : ''}`} icon="tag" label={value ?? locale('any_version')} tooltip={locale('switch_version')}>
{hasAny && <Btn label={locale('any_version')} onClick={onAny} active={!value} />}
{versions.map((v: string) =>
<Btn label={v} active={v === value} onClick={() => onChange(v as VersionId)} />)}
</BtnMenu>
}