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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * Dialog title.
  36. */
  37. title?: string;
  38. }
  39. /**
  40. * React Component for getting confirmation to stop a file recording session in
  41. * progress.
  42. *
  43. * @augments Component
  44. */
  45. class ConfirmDialog extends AbstractDialog<IProps> {
  46. /**
  47. * Default values for {@code ConfirmDialog} component's properties.
  48. *
  49. * @static
  50. */
  51. static defaultProps = {
  52. isConfirmDestructive: false
  53. };
  54. /**
  55. * Renders the dialog description.
  56. *
  57. * @returns {React$Component}
  58. */
  59. _renderDescription() {
  60. const { descriptionKey, t } = this.props;
  61. const description
  62. = typeof descriptionKey === 'string'
  63. ? t(descriptionKey)
  64. : renderHTML(
  65. t(descriptionKey?.key ?? '', descriptionKey?.params)
  66. );
  67. return (
  68. <Dialog.Description>
  69. { description }
  70. </Dialog.Description>
  71. );
  72. }
  73. /**
  74. * Implements {@code Component#render}.
  75. *
  76. * @inheritdoc
  77. */
  78. render() {
  79. const {
  80. cancelLabel,
  81. children,
  82. confirmLabel,
  83. isConfirmDestructive,
  84. t,
  85. title
  86. } = this.props;
  87. const dialogButtonStyle
  88. = isConfirmDestructive
  89. ? styles.destructiveDialogButton : styles.dialogButton;
  90. return (
  91. <Dialog.Container
  92. coverScreen = { false }
  93. visible = { true }>
  94. {
  95. title && <Dialog.Title>
  96. { t(title) }
  97. </Dialog.Title>
  98. }
  99. { this._renderDescription() }
  100. { children }
  101. <Dialog.Button
  102. label = { t(cancelLabel || 'dialog.confirmNo') }
  103. onPress = { this._onCancel }
  104. style = { styles.dialogButton } />
  105. <Dialog.Button
  106. label = { t(confirmLabel || 'dialog.confirmYes') }
  107. onPress = { this._onSubmit }
  108. style = { dialogButtonStyle } />
  109. </Dialog.Container>
  110. );
  111. }
  112. }
  113. export default translate(connect()(ConfirmDialog));