You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LanguageListItem.tsx 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Theme } from '@mui/material';
  2. import React, { useCallback } from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { translate } from '../../base/i18n/functions';
  6. import Icon from '../../base/icons/components/Icon';
  7. import { IconCheck } from '../../base/icons/svg';
  8. interface ILanguageListItemProps extends WithTranslation {
  9. /**
  10. * Whether or not the button should be full width.
  11. */
  12. lang: string;
  13. /**
  14. * Click callback.
  15. */
  16. onLanguageSelected: (lang: string) => void;
  17. /**
  18. * The id of the button.
  19. */
  20. selected?: boolean;
  21. }
  22. const useStyles = makeStyles()((theme: Theme) => {
  23. return {
  24. itemContainer: {
  25. display: 'flex',
  26. color: theme.palette.text01,
  27. alignItems: 'center',
  28. fontSize: '14px',
  29. cursor: 'pointer',
  30. '&:hover': {
  31. backgroundColor: theme.palette.ui04
  32. }
  33. },
  34. iconWrapper: {
  35. margin: '4px 10px',
  36. width: '22px',
  37. height: '22px'
  38. },
  39. activeItemContainer: {
  40. fontWeight: 700
  41. }
  42. };
  43. });
  44. /**
  45. * Component that renders the language list item.
  46. *
  47. * @returns {React$Element<any>}
  48. */
  49. const LanguageListItem = ({
  50. t,
  51. lang,
  52. selected,
  53. onLanguageSelected
  54. }: ILanguageListItemProps) => {
  55. const { classes: styles } = useStyles();
  56. const onLanguageSelectedWrapper = useCallback(() => onLanguageSelected(lang), [ lang ]);
  57. return (
  58. <div
  59. className = { `${styles.itemContainer} ${selected ? styles.activeItemContainer : ''}` }
  60. onClick = { onLanguageSelectedWrapper }>
  61. <span className = { styles.iconWrapper }>{ selected
  62. && <Icon src = { IconCheck } /> }</span>
  63. { t(lang) }
  64. </div>
  65. );
  66. };
  67. export default translate(LanguageListItem);