diff --git a/package-lock.json b/package-lock.json index ce65c06..2e70ff8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@contacto-io/style-guide", - "version": "0.5.37", + "version": "0.5.40", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index bf63e45..a2eaa09 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "registry": "https://npm.pkg.github.com" }, "repository": "git://github.com/contacto-io/contacto-console", - "version": "0.5.37", + "version": "0.5.40", "main": "build/index.js", "module": "build/index.es.js", "files": [ diff --git a/src/components/AudioPlayer/components/PlaybackSpeed.js b/src/components/AudioPlayer/components/PlaybackSpeed.js index 30f8dd6..c270f5e 100644 --- a/src/components/AudioPlayer/components/PlaybackSpeed.js +++ b/src/components/AudioPlayer/components/PlaybackSpeed.js @@ -1,42 +1,23 @@ +/* eslint-disable no-unused-vars */ import React, { useEffect, useState } from 'react' -import { Popover } from 'antd' -import { Button } from '../../Button/index' +import { RenderButtons } from '../helpers/utils' + +const speeds = [0.5, 1, 1.5, 2] -const speeds = [0.8, 1, 1.2, 1.5, 1.7, 2, 2.5] export default function PlaybackSpeed({ waveSurfer }) { const [speed, setSpeed] = useState(waveSurfer?.getPlaybackRate()) - const handleSpeedChange = (speed) => { - setSpeed(speed) - waveSurfer?.setPlaybackRate(speed) - } - useEffect(() => { setSpeed(waveSurfer?.getPlaybackRate()) }, [waveSurfer]) return ( - ( -
- {speeds.map((speed) => ( - - ))} -
- )} - > - -
+ ) } diff --git a/src/components/AudioPlayer/components/PlaybackSpeedPopup.js b/src/components/AudioPlayer/components/PlaybackSpeedPopup.js new file mode 100644 index 0000000..13481c1 --- /dev/null +++ b/src/components/AudioPlayer/components/PlaybackSpeedPopup.js @@ -0,0 +1,33 @@ +import React, { useEffect, useState } from 'react' +import { Popover } from 'antd' +import { Button } from '../../Button/index' +import { RenderButtons } from '../helpers/utils' + +const speeds = [0.8, 1, 1.2, 1.5, 1.7, 2, 2.5] +export default function PlaybackSpeedPopup({ waveSurfer }) { + const [speed, setSpeed] = useState(waveSurfer?.getPlaybackRate()) + + useEffect(() => { + setSpeed(waveSurfer?.getPlaybackRate()) + }, [waveSurfer]) + + return ( + ( + + )} + > + + + ) +} diff --git a/src/components/AudioPlayer/helpers/utils.js b/src/components/AudioPlayer/helpers/utils.js index baa47a3..bb645fe 100644 --- a/src/components/AudioPlayer/helpers/utils.js +++ b/src/components/AudioPlayer/helpers/utils.js @@ -1,3 +1,6 @@ +import React from 'react' +import { Button } from '../../Button/index' + export const getDisplayTime = (seconds) => { const int = +seconds / 60 let minutes = parseInt(int) @@ -10,3 +13,35 @@ export const getDisplayTime = (seconds) => { export const generateId = (prefix) => { return `${prefix}${Math.random().toString(36).slice(2)}` } + +export const handleSpeedChange = (speed, waveSurfer, setSpeed) => { + setSpeed(speed) + waveSurfer?.setPlaybackRate(speed) +} + +export const getType = (speed, waveSurfer) => { + return speed === waveSurfer?.getPlaybackRate() ? 'secondary' : 'table-action-link' +} + +export const RenderButtons = ({ + speeds, + waveSurfer, + setSpeed, + parentClassName, + buttonClassName, +}) => { + return ( +
+ {speeds.map((speed) => ( + + ))} +
+ ) +} diff --git a/src/components/AudioPlayer/index.js b/src/components/AudioPlayer/index.js index 11e935c..df3206a 100644 --- a/src/components/AudioPlayer/index.js +++ b/src/components/AudioPlayer/index.js @@ -4,6 +4,7 @@ import { forwardRef, useState, useLayoutEffect } from 'react' import PlayPauseIcon from './components/PlayPauseIcon' import useWaveSurfer from './helpers/useWaveSurfer' import PlaybackSpeed from './components/PlaybackSpeed' +import PlaybackSpeedPopup from './components/PlaybackSpeedPopup' import { Button } from '../Button/index' import { Icon } from '../Icon/index' import { getDisplayTime } from './helpers/utils' @@ -11,7 +12,7 @@ import './styles.scss' // TODO: @Ritik Add Error Boundaries const AudioPlayer = forwardRef((props, ref) => { - const { className, url } = props + const { className, url, showSpeedInPopup = true } = props const { playerConfig, durationConfig, waveSurferRef } = useWaveSurfer(url) const { isPlaying, loading } = playerConfig @@ -52,7 +53,11 @@ const AudioPlayer = forwardRef((props, ref) => {
{getDisplayTime(totalDuration)}
- + {showSpeedInPopup ? ( + + ) : ( + + )} ) diff --git a/src/components/AudioPlayer/index.stories.js b/src/components/AudioPlayer/index.stories.js index 771601b..3aa0167 100755 --- a/src/components/AudioPlayer/index.stories.js +++ b/src/components/AudioPlayer/index.stories.js @@ -12,3 +12,9 @@ export const Default = Template.bind({}) Default.args = { url: 'https://wavesurfer-js.org/wavesurfer-code/examples/audio/mono.mp3', } + +export const WithSpeed = Template.bind({}) +WithSpeed.args = { + url: 'https://wavesurfer-js.org/wavesurfer-code/examples/audio/mono.mp3', + showSpeedInPopup: false, +} diff --git a/src/components/AudioPlayer/styles.scss b/src/components/AudioPlayer/styles.scss index b59da7a..197ab50 100644 --- a/src/components/AudioPlayer/styles.scss +++ b/src/components/AudioPlayer/styles.scss @@ -17,7 +17,7 @@ } &.contacto-button--table-action-link { - background-color: var(--background-highlight-color); + background-color: var(--background-highlight-color) !important; &:hover { background-color: var(--background-highlight-color) !important; @@ -90,7 +90,7 @@ } } -.contacto-player-speed { +.contacto-player-speed-popup { padding-top: 8px; .ant-popover-arrow { @@ -119,10 +119,22 @@ align-items: center; gap: 8px; - .contacto-player-speed { + .contacto-player-speed-popup { @include playback-speed-button; } } } } } + +.contacto-player-speed { + display: flex; + justify-content: center; + align-items: center; + gap: 8px; + margin-left: 24px; + + .contacto-player-speed-buttons { + @include playback-speed-button; + } +}