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

VolumeSlider.js 3.1KB

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