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.

Notification.web.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import Flag from '@atlaskit/flag';
  2. import EditorInfoIcon from '@atlaskit/icon/glyph/editor/info';
  3. import React, { Component } from 'react';
  4. import { translate } from '../../base/i18n';
  5. /**
  6. * Implements a React {@link Component} to display a notification.
  7. *
  8. * @extends Component
  9. */
  10. class Notification extends Component {
  11. /**
  12. * {@code Notification} component's property types.
  13. *
  14. * @static
  15. */
  16. static propTypes = {
  17. /**
  18. * The translation key to display as the title of the notification if
  19. * no title is provided.
  20. */
  21. defaultTitleKey: React.PropTypes.string,
  22. /**
  23. * The translation arguments that may be necessary for the description.
  24. */
  25. descriptionArguments: React.PropTypes.object,
  26. /**
  27. * The translation key to use as the body of the notification.
  28. */
  29. descriptionKey: React.PropTypes.string,
  30. /**
  31. * Whether or not the dismiss button should be displayed. This is passed
  32. * in by {@code FlagGroup}.
  33. */
  34. isDismissAllowed: React.PropTypes.bool,
  35. /**
  36. * Callback invoked when the user clicks to dismiss the notification.
  37. * this is passed in by {@code FlagGroup}.
  38. */
  39. onDismissed: React.PropTypes.func,
  40. /**
  41. * Invoked to obtain translated strings.
  42. */
  43. t: React.PropTypes.func,
  44. /**
  45. * The text to display at the top of the notification. If not passed in,
  46. * the passed in defaultTitleKey will be used.
  47. */
  48. title: React.PropTypes.string,
  49. /**
  50. * The unique identifier for the notification. Passed back by the
  51. * {@code Flag} component in the onDismissed callback.
  52. */
  53. uid: React.PropTypes.number
  54. };
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. const {
  63. defaultTitleKey,
  64. descriptionArguments,
  65. descriptionKey,
  66. isDismissAllowed,
  67. onDismissed,
  68. t,
  69. title,
  70. uid
  71. } = this.props;
  72. return (
  73. <Flag
  74. appearance = 'normal'
  75. description = { t(descriptionKey, descriptionArguments) }
  76. icon = { (
  77. <EditorInfoIcon
  78. label = 'info'
  79. size = 'medium' />
  80. ) }
  81. id = { uid }
  82. isDismissAllowed = { isDismissAllowed }
  83. onDismissed = { onDismissed }
  84. title = { title || t(defaultTitleKey) } />
  85. );
  86. }
  87. }
  88. export default translate(Notification);