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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. text: {
  29. maxWidth: 'calc(100% - 30px)',
  30. overflow: 'hidden',
  31. whiteSpace: 'break-spaces',
  32. wordBreak: 'break-all'
  33. },
  34. iconButton: {
  35. padding: '2px',
  36. '&:hover': {
  37. backgroundColor: theme.palette.action03
  38. }
  39. }
  40. };
  41. });
  42. const MessageRecipient = ({
  43. _privateMessageRecipient,
  44. _isLobbyChatActive,
  45. _lobbyMessageRecipient,
  46. _onRemovePrivateMessageRecipient,
  47. _onHideLobbyChatRecipient,
  48. _visible
  49. }: IProps) => {
  50. const { classes } = useStyles();
  51. const { t } = useTranslation();
  52. const _onKeyPress = useCallback((e: React.KeyboardEvent) => {
  53. if (
  54. (_onRemovePrivateMessageRecipient || _onHideLobbyChatRecipient)
  55. && (e.key === ' ' || e.key === 'Enter')
  56. ) {
  57. e.preventDefault();
  58. if (_isLobbyChatActive && _onHideLobbyChatRecipient) {
  59. _onHideLobbyChatRecipient();
  60. } else if (_onRemovePrivateMessageRecipient) {
  61. _onRemovePrivateMessageRecipient();
  62. }
  63. }
  64. }, [ _onRemovePrivateMessageRecipient, _onHideLobbyChatRecipient, _isLobbyChatActive ]);
  65. if ((!_privateMessageRecipient && !_isLobbyChatActive) || !_visible) {
  66. return null;
  67. }
  68. return (
  69. <div
  70. className = { classes.container }
  71. id = 'chat-recipient'
  72. role = 'alert'>
  73. <span className = { classes.text }>
  74. {t(_isLobbyChatActive ? 'chat.lobbyChatMessageTo' : 'chat.messageTo', {
  75. recipient: _isLobbyChatActive ? _lobbyMessageRecipient : _privateMessageRecipient
  76. })}
  77. </span>
  78. <Button
  79. accessibilityLabel = { t('dialog.close') }
  80. className = { classes.iconButton }
  81. icon = { IconCloseLarge }
  82. onClick = { _isLobbyChatActive
  83. ? _onHideLobbyChatRecipient : _onRemovePrivateMessageRecipient }
  84. onKeyPress = { _onKeyPress }
  85. type = { BUTTON_TYPES.TERTIARY } />
  86. </div>
  87. );
  88. };
  89. export default connect(_mapStateToProps, _mapDispatchToProps)(MessageRecipient);