Skip to content

Commit

Permalink
fix: restyle OffLineLangSwitch
Browse files Browse the repository at this point in the history
refs: POLIO-1784:
  • Loading branch information
quang-le authored Dec 6, 2024
2 parents f80b6a1 + c850593 commit 5792b34
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions hat/assets/js/apps/Iaso/domains/home/components/LangSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box } from '@mui/material';
import { Box, Button } from '@mui/material';
import { makeStyles } from '@mui/styles';
import classNames from 'classnames';
import React, { FunctionComponent, useCallback } from 'react';
Expand All @@ -17,6 +17,14 @@ const useStyles = makeStyles(theme => ({
languageSwitchActive: {
color: theme.palette.primary.main,
},
languageSwitchButton: {
backgroundColor: theme.palette.success.main,
color: 'white',
borderRadius: 0,
textTransform: 'none',
paddingLeft: theme.spacing(3),
paddingRight: theme.spacing(3),
},
}));

export const LangSwitch: FunctionComponent = () => {
Expand Down Expand Up @@ -56,9 +64,15 @@ export const LangSwitch: FunctionComponent = () => {
</>
);
};

// We don't need to translate as we show "English" in english etc
const localeMap = {
fr: 'Français',
en: 'English',
};

export const OffLineLangSwitch: FunctionComponent = () => {
const classes: Record<string, string> = useStyles();
const { locale: activeLocale } = useLocale();
const { setLocale } = useLocale();
const handleClick = useCallback(
localeCode => {
Expand All @@ -68,21 +82,18 @@ export const OffLineLangSwitch: FunctionComponent = () => {
);
return (
<>
{APP_LOCALES.map((locale, index) => (
<Box key={locale.code}>
<Box
className={classNames(
classes.languageSwitch,
locale.code === activeLocale &&
classes.languageSwitchActive,
)}
onClick={() => handleClick(locale.code)}
>
{locale.code}
{APP_LOCALES.map((locale, index) => {
return (
<Box key={locale.code} ml={index === 1 ? 2 : undefined}>
<Button
onClick={() => handleClick(locale.code)}
className={classes.languageSwitchButton}
>
{localeMap[locale.code]}
</Button>
</Box>
{index + 1 !== APP_LOCALES.length && '-'}
</Box>
))}
);
})}
</>
);
};

0 comments on commit 5792b34

Please sign in to comment.