Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VolumeSlider.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconVolume } from '../../../base/icons';
  5. import { VOLUME_SLIDER_SCALE } from '../../constants';
  6. /**
  7. * The type of the React {@code Component} props of {@link VolumeSlider}.
  8. */
  9. type Props = {
  10. /**
  11. * The value of the audio slider should display at when the component first
  12. * mounts. Changes will be stored in state. The value should be a number
  13. * between 0 and 1.
  14. */
  15. initialValue: number,
  16. /**
  17. * The callback to invoke when the audio slider value changes.
  18. */
  19. onChange: Function,
  20. /**
  21. * Invoked to obtain translated strings.
  22. */
  23. t: 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
  65. aria-label = { this.props.t('volumeSlider') }
  66. className = 'popupmenu__item'>
  67. <div className = 'popupmenu__contents'>
  68. <span className = 'popupmenu__icon'>
  69. <Icon src = { IconVolume } />
  70. </span>
  71. <div className = 'popupmenu__slider_container'>
  72. <input
  73. aria-valuemax = { VOLUME_SLIDER_SCALE }
  74. aria-valuemin = { 0 }
  75. aria-valuenow = { this.state.volumeLevel }
  76. className = 'popupmenu__slider'
  77. max = { VOLUME_SLIDER_SCALE }
  78. min = { 0 }
  79. onChange = { this._onVolumeChange }
  80. tabIndex = { 0 }
  81. type = 'range'
  82. value = { this.state.volumeLevel } />
  83. </div>
  84. </div>
  85. </li>
  86. );
  87. }
  88. _onVolumeChange: (Object) => void;
  89. /**
  90. * Sets the internal state of the volume level for the volume slider.
  91. * Invokes the prop onVolumeChange to notify of volume changes.
  92. *
  93. * @param {Object} event - DOM Event for slider change.
  94. * @private
  95. * @returns {void}
  96. */
  97. _onVolumeChange(event) {
  98. const volumeLevel = event.currentTarget.value;
  99. this.props.onChange(volumeLevel / VOLUME_SLIDER_SCALE);
  100. this.setState({ volumeLevel });
  101. }
  102. }
  103. export default translate(VolumeSlider);