From 0bdcd91b8dd5c2d446af5d3b98807ff0c7297bfa Mon Sep 17 00:00:00 2001 From: gofnnp Date: Tue, 25 Jun 2024 01:41:53 +0400 Subject: [PATCH] play-pause-button add play/pause control to personal video --- .../components/PersonalVideo/index.tsx | 14 +++- .../PersonalVideo/styles.module.css | 9 +++ .../ABDesign/v1/ui/PlayPauseButton/index.tsx | 64 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/components/pages/ABDesign/v1/ui/PlayPauseButton/index.tsx diff --git a/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/index.tsx b/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/index.tsx index 01bee65..83a4f1d 100644 --- a/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/index.tsx +++ b/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/index.tsx @@ -3,6 +3,7 @@ import ReactPlayer from "react-player"; import styles from "./styles.module.css"; import Loader from "@/components/Loader"; import PlayButton from "../../../../ui/PlayButton"; +import PlayPauseButton from "../../../../ui/PlayPauseButton"; interface IPersonalVideoProps { gender: string; @@ -11,6 +12,7 @@ interface IPersonalVideoProps { const PersonalVideo = React.memo(({ url, gender }) => { const [isPlaying, setIsPlaying] = useState(false); + const [isStarted, setIsStarted] = useState(false); const [isError, setIsError] = useState(false); const onError = (error: unknown) => { @@ -21,7 +23,9 @@ const PersonalVideo = React.memo(({ url, gender }) => { return (
- {!isPlaying && !isError && } + {!isPlaying && !isError && !isStarted && ( + + )} {isError && ( (({ url, gender }) => { playing={isPlaying} stopOnUnmount={true} width="100%" + onStart={() => setIsStarted(true)} onReady={() => setIsPlaying(true)} onError={onError} playsinline={true} @@ -48,6 +53,13 @@ const PersonalVideo = React.memo(({ url, gender }) => { aspectRatio: "16 / 9", }} /> + {!isError && isStarted && ( + setIsPlaying((prev) => !prev)} + className={styles["play-pause-button"]} + /> + )}
); }); diff --git a/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/styles.module.css b/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/styles.module.css index 7880b62..b6a4cf5 100644 --- a/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/styles.module.css +++ b/src/components/pages/ABDesign/v1/pages/TrialPayment/components/PersonalVideo/styles.module.css @@ -15,4 +15,13 @@ top: 50%; left: 50%; transform: translate(-50%, -50%); +} + +.play-pause-button { + position: absolute; + bottom: 10px; + left: 8px; + width: 34px; + height: auto; + z-index: 10; } \ No newline at end of file diff --git a/src/components/pages/ABDesign/v1/ui/PlayPauseButton/index.tsx b/src/components/pages/ABDesign/v1/ui/PlayPauseButton/index.tsx new file mode 100644 index 0000000..3d50ffa --- /dev/null +++ b/src/components/pages/ABDesign/v1/ui/PlayPauseButton/index.tsx @@ -0,0 +1,64 @@ +import { SVGProps } from "react"; + +interface IPlayPauseButtonProps { + state?: "play" | "pause"; +} + +function PlayPauseButton({ + state = "play", + ...props +}: IPlayPauseButtonProps & SVGProps) { + return ( + + + + + {state === "play" && ( + + )} + {state === "pause" && ( + <> + + + + )} + + + + + + + + + + ); +} + +export default PlayPauseButton;