Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AbstractNotification.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // @flow
  2. import { Component } from 'react';
  3. import { NOTIFICATION_TYPE } from '../constants';
  4. export type Props = {
  5. /**
  6. * Display appearance for the component, passed directly to the
  7. * notification.
  8. */
  9. appearance: string,
  10. /**
  11. * Whether or not the title and description should be concatenated.
  12. */
  13. concatText?: boolean,
  14. /**
  15. * Callback invoked when the custom button is clicked.
  16. */
  17. customActionHandler: Function[],
  18. /**
  19. * The text to display as button in the notification for the custom action.
  20. */
  21. customActionNameKey: string[],
  22. /**
  23. * The text to display in the body of the notification. If not passed
  24. * in, the passed in descriptionKey will be used.
  25. */
  26. defaultTitleKey: string,
  27. /**
  28. * A description string that can be used in addition to the prop
  29. * descriptionKey.
  30. */
  31. description: string,
  32. /**
  33. * The translation arguments that may be necessary for the description.
  34. */
  35. descriptionArguments: Object,
  36. /**
  37. * The translation key to use as the body of the notification.
  38. */
  39. descriptionKey: string,
  40. /**
  41. * Whether the support link should be hidden in the case of an error
  42. * message.
  43. */
  44. hideErrorSupportLink: boolean,
  45. /**
  46. * The type of icon to be displayed. If not passed in, the appearance
  47. * type will be used.
  48. */
  49. icon?: String,
  50. /**
  51. * Maximum lines of the description.
  52. */
  53. maxLines: ?number,
  54. /**
  55. * Callback invoked when the user clicks to dismiss the notification.
  56. */
  57. onDismissed: Function,
  58. /**
  59. * Invoked to obtain translated strings.
  60. */
  61. t: Function,
  62. /**
  63. * The text to display at the top of the notification. If not passed in,
  64. * the passed in titleKey will be used.
  65. */
  66. title: string,
  67. /**
  68. * The translation arguments that may be necessary for the title.
  69. */
  70. titleArguments: Object,
  71. /**
  72. * The translation key to display as the title of the notification if
  73. * no title is provided.
  74. */
  75. titleKey: string,
  76. /**
  77. * The unique identifier for the notification.
  78. */
  79. uid: string
  80. };
  81. /**
  82. * Abstract class for {@code Notification} component.
  83. *
  84. * @augments Component
  85. */
  86. export default class AbstractNotification<P: Props> extends Component<P> {
  87. /**
  88. * Default values for {@code Notification} component's properties.
  89. *
  90. * @static
  91. */
  92. static defaultProps = {
  93. appearance: NOTIFICATION_TYPE.NORMAL
  94. };
  95. /**
  96. * Initializes a new {@code Notification} instance.
  97. *
  98. * @param {Object} props - The read-only properties with which the new
  99. * instance is to be initialized.
  100. */
  101. constructor(props: P) {
  102. super(props);
  103. // Bind event handler so it is only bound once for every instance.
  104. this._onDismissed = this._onDismissed.bind(this);
  105. }
  106. _getDescription: () => Array<string>;
  107. /**
  108. * Returns the description array to be displayed.
  109. *
  110. * @protected
  111. * @returns {Array<string>}
  112. */
  113. _getDescription() {
  114. const {
  115. description,
  116. descriptionArguments,
  117. descriptionKey,
  118. t
  119. } = this.props;
  120. const descriptionArray = [];
  121. descriptionKey
  122. && descriptionArray.push(t(descriptionKey, descriptionArguments));
  123. description && descriptionArray.push(description);
  124. return descriptionArray;
  125. }
  126. _getDescriptionKey: () => string;
  127. /**
  128. * Returns the description key that was used if any.
  129. *
  130. * @protected
  131. * @returns {string}
  132. */
  133. _getDescriptionKey() {
  134. return this.props.descriptionKey;
  135. }
  136. _onDismissed: () => void;
  137. /**
  138. * Callback to dismiss the notification.
  139. *
  140. * @private
  141. * @returns {void}
  142. */
  143. _onDismissed() {
  144. this.props.onDismissed(this.props.uid);
  145. }
  146. }