From dc8f0b4d33b74a6dfb74f3f3dbcce0148948889d Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 11 Nov 2024 12:15:24 -0800 Subject: add customizable LRC colors --- src/app/components/LRCPlayer.tsx | 24 ++++++++--- src/app/page.tsx | 86 +++++++++++++++++++++++++++++++--------- 2 files changed, 85 insertions(+), 25 deletions(-) diff --git a/src/app/components/LRCPlayer.tsx b/src/app/components/LRCPlayer.tsx index e6d9551..92b9531 100644 --- a/src/app/components/LRCPlayer.tsx +++ b/src/app/components/LRCPlayer.tsx @@ -6,6 +6,8 @@ interface LineProps { $active: boolean; $next: boolean; $animate: boolean; + $lrcColor: string; + $fontColor: string; } const Line = styled.div` @@ -16,13 +18,13 @@ const Line = styled.div` font-family: "Roboto", sans-serif; font-weight: 500; text-align: center; - color: rgb(72, 72, 72); + color: ${({ $fontColor }) => $fontColor}; - background: linear-gradient( + background: ${({ $lrcColor }) => `linear-gradient( to right, rgba(0, 0, 0, 0) 50%, - rgb(200, 190, 190) 50% - ); + ${$lrcColor} 50% + )`}; background-size: 200% 100%; background-position: right bottom; @@ -53,23 +55,33 @@ interface LrcPlayerProps { currentMillisecond: number; lrc: string; animate: boolean; + lrcColor: string; + fontColor: string; } const LrcPlayer: React.FC = ({ currentMillisecond, lrc, animate, + lrcColor = "#C8BEBE", + fontColor = "rgb(72, 72, 72)", }) => { const lineRenderer = useCallback( ({ active, line: { content } }: { active: boolean; line: LrcLine }) => { const next = active && content === ""; return ( - + {content} ); }, - [animate], + [animate, lrcColor, fontColor], ); return ( diff --git a/src/app/page.tsx b/src/app/page.tsx index 3e8dfb6..c781f58 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -6,7 +6,6 @@ import { toast, ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; import { FaPlay, FaPause, FaVolumeUp, FaVolumeMute } from "react-icons/fa"; import { CaptionsRenderer } from "react-srv3"; -import { Button } from "react-bootstrap"; // Srtyled components const Root = styled.div` @@ -99,9 +98,26 @@ function KaraokePage() { const [statusText, setStatusText] = useState("No video selected"); const [balance, setBalance] = useState(0); const [animate, setAnimate] = useState(true); + const [lrcColor, setLrcColor] = useState("#C8BEBE"); + const [fontColor, setFontColor] = useState("#000000"); const [supplementAudioOffset, setSupplementAudioOffset] = useState(0); + useEffect(() => { + const savedLrcColor = localStorage.getItem("lrcColor"); + const savedFontColor = localStorage.getItem("fontColor"); + if (savedLrcColor) setLrcColor(savedLrcColor); + if (savedFontColor) setFontColor(savedFontColor); + }, []); + + useEffect(() => { + localStorage.setItem("lrcColor", lrcColor); + }, [lrcColor]); + + useEffect(() => { + localStorage.setItem("fontColor", fontColor); + }, [fontColor]); + // Functions for handling file input changes const handleLrcFileChange = ( event: React.ChangeEvent, @@ -225,6 +241,7 @@ function KaraokePage() { }; }); + // Side effect for volume controls useEffect(() => { const video = videoRef.current; const audio = supplementAudioRef.current; @@ -238,6 +255,7 @@ function KaraokePage() { } }, [balance]); + // Side effect for audio useEffect(() => { const video = videoRef.current; const audio = supplementAudioRef.current; @@ -370,6 +388,8 @@ function KaraokePage() { lrc={lrcContent} currentMillisecond={currentMillisecond} animate={animate} + lrcColor={lrcColor} + fontColor={fontColor} /> {/* Ternary operation for if videoUrl has been set */} @@ -616,25 +636,53 @@ function KaraokePage() { } step="25" /> + +
+ + setLrcColor(e.target.value) + } + /> + + setFontColor(e.target.value) + } + /> + +
- )} -- cgit v1.2.3