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

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