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.

MessageRecipient.tsx 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IconCloseLarge } from '../../../base/icons/svg';
  6. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  7. import Button from '../../../base/ui/components/web/Button';
  8. import { BUTTON_TYPES } from '../../../base/ui/constants.any';
  9. import {
  10. IProps,
  11. _mapDispatchToProps,
  12. _mapStateToProps
  13. } from '../AbstractMessageRecipient';
  14. const useStyles = makeStyles()(theme => {
  15. return {
  16. container: {
  17. margin: '0 16px 8px',
  18. padding: '6px',
  19. paddingLeft: '16px',
  20. display: 'flex',
  21. justifyContent: 'space-between',
  22. alignItems: 'center',
  23. backgroundColor: theme.palette.support05,
  24. borderRadius: theme.shape.borderRadius,
  25. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  26. color: theme.palette.text01
  27. },
  28. iconButton: {
  29. padding: '2px',
  30. '&:hover': {
  31. backgroundColor: theme.palette.action03
  32. }
  33. }
  34. };
  35. });
  36. const MessageRecipient = ({
  37. _privateMessageRecipient,
  38. _isLobbyChatActive,
  39. _lobbyMessageRecipient,
  40. _onRemovePrivateMessageRecipient,
  41. _onHideLobbyChatRecipient,
  42. _visible
  43. }: IProps) => {
  44. const { classes } = useStyles();
  45. const { t } = useTranslation();
  46. const _onKeyPress = useCallback((e: React.KeyboardEvent) => {
  47. if (
  48. (_onRemovePrivateMessageRecipient || _onHideLobbyChatRecipient)
  49. && (e.key === ' ' || e.key === 'Enter')
  50. ) {
  51. e.preventDefault();
  52. if (_isLobbyChatActive && _onHideLobbyChatRecipient) {
  53. _onHideLobbyChatRecipient();
  54. } else if (_onRemovePrivateMessageRecipient) {
  55. _onRemovePrivateMessageRecipient();
  56. }
  57. }
  58. }, [ _onRemovePrivateMessageRecipient, _onHideLobbyChatRecipient, _isLobbyChatActive ]);
  59. if ((!_privateMessageRecipient && !_isLobbyChatActive) || !_visible) {
  60. return null;
  61. }
  62. return (
  63. <div
  64. className = { classes.container }
  65. id = 'chat-recipient'
  66. role = 'alert'>
  67. <span>
  68. {t(_isLobbyChatActive ? 'chat.lobbyChatMessageTo' : 'chat.messageTo', {
  69. recipient: _isLobbyChatActive ? _lobbyMessageRecipient : _privateMessageRecipient
  70. })}
  71. </span>
  72. <Button
  73. accessibilityLabel = { t('dialog.close') }
  74. className = { classes.iconButton }
  75. icon = { IconCloseLarge }
  76. onClick = { _isLobbyChatActive
  77. ? _onHideLobbyChatRecipient : _onRemovePrivateMessageRecipient }
  78. onKeyPress = { _onKeyPress }
  79. type = { BUTTON_TYPES.TERTIARY } />
  80. </div>
  81. );
  82. };
  83. export default connect(_mapStateToProps, _mapDispatchToProps)(MessageRecipient);