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.

DesktopSourcePreview.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { translate } from '../../base/i18n';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link DesktopSourcePreview}.
  7. */
  8. type Props = {
  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: Object,
  29. /**
  30. * The source type of the DesktopCapturerSources to display.
  31. */
  32. type: string,
  33. /**
  34. * Invoked to obtain translated strings.
  35. */
  36. t: Function
  37. };
  38. /**
  39. * React component for displaying a preview of a DesktopCapturerSource.
  40. *
  41. * @extends Component
  42. */
  43. class DesktopSourcePreview extends Component<Props> {
  44. /**
  45. * Initializes a new DesktopSourcePreview instance.
  46. *
  47. * @param {Object} props - The read-only properties with which the new
  48. * instance is to be initialized.
  49. */
  50. constructor(props: Props) {
  51. super(props);
  52. this._onClick = this._onClick.bind(this);
  53. this._onDoubleClick = this._onDoubleClick.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. const selectedClass = this.props.selected ? 'is-selected' : '';
  63. const displayClasses = `desktop-picker-source ${selectedClass}`;
  64. return (
  65. <div
  66. className = { displayClasses }
  67. onClick = { this._onClick }
  68. onDoubleClick = { this._onDoubleClick }>
  69. <div className = 'desktop-source-preview-image-container'>
  70. <img
  71. alt = { this.props.t('welcomepage.logo.desktopPreviewThumbnail') }
  72. className = 'desktop-source-preview-thumbnail'
  73. src = { this.props.source.thumbnail.toDataURL() } />
  74. </div>
  75. <div className = 'desktop-source-preview-label'>
  76. { this.props.source.name }
  77. </div>
  78. </div>
  79. );
  80. }
  81. _onClick: () => void;
  82. /**
  83. * Invokes the passed in onClick callback.
  84. *
  85. * @returns {void}
  86. */
  87. _onClick() {
  88. const { source, type } = this.props;
  89. this.props.onClick(source.id, type);
  90. }
  91. _onDoubleClick: () => void;
  92. /**
  93. * Invokes the passed in onDoubleClick callback.
  94. *
  95. * @returns {void}
  96. */
  97. _onDoubleClick() {
  98. const { source, type } = this.props;
  99. this.props.onDoubleClick(source.id, type);
  100. }
  101. }
  102. export default translate(DesktopSourcePreview);