您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DesktopSourcePreview.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { translate } from '../../base/i18n/functions';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link DesktopSourcePreview}.
  7. */
  8. interface IProps extends WithTranslation {
  9. /**
  10. * The callback to invoke when the component is clicked. The id of the
  11. * clicked on DesktopCapturerSource will be passed in.
  12. */
  13. onClick: Function;
  14. /**
  15. * The callback to invoke when the component is double clicked. The id of
  16. * the DesktopCapturerSource will be passed in.
  17. */
  18. onDoubleClick: Function;
  19. /**
  20. * The indicator which determines whether this DesktopSourcePreview is
  21. * selected. If true, the 'is-selected' CSS class will be added to the root
  22. * of Component.
  23. */
  24. selected: boolean;
  25. /**
  26. * The DesktopCapturerSource to display.
  27. */
  28. source: any;
  29. /**
  30. * The source type of the DesktopCapturerSources to display.
  31. */
  32. type: string;
  33. }
  34. /**
  35. * React component for displaying a preview of a DesktopCapturerSource.
  36. *
  37. * @augments Component
  38. */
  39. class DesktopSourcePreview extends Component<IProps> {
  40. /**
  41. * Initializes a new DesktopSourcePreview instance.
  42. *
  43. * @param {Object} props - The read-only properties with which the new
  44. * instance is to be initialized.
  45. */
  46. constructor(props: IProps) {
  47. super(props);
  48. this._onClick = this._onClick.bind(this);
  49. this._onDoubleClick = this._onDoubleClick.bind(this);
  50. }
  51. /**
  52. * Implements React's {@link Component#render()}.
  53. *
  54. * @inheritdoc
  55. * @returns {ReactElement}
  56. */
  57. render() {
  58. const selectedClass = this.props.selected ? 'is-selected' : '';
  59. const displayClasses = `desktop-picker-source ${selectedClass}`;
  60. return (
  61. <div
  62. className = { displayClasses }
  63. onClick = { this._onClick }
  64. onDoubleClick = { this._onDoubleClick }>
  65. <div className = 'desktop-source-preview-image-container'>
  66. <img
  67. alt = { this.props.t('welcomepage.logo.desktopPreviewThumbnail') }
  68. className = 'desktop-source-preview-thumbnail'
  69. src = { this.props.source.thumbnail.toDataURL() } />
  70. </div>
  71. <div className = 'desktop-source-preview-label'>
  72. { this.props.source.name }
  73. </div>
  74. </div>
  75. );
  76. }
  77. /**
  78. * Invokes the passed in onClick callback.
  79. *
  80. * @returns {void}
  81. */
  82. _onClick() {
  83. const { source, type } = this.props;
  84. this.props.onClick(source.id, type);
  85. }
  86. /**
  87. * Invokes the passed in onDoubleClick callback.
  88. *
  89. * @returns {void}
  90. */
  91. _onDoubleClick() {
  92. const { source, type } = this.props;
  93. this.props.onDoubleClick(source.id, type);
  94. }
  95. }
  96. export default translate(DesktopSourcePreview);