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.

ChatDialogHeader.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import React, { useCallback } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconClose } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import { toggleChat } from '../../actions.web';
  7. type Props = {
  8. /**
  9. * Function to be called when pressing the close button.
  10. */
  11. onCancel: Function,
  12. /**
  13. * An optional class name.
  14. */
  15. className: string,
  16. /**
  17. * Invoked to obtain translated strings.
  18. */
  19. t: Function
  20. };
  21. /**
  22. * Custom header of the {@code ChatDialog}.
  23. *
  24. * @returns {React$Element<any>}
  25. */
  26. function Header({ onCancel, className, t }: Props) {
  27. const onKeyPressHandler = useCallback(e => {
  28. if (onCancel && (e.key === ' ' || e.key === 'Enter')) {
  29. e.preventDefault();
  30. onCancel();
  31. }
  32. }, [ onCancel ]);
  33. return (
  34. <div
  35. className = { className || 'chat-dialog-header' }
  36. role = 'heading'>
  37. { t('chat.title') }
  38. <Icon
  39. ariaLabel = { t('toolbar.closeChat') }
  40. onClick = { onCancel }
  41. onKeyPress = { onKeyPressHandler }
  42. role = 'button'
  43. src = { IconClose }
  44. tabIndex = { 0 } />
  45. </div>
  46. );
  47. }
  48. const mapDispatchToProps = { onCancel: toggleChat };
  49. export default translate(connect(null, mapDispatchToProps)(Header));