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.

ConfirmDialog.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import React from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import Dialog from 'react-native-dialog';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../../i18n/functions';
  6. import { renderHTML } from '../functions.native';
  7. import AbstractDialog, { IProps as AbstractProps } from './AbstractDialog';
  8. import styles from './styles';
  9. /**
  10. * The type of the React {@code Component} props of
  11. * {@link ConfirmDialog}.
  12. */
  13. interface IProps extends AbstractProps, WithTranslation {
  14. /**
  15. * The i18n key of the text label for the cancel button.
  16. */
  17. cancelLabel?: string;
  18. /**
  19. * The React {@code Component} children.
  20. */
  21. children?: React.ReactNode;
  22. /**
  23. * The i18n key of the text label for the confirm button.
  24. */
  25. confirmLabel?: string;
  26. /**
  27. * Dialog description key for translations.
  28. */
  29. descriptionKey?: string | { key: string; params: string; };
  30. /**
  31. * Whether or not the nature of the confirm button is destructive.
  32. */
  33. isConfirmDestructive?: Boolean;
  34. /**
  35. * Whether or not the confirm button is hidden.
  36. */
  37. isConfirmHidden?: Boolean;
  38. /**
  39. * Dialog title.
  40. */
  41. title?: string;
  42. }
  43. /**
  44. * React Component for getting confirmation to stop a file recording session in
  45. * progress.
  46. *
  47. * @augments Component
  48. */
  49. class ConfirmDialog extends AbstractDialog<IProps> {
  50. /**
  51. * Default values for {@code ConfirmDialog} component's properties.
  52. *
  53. * @static
  54. */
  55. static defaultProps = {
  56. isConfirmDestructive: false,
  57. isConfirmHidden: false
  58. };
  59. /**
  60. * Renders the dialog description.
  61. *
  62. * @returns {React$Component}
  63. */
  64. _renderDescription() {
  65. const { descriptionKey, t } = this.props;
  66. const description
  67. = typeof descriptionKey === 'string'
  68. ? t(descriptionKey)
  69. : renderHTML(
  70. t(descriptionKey?.key ?? '', descriptionKey?.params)
  71. );
  72. return (
  73. <Dialog.Description>
  74. { description }
  75. </Dialog.Description>
  76. );
  77. }
  78. /**
  79. * Implements {@code Component#render}.
  80. *
  81. * @inheritdoc
  82. */
  83. render() {
  84. const {
  85. cancelLabel,
  86. children,
  87. confirmLabel,
  88. isConfirmDestructive,
  89. isConfirmHidden,
  90. t,
  91. title
  92. } = this.props;
  93. const dialogButtonStyle
  94. = isConfirmDestructive
  95. ? styles.destructiveDialogButton : styles.dialogButton;
  96. return (
  97. <Dialog.Container
  98. coverScreen = { false }
  99. visible = { true }>
  100. {
  101. title && <Dialog.Title>
  102. { t(title) }
  103. </Dialog.Title>
  104. }
  105. { this._renderDescription() }
  106. { children }
  107. <Dialog.Button
  108. label = { t(cancelLabel || 'dialog.confirmNo') }
  109. onPress = { this._onCancel }
  110. style = { styles.dialogButton } />
  111. {
  112. !isConfirmHidden && <Dialog.Button
  113. label = { t(confirmLabel || 'dialog.confirmYes') }
  114. onPress = { this._onSubmit }
  115. style = { dialogButtonStyle } />
  116. }
  117. </Dialog.Container>
  118. );
  119. }
  120. }
  121. export default translate(connect()(ConfirmDialog));