2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2022-08-31 15:57:31 +00:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-09-13 07:36:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2022-08-31 15:57:31 +00:00
|
|
|
|
2022-09-06 17:32:20 +00:00
|
|
|
import { translate } from '../../base/i18n/functions';
|
|
|
|
import Icon from '../../base/icons/components/Icon';
|
|
|
|
import { IconCheck } from '../../base/icons/svg';
|
2022-08-31 15:57:31 +00:00
|
|
|
|
|
|
|
interface ILanguageListItemProps extends WithTranslation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the button should be full width.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
lang: string;
|
2022-08-31 15:57:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Click callback.
|
|
|
|
*/
|
|
|
|
onLanguageSelected: (lang: string) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the button.
|
|
|
|
*/
|
|
|
|
selected?: boolean;
|
|
|
|
}
|
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2022-08-31 15:57:31 +00:00
|
|
|
return {
|
|
|
|
itemContainer: {
|
|
|
|
display: 'flex',
|
|
|
|
color: theme.palette.text01,
|
|
|
|
alignItems: 'center',
|
2022-09-29 11:44:59 +00:00
|
|
|
fontSize: '14px',
|
|
|
|
cursor: 'pointer',
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.ui04
|
|
|
|
}
|
2022-08-31 15:57:31 +00:00
|
|
|
},
|
|
|
|
iconWrapper: {
|
|
|
|
margin: '4px 10px',
|
|
|
|
width: '22px',
|
|
|
|
height: '22px'
|
|
|
|
},
|
|
|
|
activeItemContainer: {
|
|
|
|
fontWeight: 700
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component that renders the language list item.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const LanguageListItem = ({
|
|
|
|
t,
|
|
|
|
lang,
|
|
|
|
selected,
|
|
|
|
onLanguageSelected
|
|
|
|
}: ILanguageListItemProps) => {
|
2022-09-13 07:36:00 +00:00
|
|
|
const { classes: styles } = useStyles();
|
2022-08-31 15:57:31 +00:00
|
|
|
const onLanguageSelectedWrapper = useCallback(() => onLanguageSelected(lang), [ lang ]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = { `${styles.itemContainer} ${selected ? styles.activeItemContainer : ''}` }
|
|
|
|
onClick = { onLanguageSelectedWrapper }>
|
|
|
|
<span className = { styles.iconWrapper }>{ selected
|
|
|
|
&& <Icon src = { IconCheck } /> }</span>
|
|
|
|
{ t(lang) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default translate(LanguageListItem);
|