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.

ParticipantName.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. type Props = {
  5. /**
  6. * Flag signaling if the name is ediable or not.
  7. */
  8. isEditable: boolean,
  9. /**
  10. * Joins the current meeting.
  11. */
  12. joinConference: Function,
  13. /**
  14. * Sets the name for the joining user.
  15. */
  16. setName: Function,
  17. /**
  18. * Used to obtain translations.
  19. */
  20. t: Function,
  21. /**
  22. * The text to be displayed.
  23. */
  24. value: string,
  25. };
  26. /**
  27. * Participant name - can be an editable input or just the text name.
  28. *
  29. * @returns {ReactElement}
  30. */
  31. class ParticipantName extends Component<Props> {
  32. /**
  33. * Initializes a new {@code ParticipantName} instance.
  34. *
  35. * @param {Props} props - The props of the component.
  36. * @inheritdoc
  37. */
  38. constructor(props) {
  39. super(props);
  40. this._onKeyDown = this._onKeyDown.bind(this);
  41. this._onNameChange = this._onNameChange.bind(this);
  42. }
  43. _onKeyDown: () => void;
  44. /**
  45. * Joins the conference on 'Enter'.
  46. *
  47. * @param {Event} event - Key down event object.
  48. * @returns {void}
  49. */
  50. _onKeyDown(event) {
  51. if (event.key === 'Enter') {
  52. this.props.joinConference();
  53. }
  54. }
  55. _onNameChange: () => void;
  56. /**
  57. * Handler used for changing the guest user name.
  58. *
  59. * @returns {undefined}
  60. */
  61. _onNameChange({ target: { value } }) {
  62. this.props.setName(value);
  63. }
  64. /**
  65. * Implements React's {@link Component#render()}.
  66. *
  67. * @inheritdoc
  68. * @returns {ReactElement}
  69. */
  70. render() {
  71. const { value, isEditable, t } = this.props;
  72. const { _onKeyDown, _onNameChange } = this;
  73. return isEditable ? (
  74. <input
  75. autoFocus = { true }
  76. className = 'prejoin-preview-name prejoin-preview-name--editable'
  77. onChange = { _onNameChange }
  78. onKeyDown = { _onKeyDown }
  79. placeholder = { t('dialog.enterDisplayName') }
  80. value = { value } />
  81. )
  82. : <div
  83. className = 'prejoin-preview-name prejoin-preview-name--text'
  84. onKeyDown = { _onKeyDown }
  85. tabIndex = '0' >
  86. {value}
  87. </div>
  88. ;
  89. }
  90. }
  91. export default translate(ParticipantName);