Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/player/components/PlayerPopoverTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { PopoverTrigger } from '@/components/ui/popover';
import icon from '@/assets/icon.png';
import { BorderTrail } from '@/components/ui/border-trail';
Expand All @@ -8,18 +9,38 @@ interface PlayerPopoverTriggerProps {
}

export default function PlayerPopoverTrigger({ onClick, isPlaying }: PlayerPopoverTriggerProps) {
const containerRef = useRef<HTMLLIElement>(null);
const [parentWidth, setParentWidth] = useState<number>(0);

useEffect(() => {
const root = containerRef.current?.getRootNode() as ShadowRoot | Document | null;
const host = (root instanceof ShadowRoot ? root.host : null) as HTMLElement | null;

if (!host) return console.warn('dotbugi-player host not found');

const observer = new ResizeObserver((entries) => {
const entry = entries[0];
if (entry) setParentWidth(entry.contentRect.width);
});

observer.observe(host);
return () => observer.disconnect();
}, []);

const isCompact = parentWidth < 190;

return (
<PopoverTrigger asChild>
<li
ref={containerRef}
onClick={onClick}
className="relative flex justify-center items-center text-white text-2xl
font-bold cursor-pointer h-[61px] px-4 bg-transparent overflow-visible
"
font-bold cursor-pointer h-[61px] px-4 bg-transparent overflow-visible"
>
<div className="flex w-full justify-start items-center z-10 px-4">
<img src={icon} alt="돋부기 아이콘" className="w-10 h-10 mr-4" />
<img src={icon} alt="돋부기 아이콘" className={`${isCompact ? 'w-6 h-6 mr-2' : 'w-10 h-10 mr-4'}`} />
<div className="flex justify-between w-full items-center">
<h5 className="m-1">돋부기 🔎</h5>
{!isCompact && <h5 className="m-1">돋부기 🔎</h5>}
<span className={`w-4 h-4 rounded-full ${isPlaying ? 'bg-green-700' : 'bg-red-700'}`} />
</div>
</div>
Expand Down
Loading