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 2.8KB

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