From 3dd7d828def06a670dfdbb945d9efeb9ffb95755 Mon Sep 17 00:00:00 2001 From: Marten Mrfc <101009922+Marten-Mrfc@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:07:35 +0200 Subject: [PATCH] [Docs] Redid the player controls ui --- documentation/src/components/Player/index.tsx | 122 +++++++++++++----- 1 file changed, 93 insertions(+), 29 deletions(-) diff --git a/documentation/src/components/Player/index.tsx b/documentation/src/components/Player/index.tsx index 5a9dbb469e..d37e55ecf7 100644 --- a/documentation/src/components/Player/index.tsx +++ b/documentation/src/components/Player/index.tsx @@ -1,38 +1,102 @@ -import React, { useState } from "react"; +import React, { useState, useRef } from "react"; import ReactPlayer from "react-player"; - +import { Icon } from "@iconify/react"; +import fullscreen from "screenfull"; interface PlayerProps { - url: string; + url: string; } export default function Player({ url }: PlayerProps) { - let [progress, setProgress] = useState(0); - return ( -
- - setProgress(state.played * 100)} - className="[&>video]:rounded-b-lg" - /> + const [progress, setProgress] = useState(0); + const [playing, setPlaying] = useState(true); + const playerRef = useRef(null); + const playerContainerRef = useRef(null); + + const togglePlayPause = () => { + setPlaying((prev) => !prev); + }; + + const handleSeek = (e: React.ChangeEvent) => { + const newProgress = parseFloat(e.target.value); + setProgress(newProgress); + playerRef.current?.seekTo(newProgress / 100, "fraction"); + }; + + return ( +
+ + setProgress(state.played * 100)} + /> +
+
+ +
+
+ fullscreen.toggle(playerContainerRef.current)} + className="cursor-pointer m-100" + icon="mdi:fullscreen" + fontSize={40} + color="white" + /> +
- ); +
+); + +} +interface ProgressBarProps { + progress: number; + onSeek: (e: React.ChangeEvent) => void; } -function Bar({ progress }: { progress: number }) { - return ( -
-
-
- ); +function ProgressBar({ progress, onSeek }: ProgressBarProps) { + return ( +
+
+ +
+
+ ); +} + +interface BarProps { + progress: number; + onSeek: (e: React.ChangeEvent) => void; +} + +function Bar({ progress, onSeek }: BarProps) { + return ( +
+ +
+
+ ); }