From d6d318006b0519ee3de0b640ce1da580e495ce11 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sun, 19 Feb 2023 21:00:22 +0100 Subject: [PATCH] chromecast button styling Co-authored-by: Jip Frijlink Co-authored-by: James Hawkins Co-authored-by: William Oldham --- src/setup/index.css | 5 +- .../components/actions/ChromecastAction.tsx | 50 ++++++++++++++++++- .../parts/VideoPlayerIconButton.tsx | 14 ++++-- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/setup/index.css b/src/setup/index.css index 79bd1613..c3d97c26 100644 --- a/src/setup/index.css +++ b/src/setup/index.css @@ -50,7 +50,6 @@ body[data-no-select] { overflow: hidden; } -google-cast-launcher { - @apply pointer-events-auto m-2 text-white flex items-center justify-center p-2; - @apply transition-[background-color,transform] duration-100 rounded-full bg-denim-600 bg-opacity-0 hover:bg-opacity-50 active:bg-denim-500 active:bg-opacity-100 active:scale-110; +.google-cast-button:not(.casting) google-cast-launcher { + @apply brightness-[500]; } diff --git a/src/video/components/actions/ChromecastAction.tsx b/src/video/components/actions/ChromecastAction.tsx index 123a6130..7334af67 100644 --- a/src/video/components/actions/ChromecastAction.tsx +++ b/src/video/components/actions/ChromecastAction.tsx @@ -1,12 +1,60 @@ import { Icons } from "@/components/Icon"; import { VideoPlayerIconButton } from "@/video/components/parts/VideoPlayerIconButton"; +import { useVideoPlayerDescriptor } from "@/video/state/hooks"; +import { useMisc } from "@/video/state/logic/misc"; +import { useCallback, useEffect, useRef, useState } from "react"; interface Props { className?: string; } export function ChromecastAction(props: Props) { + const [hidden, setHidden] = useState(false); + const descriptor = useVideoPlayerDescriptor(); + const misc = useMisc(descriptor); + const isCasting = misc.isCasting; + const ref = useRef(null); + + const setButtonVisibility = useCallback( + (tag: HTMLElement) => { + const isVisible = (tag.getAttribute("style") ?? "").includes("inline"); + setHidden(!isVisible); + }, + [setHidden] + ); + + useEffect(() => { + const tag = ref.current?.querySelector("google-cast-launcher"); + if (!tag) return; + + const observer = new MutationObserver(() => { + setButtonVisibility(tag); + }); + + observer.observe(tag, { attributes: true, attributeFilter: ["style"] }); + setButtonVisibility(tag); + + return () => { + observer.disconnect(); + }; + }, [setButtonVisibility]); + return ( - +