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

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