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

AbstractNotification.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { NOTIFICATION_TYPE } from '../constants';
  4. export interface IProps extends WithTranslation {
  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 type of button.
  24. */
  25. customActionType?: string[];
  26. /**
  27. * The text to display in the body of the notification. If not passed
  28. * in, the passed in descriptionKey will be used.
  29. */
  30. defaultTitleKey: string;
  31. /**
  32. * A description string that can be used in addition to the prop
  33. * descriptionKey.
  34. */
  35. description: string;
  36. /**
  37. * The translation arguments that may be necessary for the description.
  38. */
  39. descriptionArguments: Object;
  40. /**
  41. * The translation key to use as the body of the notification.
  42. */
  43. descriptionKey: string;
  44. /**
  45. * Whether the support link should be hidden in the case of an error
  46. * message.
  47. */
  48. hideErrorSupportLink: boolean;
  49. /**
  50. * The type of icon to be displayed. If not passed in, the appearance
  51. * type will be used.
  52. */
  53. icon?: string;
  54. /**
  55. * Maximum lines of the description.
  56. */
  57. maxLines?: number;
  58. /**
  59. * Callback invoked when the user clicks to dismiss the notification.
  60. */
  61. onDismissed: 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 extends IProps> 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. /**
  107. * Returns the description array to be displayed.
  108. *
  109. * @protected
  110. * @returns {Array<string>}
  111. */
  112. _getDescription() {
  113. const {
  114. description,
  115. descriptionArguments,
  116. descriptionKey,
  117. t
  118. } = this.props;
  119. const descriptionArray = [];
  120. descriptionKey
  121. && descriptionArray.push(t(descriptionKey, descriptionArguments));
  122. description && descriptionArray.push(description);
  123. return descriptionArray;
  124. }
  125. /**
  126. * Returns the description key that was used if any.
  127. *
  128. * @protected
  129. * @returns {string}
  130. */
  131. _getDescriptionKey() {
  132. return this.props.descriptionKey;
  133. }
  134. /**
  135. * Callback to dismiss the notification.
  136. *
  137. * @private
  138. * @returns {void}
  139. */
  140. _onDismissed() {
  141. this.props.onDismissed(this.props.uid);
  142. }
  143. }