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

DesktopSourcePreview.js 2.6KB

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