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

VolumeSlider.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. /**
  4. * Used to modify initialValue, which is expected to be a decimal value between
  5. * 0 and 1, and converts it to a number representable by an input slider, which
  6. * recognizes whole numbers.
  7. */
  8. const VOLUME_SLIDER_SCALE = 100;
  9. /**
  10. * The type of the React {@code Component} props of {@link VolumeSlider}.
  11. */
  12. type Props = {
  13. /**
  14. * The value of the audio slider should display at when the component first
  15. * mounts. Changes will be stored in state. The value should be a number
  16. * between 0 and 1.
  17. */
  18. initialValue: number,
  19. /**
  20. * The callback to invoke when the audio slider value changes.
  21. */
  22. onChange: Function
  23. };
  24. /**
  25. * The type of the React {@code Component} state of {@link VolumeSlider}.
  26. */
  27. type State = {
  28. /**
  29. * The volume of the participant's audio element. The value will
  30. * be represented by a slider.
  31. */
  32. volumeLevel: number
  33. };
  34. /**
  35. * Implements a React {@link Component} which displays an input slider for
  36. * adjusting the local volume of a remote participant.
  37. *
  38. * @extends Component
  39. */
  40. class VolumeSlider extends Component<Props, State> {
  41. /**
  42. * Initializes a new {@code VolumeSlider} instance.
  43. *
  44. * @param {Object} props - The read-only properties with which the new
  45. * instance is to be initialized.
  46. */
  47. constructor(props: Props) {
  48. super(props);
  49. this.state = {
  50. volumeLevel: (props.initialValue || 0) * VOLUME_SLIDER_SCALE
  51. };
  52. // Bind event handlers so they are only bound once for every instance.
  53. this._onVolumeChange = this._onVolumeChange.bind(this);
  54. }
  55. /**
  56. * Implements React's {@link Component#render()}.
  57. *
  58. * @inheritdoc
  59. * @returns {ReactElement}
  60. */
  61. render() {
  62. return (
  63. <li className = 'popupmenu__item'>
  64. <div className = 'popupmenu__contents'>
  65. <span className = 'popupmenu__icon'>
  66. <i className = 'icon-volume' />
  67. </span>
  68. <div className = 'popupmenu__slider_container'>
  69. <input
  70. className = 'popupmenu__slider'
  71. max = { VOLUME_SLIDER_SCALE }
  72. min = { 0 }
  73. onChange = { this._onVolumeChange }
  74. type = 'range'
  75. value = { this.state.volumeLevel } />
  76. </div>
  77. </div>
  78. </li>
  79. );
  80. }
  81. _onVolumeChange: (Object) => void;
  82. /**
  83. * Sets the internal state of the volume level for the volume slider.
  84. * Invokes the prop onVolumeChange to notify of volume changes.
  85. *
  86. * @param {Object} event - DOM Event for slider change.
  87. * @private
  88. * @returns {void}
  89. */
  90. _onVolumeChange(event) {
  91. const volumeLevel = event.currentTarget.value;
  92. this.props.onChange(volumeLevel / VOLUME_SLIDER_SCALE);
  93. this.setState({ volumeLevel });
  94. }
  95. }
  96. export default VolumeSlider;