2017-07-28 17:56:49 +00:00
|
|
|
import Flag from '@atlaskit/flag';
|
|
|
|
import EditorInfoIcon from '@atlaskit/icon/glyph/editor/info';
|
2017-09-27 21:23:31 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-07-28 17:56:49 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} to display a notification.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class Notification extends Component {
|
|
|
|
/**
|
|
|
|
* {@code Notification} component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* The translation key to display as the title of the notification if
|
|
|
|
* no title is provided.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
defaultTitleKey: PropTypes.string,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation arguments that may be necessary for the description.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
descriptionArguments: PropTypes.object,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation key to use as the body of the notification.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
descriptionKey: PropTypes.string,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the dismiss button should be displayed. This is passed
|
|
|
|
* in by {@code FlagGroup}.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
isDismissAllowed: PropTypes.bool,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when the user clicks to dismiss the notification.
|
|
|
|
* this is passed in by {@code FlagGroup}.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
onDismissed: PropTypes.func,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
t: PropTypes.func,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The text to display at the top of the notification. If not passed in,
|
|
|
|
* the passed in defaultTitleKey will be used.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
title: PropTypes.string,
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The unique identifier for the notification. Passed back by the
|
|
|
|
* {@code Flag} component in the onDismissed callback.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
uid: PropTypes.number
|
2017-07-28 17:56:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
defaultTitleKey,
|
|
|
|
descriptionArguments,
|
|
|
|
descriptionKey,
|
|
|
|
isDismissAllowed,
|
|
|
|
onDismissed,
|
|
|
|
t,
|
|
|
|
title,
|
|
|
|
uid
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Flag
|
|
|
|
appearance = 'normal'
|
|
|
|
description = { t(descriptionKey, descriptionArguments) }
|
|
|
|
icon = { (
|
|
|
|
<EditorInfoIcon
|
|
|
|
label = 'info'
|
|
|
|
size = 'medium' />
|
|
|
|
) }
|
|
|
|
id = { uid }
|
|
|
|
isDismissAllowed = { isDismissAllowed }
|
|
|
|
onDismissed = { onDismissed }
|
|
|
|
title = { title || t(defaultTitleKey) } />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(Notification);
|