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.

ChatHeader.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch } from 'react-redux';
  4. import Icon from '../../../base/icons/components/Icon';
  5. import { IconCloseLarge } from '../../../base/icons/svg';
  6. import { toggleChat } from '../../actions.web';
  7. interface IProps {
  8. /**
  9. * An optional class name.
  10. */
  11. className: string;
  12. /**
  13. * Whether the polls feature is enabled or not.
  14. */
  15. isPollsEnabled: boolean;
  16. /**
  17. * Function to be called when pressing the close button.
  18. */
  19. onCancel: Function;
  20. }
  21. /**
  22. * Custom header of the {@code ChatDialog}.
  23. *
  24. * @returns {React$Element<any>}
  25. */
  26. function ChatHeader({ className, isPollsEnabled }: IProps) {
  27. const dispatch = useDispatch();
  28. const { t } = useTranslation();
  29. const onCancel = useCallback(() => {
  30. dispatch(toggleChat());
  31. }, []);
  32. const onKeyPressHandler = useCallback(e => {
  33. if (onCancel && (e.key === ' ' || e.key === 'Enter')) {
  34. e.preventDefault();
  35. onCancel();
  36. }
  37. }, []);
  38. return (
  39. <div
  40. className = { className || 'chat-dialog-header' }>
  41. <span
  42. aria-level = { 1 }
  43. role = 'heading'>
  44. { t(isPollsEnabled ? 'chat.titleWithPolls' : 'chat.title') }
  45. </span>
  46. <Icon
  47. ariaLabel = { t('toolbar.closeChat') }
  48. onClick = { onCancel }
  49. onKeyPress = { onKeyPressHandler }
  50. role = 'button'
  51. src = { IconCloseLarge }
  52. tabIndex = { 0 } />
  53. </div>
  54. );
  55. }
  56. export default ChatHeader;