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.

NotificationsContainer.web.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @flow
  2. import { FlagGroup } from '@atlaskit/flag';
  3. import React from 'react';
  4. import { connect } from 'react-redux';
  5. import AbstractNotificationsContainer, {
  6. _abstractMapStateToProps as _mapStateToProps,
  7. type Props
  8. } from './AbstractNotificationsContainer';
  9. import Notification from './Notification';
  10. /**
  11. * Implements a React {@link Component} which displays notifications and handles
  12. * automatic dismissmal after a notification is shown for a defined timeout
  13. * period.
  14. *
  15. * @extends {Component}
  16. */
  17. class NotificationsContainer extends AbstractNotificationsContainer<Props> {
  18. /**
  19. * Implements React's {@link Component#render()}.
  20. *
  21. * @inheritdoc
  22. * @returns {ReactElement}
  23. */
  24. render() {
  25. return (
  26. <FlagGroup onDismissed = { this._onDismissed }>
  27. { this._renderFlags() }
  28. </FlagGroup>
  29. );
  30. }
  31. _onDismissed: number => void;
  32. /**
  33. * Renders notifications to display as ReactElements. An empty array will
  34. * be returned if notifications are disabled.
  35. *
  36. * @private
  37. * @returns {ReactElement[]}
  38. */
  39. _renderFlags() {
  40. const { _notifications } = this.props;
  41. return _notifications.map(notification => {
  42. const { props, uid } = notification;
  43. // The id attribute is necessary as {@code FlagGroup} looks for
  44. // either id or key to set a key on notifications, but accessing
  45. // props.key will cause React to print an error.
  46. return (
  47. <Notification
  48. { ...props }
  49. id = { uid }
  50. key = { uid }
  51. uid = { uid } />
  52. );
  53. });
  54. }
  55. }
  56. export default connect(_mapStateToProps)(NotificationsContainer);