2022-08-26 09:54:03 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2021-01-14 16:12:08 +00:00
|
|
|
/* eslint-disable react/no-multi-comp */
|
|
|
|
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
|
|
import WarningIcon from '@atlaskit/icon/glyph/warning';
|
|
|
|
import {
|
|
|
|
Header,
|
|
|
|
Title,
|
|
|
|
titleIconWrapperStyles,
|
|
|
|
TitleText
|
2022-08-26 09:54:03 +00:00
|
|
|
// @ts-ignore
|
2021-01-14 16:12:08 +00:00
|
|
|
} from '@atlaskit/modal-dialog/dist/es2019/styled/Content';
|
2021-10-08 08:05:16 +00:00
|
|
|
import { withStyles } from '@material-ui/core/styles';
|
2021-01-14 16:12:08 +00:00
|
|
|
import React from 'react';
|
2022-08-26 09:54:03 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2021-01-14 16:12:08 +00:00
|
|
|
|
2022-08-26 09:54:03 +00:00
|
|
|
import { translate } from '../../../i18n/functions';
|
2022-07-28 13:09:38 +00:00
|
|
|
import { IconClose } from '../../../icons/svg/index';
|
2022-08-26 09:54:03 +00:00
|
|
|
// @ts-ignore
|
2021-10-08 08:05:16 +00:00
|
|
|
import { withPixelLineHeight } from '../../../styles/functions';
|
2022-07-28 13:09:38 +00:00
|
|
|
import Button from '../../../ui/components/web/Button';
|
|
|
|
import { BUTTON_TYPES } from '../../../ui/constants';
|
2021-01-14 16:12:08 +00:00
|
|
|
|
|
|
|
const TitleIcon = ({ appearance }: { appearance?: 'danger' | 'warning' }) => {
|
|
|
|
if (!appearance) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IconSymbol = appearance === 'danger' ? ErrorIcon : WarningIcon;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span css = { titleIconWrapperStyles(appearance) }>
|
|
|
|
<IconSymbol label = { `${appearance} icon` } />
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-08-26 09:54:03 +00:00
|
|
|
interface Props extends WithTranslation {
|
2021-01-14 16:12:08 +00:00
|
|
|
appearance?: 'danger' | 'warning',
|
2022-08-26 09:54:03 +00:00
|
|
|
classes: any,
|
2021-01-14 16:12:08 +00:00
|
|
|
heading: string,
|
2021-05-26 16:15:35 +00:00
|
|
|
hideCloseIconButton: boolean,
|
2022-08-26 09:54:03 +00:00
|
|
|
id?: string,
|
2021-01-14 16:12:08 +00:00
|
|
|
isHeadingMultiline: boolean,
|
2022-08-26 09:54:03 +00:00
|
|
|
onClose: (e?: any) => void,
|
|
|
|
showKeyline: boolean,
|
|
|
|
testId?: string
|
2021-01-14 16:12:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 08:05:16 +00:00
|
|
|
/**
|
|
|
|
* Creates the styles for the component.
|
|
|
|
*
|
|
|
|
* @param {Object} theme - The current UI theme.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-08-26 09:54:03 +00:00
|
|
|
const styles = (theme: any) => {
|
2021-10-08 08:05:16 +00:00
|
|
|
return {
|
|
|
|
closeButton: {
|
|
|
|
borderRadius: theme.shape.borderRadius,
|
|
|
|
cursor: 'pointer',
|
|
|
|
padding: 13,
|
|
|
|
|
|
|
|
[theme.breakpoints.down('480')]: {
|
|
|
|
background: theme.palette.action02
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:hover': {
|
2022-07-12 12:28:20 +00:00
|
|
|
background: theme.palette.ui04
|
2021-10-08 08:05:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
boxShadow: 'none',
|
|
|
|
|
|
|
|
'& h4': {
|
|
|
|
...withPixelLineHeight(theme.typography.heading5),
|
|
|
|
color: theme.palette.text01
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-14 16:12:08 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* A default header for modal-dialog components.
|
2021-01-14 16:12:08 +00:00
|
|
|
*
|
|
|
|
* @class ModalHeader
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments {React.Component<Props>}
|
2021-01-14 16:12:08 +00:00
|
|
|
*/
|
2021-06-10 12:48:44 +00:00
|
|
|
class ModalHeader extends React.Component<Props> {
|
2021-01-14 16:12:08 +00:00
|
|
|
static defaultProps = {
|
|
|
|
isHeadingMultiline: true
|
|
|
|
};
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code ModalHeader} instance.
|
|
|
|
*
|
|
|
|
* @param {*} props - The read-only properties with which the new instance
|
|
|
|
* is to be initialized.
|
|
|
|
*/
|
2022-08-26 09:54:03 +00:00
|
|
|
constructor(props: Props) {
|
2021-06-10 12:48:44 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handler so it is only bound once for every instance.
|
|
|
|
this._onKeyPress = this._onKeyPress.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* KeyPress handler for accessibility.
|
|
|
|
*
|
|
|
|
* @param {Object} e - The key event to handle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-26 09:54:03 +00:00
|
|
|
_onKeyPress(e: React.KeyboardEvent) {
|
2021-06-10 12:48:44 +00:00
|
|
|
if (this.props.onClose && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 16:12:08 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
appearance,
|
2021-10-08 08:05:16 +00:00
|
|
|
classes,
|
2021-01-14 16:12:08 +00:00
|
|
|
heading,
|
2021-05-26 16:15:35 +00:00
|
|
|
hideCloseIconButton,
|
2021-01-14 16:12:08 +00:00
|
|
|
onClose,
|
|
|
|
showKeyline,
|
|
|
|
isHeadingMultiline,
|
2021-06-10 12:48:44 +00:00
|
|
|
testId,
|
|
|
|
t
|
2021-01-14 16:12:08 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!heading) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-10-08 08:05:16 +00:00
|
|
|
<Header
|
|
|
|
className = { classes.header }
|
|
|
|
showKeyline = { showKeyline }>
|
2021-01-14 16:12:08 +00:00
|
|
|
<Title>
|
|
|
|
<TitleIcon appearance = { appearance } />
|
|
|
|
<TitleText
|
|
|
|
data-testid = { testId && `${testId}-heading` }
|
|
|
|
id = { id }
|
|
|
|
isHeadingMultiline = { isHeadingMultiline }>
|
|
|
|
{heading}
|
|
|
|
</TitleText>
|
|
|
|
</Title>
|
2021-06-10 12:48:44 +00:00
|
|
|
|
2021-05-26 16:15:35 +00:00
|
|
|
{
|
2022-07-28 13:09:38 +00:00
|
|
|
!hideCloseIconButton && <Button
|
|
|
|
accessibilityLabel = { t('dialog.close') }
|
|
|
|
icon = { IconClose }
|
|
|
|
id = 'modal-header-close-button'
|
|
|
|
onClick = { onClose }
|
|
|
|
size = 'large'
|
|
|
|
type = { BUTTON_TYPES.TERTIARY } />
|
2021-05-26 16:15:35 +00:00
|
|
|
}
|
2021-01-14 16:12:08 +00:00
|
|
|
</Header>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-10-08 08:05:16 +00:00
|
|
|
export default translate(withStyles(styles)(ModalHeader));
|