-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40d39bd
commit 9aee902
Showing
9 changed files
with
106 additions
and
207 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
101 changes: 101 additions & 0 deletions
101
frontend/src/features/public-form/components/LanguageControl/LanguageControl.tsx
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,101 @@ | ||
import { BiChevronDown } from 'react-icons/bi' | ||
import { | ||
Box, | ||
Button, | ||
Flex, | ||
HStack, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
MenuList, | ||
Text, | ||
} from '@chakra-ui/react' | ||
|
||
import { Language } from '~shared/types' | ||
|
||
import { usePublicFormContext } from '~features/public-form/PublicFormContext' | ||
|
||
import { useBgColor } from '../PublicFormWrapper' | ||
|
||
type LanguageListType = { | ||
language: Language | ||
title: string | ||
} | ||
|
||
const LANGUAGES: LanguageListType[] = [ | ||
{ language: Language.ENGLISH, title: 'English' }, | ||
{ language: Language.CHINESE, title: '中文' }, | ||
{ language: Language.MALAY, title: 'Melayu' }, | ||
{ language: Language.TAMIL, title: 'தமிழ்' }, | ||
] | ||
|
||
export const LanguageControl = (): JSX.Element => { | ||
const { form, publicFormLanguage, setPublicFormLanguage } = | ||
usePublicFormContext() | ||
|
||
const availableLanguages = new Set(form?.supportedLanguages ?? []) | ||
|
||
const languagesList = LANGUAGES.filter((language) => | ||
availableLanguages.has(language.language), | ||
) | ||
|
||
// English language is always supported. Hence if form supports multi-lang | ||
// and there is more than one supported language available, show the | ||
// language dropdown. | ||
const shouldShowLanguageDropdown = | ||
form?.hasMultiLang && availableLanguages.size > 1 | ||
|
||
const bgColour = useBgColor({ | ||
colorTheme: form?.startPage.colorTheme, | ||
}) | ||
|
||
const handleLanguageChange = (language: string) => { | ||
if (setPublicFormLanguage) { | ||
setPublicFormLanguage(language as Language) | ||
} | ||
} | ||
|
||
const selectedLanguage = LANGUAGES.find( | ||
(language) => language.language === publicFormLanguage, | ||
)?.title | ||
|
||
return ( | ||
<Flex | ||
background={bgColour} | ||
zIndex={10} | ||
px={{ base: '1.5rem', md: 0 }} | ||
justifyContent={{ base: 'start', md: 'center' }} | ||
> | ||
<HStack mt="-32px" bg="white" borderRadius="4px" shadow="md"> | ||
{shouldShowLanguageDropdown && ( | ||
<Menu variant="clear"> | ||
<MenuButton | ||
as={Button} | ||
rightIcon={<BiChevronDown />} | ||
variant="clear" | ||
color="secondary.500" | ||
> | ||
{selectedLanguage} | ||
</MenuButton> | ||
<MenuList> | ||
{languagesList.map((language) => { | ||
return ( | ||
<MenuItem | ||
onClick={() => { | ||
handleLanguageChange(language.language) | ||
}} | ||
px={4} | ||
h={12} | ||
w="140px" | ||
> | ||
{language.title} | ||
</MenuItem> | ||
) | ||
})} | ||
</MenuList> | ||
</Menu> | ||
)} | ||
</HStack> | ||
</Flex> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/features/public-form/components/LanguageControl/index.ts
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 @@ | ||
export { LanguageControl as default } from './LanguageControl' |
145 changes: 0 additions & 145 deletions
145
frontend/src/features/public-form/components/ZoomControl/ZoomControl.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
frontend/src/features/public-form/components/ZoomControl/index.ts
This file was deleted.
Oops, something went wrong.