clipper/frontend/src/ControlBar.tsx

100 lines
2.8 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { PlayState } from './Player';
import {
CloudDownloadIcon,
FastForwardIcon,
PauseIcon,
PlayIcon,
RewindIcon,
ZoomInIcon,
ZoomOutIcon,
} from '@heroicons/react/solid';
2021-10-08 14:38:35 +00:00
interface Props {
playState: PlayState;
zoomInEnabled: boolean;
zoomOutEnabled: boolean;
onTogglePlay: () => void;
2021-12-29 15:38:25 +00:00
onClip: () => void;
2022-01-07 18:51:29 +00:00
onZoomIn: () => void;
onZoomOut: () => void;
downloadClipEnabled: boolean;
2021-10-08 14:38:35 +00:00
}
const ControlBar: React.FC<Props> = React.memo((props: Props) => {
const buttonStyle =
'bg-gray-600 hover:bg-gray-500 text-white font-bold py-2 px-4 rounded';
const disabledButtonStyle =
'bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-auto';
const downloadButtonStyle = props.downloadClipEnabled
? 'bg-green-600 hover:bg-green-600 text-white font-bold py-2 px-4 rounded absolute right-0'
: 'bg-gray-600 hover:cursor-not-allowed text-gray-500 font-bold py-2 px-4 rounded absolute right-0';
const iconStyle = 'inline h-7 w-7 text-white-500';
const playPauseComponent =
props.playState == PlayState.Playing ? (
<PauseIcon className={iconStyle} />
) : (
<PlayIcon className={iconStyle} />
);
2021-10-08 14:38:35 +00:00
const handleClip = () => {
if (props.downloadClipEnabled) {
props.onClip();
}
};
// Detect if the space bar has been used to trigger this event, and ignore
// it if so. This conflicts with the player interface.
const filterMouseEvent = (evt: React.MouseEvent, cb: () => void) => {
if (evt.detail == 0) {
return;
}
cb();
};
2021-10-08 14:38:35 +00:00
return (
<>
<div className="relative grow-0 w-full py-2 space-x-2">
<button className={buttonStyle}>
<RewindIcon className={iconStyle} />
</button>
<button
className={buttonStyle}
onClick={(evt) => filterMouseEvent(evt, props.onTogglePlay)}
>
{playPauseComponent}
2021-10-08 14:38:35 +00:00
</button>
<button className={buttonStyle}>
<FastForwardIcon className={iconStyle} />
2021-10-08 14:38:35 +00:00
</button>
<button
className={props.zoomInEnabled ? buttonStyle : disabledButtonStyle}
onClick={(evt) => filterMouseEvent(evt, props.onZoomIn)}
>
<ZoomInIcon className={iconStyle} />
2021-12-29 15:38:25 +00:00
</button>
<button
className={props.zoomOutEnabled ? buttonStyle : disabledButtonStyle}
onClick={(evt) => filterMouseEvent(evt, props.onZoomOut)}
>
<ZoomOutIcon className={iconStyle} />
2022-01-07 18:51:29 +00:00
</button>
<button
className={downloadButtonStyle}
onClick={(evt) => filterMouseEvent(evt, handleClip)}
>
<CloudDownloadIcon className={`${iconStyle} mr-2`} />
Download clip as MP3
2022-01-07 18:51:29 +00:00
</button>
2021-10-08 14:38:35 +00:00
</div>
</>
);
});
ControlBar.displayName = 'ControlBar';
export { ControlBar };