2021-01-12 13:24:55 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2021-01-12 13:24:55 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2021-01-12 13:24:55 +00:00
|
|
|
import { Icon, IconClose } from '../../../base/icons';
|
|
|
|
import { connect } from '../../../base/redux';
|
2021-02-24 12:26:00 +00:00
|
|
|
import { toggleChat } from '../../actions.web';
|
2021-01-12 13:24:55 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be called when pressing the close button.
|
|
|
|
*/
|
|
|
|
onCancel: Function,
|
|
|
|
|
2021-01-14 16:12:08 +00:00
|
|
|
/**
|
|
|
|
* An optional class name.
|
|
|
|
*/
|
|
|
|
className: string,
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2021-09-10 18:57:36 +00:00
|
|
|
/**
|
|
|
|
* Whether the polls feature is enabled or not.
|
|
|
|
*/
|
|
|
|
isPollsEnabled: boolean,
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
2021-01-12 13:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom header of the {@code ChatDialog}.
|
|
|
|
*
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
*/
|
2021-09-10 18:57:36 +00:00
|
|
|
function Header({ onCancel, className, isPollsEnabled, t }: Props) {
|
2021-06-10 12:48:44 +00:00
|
|
|
|
|
|
|
const onKeyPressHandler = useCallback(e => {
|
|
|
|
if (onCancel && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
e.preventDefault();
|
|
|
|
onCancel();
|
|
|
|
}
|
|
|
|
}, [ onCancel ]);
|
|
|
|
|
2021-01-12 13:24:55 +00:00
|
|
|
return (
|
|
|
|
<div
|
2021-06-10 12:48:44 +00:00
|
|
|
className = { className || 'chat-dialog-header' }
|
|
|
|
role = 'heading'>
|
2021-09-10 18:57:36 +00:00
|
|
|
{ t(isPollsEnabled ? 'chat.titleWithPolls' : 'chat.title') }
|
2021-01-12 13:24:55 +00:00
|
|
|
<Icon
|
2021-06-10 12:48:44 +00:00
|
|
|
ariaLabel = { t('toolbar.closeChat') }
|
2021-01-12 13:24:55 +00:00
|
|
|
onClick = { onCancel }
|
2021-06-10 12:48:44 +00:00
|
|
|
onKeyPress = { onKeyPressHandler }
|
|
|
|
role = 'button'
|
|
|
|
src = { IconClose }
|
|
|
|
tabIndex = { 0 } />
|
2021-01-12 13:24:55 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-24 12:26:00 +00:00
|
|
|
const mapDispatchToProps = { onCancel: toggleChat };
|
2021-01-12 13:24:55 +00:00
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
export default translate(connect(null, mapDispatchToProps)(Header));
|