mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): use chakra menu for language picker
This commit is contained in:
parent
4d6eea7e81
commit
7d582553f2
@ -1,15 +1,19 @@
|
|||||||
import type { ReactNode } from 'react';
|
import {
|
||||||
|
Menu,
|
||||||
import { VStack } from '@chakra-ui/react';
|
MenuButton,
|
||||||
import IAIButton from 'common/components/IAIButton';
|
MenuItemOption,
|
||||||
|
MenuList,
|
||||||
|
MenuOptionGroup,
|
||||||
|
Tooltip,
|
||||||
|
} from '@chakra-ui/react';
|
||||||
import IAIIconButton from 'common/components/IAIIconButton';
|
import IAIIconButton from 'common/components/IAIIconButton';
|
||||||
import IAIPopover from 'common/components/IAIPopover';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FaCheck, FaLanguage } from 'react-icons/fa';
|
import { FaLanguage } from 'react-icons/fa';
|
||||||
import i18n from 'i18n';
|
import i18n from 'i18n';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { languageSelector } from '../store/systemSelectors';
|
import { languageSelector } from '../store/systemSelectors';
|
||||||
import { languageChanged } from '../store/systemSlice';
|
import { languageChanged } from '../store/systemSlice';
|
||||||
|
import { map } from 'lodash-es';
|
||||||
|
|
||||||
export const LANGUAGES = {
|
export const LANGUAGES = {
|
||||||
ar: i18n.t('common.langArabic', { lng: 'ar' }),
|
ar: i18n.t('common.langArabic', { lng: 'ar' }),
|
||||||
@ -35,43 +39,29 @@ export default function LanguagePicker() {
|
|||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const language = useAppSelector(languageSelector);
|
const language = useAppSelector(languageSelector);
|
||||||
|
|
||||||
const renderLanguagePicker = () => {
|
|
||||||
const languagesToRender: ReactNode[] = [];
|
|
||||||
Object.keys(LANGUAGES).forEach((lang) => {
|
|
||||||
const l = lang as keyof typeof LANGUAGES;
|
|
||||||
languagesToRender.push(
|
|
||||||
<IAIButton
|
|
||||||
key={lang}
|
|
||||||
isChecked={language === l}
|
|
||||||
leftIcon={language === l ? <FaCheck /> : undefined}
|
|
||||||
onClick={() => dispatch(languageChanged(l))}
|
|
||||||
aria-label={LANGUAGES[l]}
|
|
||||||
size="sm"
|
|
||||||
minWidth="200px"
|
|
||||||
>
|
|
||||||
{LANGUAGES[l]}
|
|
||||||
</IAIButton>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return languagesToRender;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IAIPopover
|
<Tooltip title={t('common.languagePickerLabel')}>
|
||||||
triggerComponent={
|
<Menu closeOnSelect={false}>
|
||||||
<IAIIconButton
|
<MenuButton
|
||||||
aria-label={t('common.languagePickerLabel')}
|
as={IAIIconButton}
|
||||||
tooltip={t('common.languagePickerLabel')}
|
|
||||||
icon={<FaLanguage />}
|
icon={<FaLanguage />}
|
||||||
size="sm"
|
|
||||||
variant="link"
|
variant="link"
|
||||||
data-variant="link"
|
aria-label={t('common.languagePickerLabel')}
|
||||||
fontSize={26}
|
|
||||||
/>
|
/>
|
||||||
}
|
<MenuList>
|
||||||
>
|
<MenuOptionGroup value={language}>
|
||||||
<VStack>{renderLanguagePicker()}</VStack>
|
{map(LANGUAGES, (languageName, l: keyof typeof LANGUAGES) => (
|
||||||
</IAIPopover>
|
<MenuItemOption
|
||||||
|
key={l}
|
||||||
|
value={l}
|
||||||
|
onClick={() => dispatch(languageChanged(l))}
|
||||||
|
>
|
||||||
|
{languageName}
|
||||||
|
</MenuItemOption>
|
||||||
|
))}
|
||||||
|
</MenuOptionGroup>
|
||||||
|
</MenuList>
|
||||||
|
</Menu>
|
||||||
|
</Tooltip>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user