2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-02-17 06:14:10 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-01-26 03:52:17 +08:00
|
|
|
import styles from './styles.scss';
|
|
|
|
import cx from 'classnames';
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
|
|
|
|
const COLORS = [
|
|
|
|
'default', 'primary', 'danger', 'success',
|
|
|
|
];
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
color: PropTypes.oneOf(COLORS),
|
|
|
|
message: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
color: 'default',
|
|
|
|
};
|
|
|
|
|
2017-02-17 06:14:10 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
closeLabel: {
|
|
|
|
id: 'app.audioNotification.closeLabel',
|
2017-04-10 23:50:03 +08:00
|
|
|
description: 'Audio notification dismiss label',
|
2017-02-17 06:14:10 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
class AudioNotification extends Component {
|
2017-01-26 03:52:17 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleClose = this.handleClose.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClose() {
|
|
|
|
this.props.handleClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-02-17 06:14:10 +08:00
|
|
|
const {
|
|
|
|
color,
|
|
|
|
message,
|
|
|
|
intl,
|
|
|
|
} = this.props;
|
2017-01-26 03:52:17 +08:00
|
|
|
|
2017-03-25 00:38:49 +08:00
|
|
|
if (!color || !message) {
|
2017-01-26 03:52:17 +08:00
|
|
|
return null;
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role="alert"
|
|
|
|
className={cx(styles.audioNotifications, styles[this.props.color])}
|
|
|
|
>
|
|
|
|
{message}
|
|
|
|
<Button
|
|
|
|
className={styles.closeBtn}
|
|
|
|
label={intl.formatMessage(intlMessages.closeLabel)}
|
|
|
|
icon={'close'}
|
|
|
|
size={'sm'}
|
|
|
|
circle
|
|
|
|
hideLabel
|
|
|
|
onClick={this.handleClose}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2017-01-26 03:52:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioNotification.propTypes = propTypes;
|
|
|
|
AudioNotification.defaultProps = defaultProps;
|
2017-02-17 06:14:10 +08:00
|
|
|
|
|
|
|
export default injectIntl(AudioNotification);
|