"use client"; import { cn } from "@/lib/utils"; import { motion } from "framer-motion"; import React, { useEffect, useRef } from "react"; export default function Switch({ allTag, nowTag, setTag, }: { allTag: string[]; nowTag: string; setTag: (tag: string) => void; }) { const scrollRef = useRef(null); useEffect(() => { const container = scrollRef.current; if (!container) return; const isOverflowing = container.scrollWidth > container.clientWidth; if (!isOverflowing) { return; } const onWheel = (e: WheelEvent) => { e.preventDefault(); e.stopPropagation(); container.scrollLeft += e.deltaY; }; container.addEventListener("wheel", onWheel, { passive: false }); return () => { container.removeEventListener("wheel", onWheel); }; }, []); return (
{allTag.map((tag) => (
setTag(tag)} className={cn( "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500", nowTag === tag ? "text-black dark:text-white" : "text-stone-400 dark:text-stone-500", )} > {nowTag === tag && ( )}

{tag}

))}
); }