视频播放器仓库

Volume.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import styles from './Volume.css';
  3. import VolumeOff from './../Icon/volume_off.svg';
  4. import VolumeUp from './../Icon/volume_up.svg';
  5. export default ({ onChange, onClick, volume, muted, className, ariaLabelMute, ariaLabelUnmute, ariaLabelVolume }) => {
  6. const volumeValue = muted || !volume
  7. ? 0
  8. : +volume;
  9. const isSilent = muted || volume <= 0;
  10. return (
  11. <div className={[
  12. styles.component,
  13. className
  14. ].join(' ')}>
  15. <button
  16. aria-label={isSilent
  17. ? ariaLabelUnmute
  18. : ariaLabelMute}
  19. className={styles.button}
  20. onClick={onClick}
  21. type="button">
  22. { isSilent
  23. ? <VolumeOff
  24. height={34}
  25. width={34}
  26. className={styles.icon}
  27. fill="#fff" />
  28. : <VolumeUp
  29. height={34}
  30. width={34}
  31. className={styles.icon}
  32. fill="#fff"/> }
  33. </button>
  34. <div className={styles.slider}>
  35. <div className={styles.track}>
  36. <div
  37. className={styles.fill}
  38. style={{
  39. height: `${volumeValue * 100}%`
  40. }} />
  41. <input
  42. min="0"
  43. step={0.1}
  44. max="1"
  45. type="range"
  46. orient="vertical"
  47. onChange={onChange}
  48. aria-label={ariaLabelVolume}
  49. className={styles.input}
  50. value={volumeValue} />
  51. </div>
  52. </div>
  53. </div>
  54. );
  55. };