diff --git a/bun.lockb b/bun.lockb index a60aeb1..f707626 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 2f14608..14b09d9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "preview": "vite preview" }, "dependencies": { - "@fontsource/inter": "^5.1.0", + "@fontsource/inter": "^5.1.1", "@heroicons/react": "^2.2.0", "@radix-ui/react-accordion": "^1.2.2", "@radix-ui/react-checkbox": "^1.1.3", @@ -42,7 +42,7 @@ "prettier-plugin-tailwindcss": "^0.6.9", "react": "^19.0.0", "react-dom": "^19.0.0", - "react-i18next": "^15.2.0", + "react-i18next": "^15.4.0", "react-router-dom": "^7.1.1", "recharts": "^2.15.0", "sonner": "^1.7.1", @@ -51,7 +51,7 @@ }, "devDependencies": { "@eslint/js": "^9.17.0", - "@types/node": "^22.10.2", + "@types/node": "^22.10.3", "@types/react": "^19.0.2", "@types/react-dom": "^19.0.2", "@vitejs/plugin-react-swc": "^3.7.2", @@ -63,7 +63,7 @@ "postcss": "^8.4.49", "tailwindcss": "^3.4.17", "typescript": "~5.6.3", - "typescript-eslint": "^8.18.2", + "typescript-eslint": "^8.19.0", "vite": "^6.0.6" } } diff --git a/src/components/GroupSwitch.tsx b/src/components/GroupSwitch.tsx index 144b684..9446785 100644 --- a/src/components/GroupSwitch.tsx +++ b/src/components/GroupSwitch.tsx @@ -1,5 +1,6 @@ import { cn } from "@/lib/utils" import { m } from "framer-motion" +import { createRef, useEffect, useRef } from "react" export default function GroupSwitch({ tabs, @@ -13,16 +14,52 @@ export default function GroupSwitch({ const customBackgroundImage = // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined + + const scrollRef = useRef(null) + const tagRefs = useRef(tabs.map(() => createRef())) + + useEffect(() => { + const container = scrollRef.current + if (!container) return + + const isOverflowing = container.scrollWidth > container.clientWidth + if (!isOverflowing) return + + const onWheel = (e: WheelEvent) => { + e.preventDefault() + container.scrollLeft += e.deltaY + } + + container.addEventListener("wheel", onWheel, { passive: false }) + + return () => { + container.removeEventListener("wheel", onWheel) + } + }, []) + + useEffect(() => { + const currentTagRef = tagRefs.current[tabs.indexOf(currentTab)] + + if (currentTagRef && currentTagRef.current) { + currentTagRef.current.scrollIntoView({ + behavior: "smooth", + block: "nearest", + inline: "center", + }) + } + }, [currentTab]) + return ( -
+
- {tabs.map((tab: string) => ( + {tabs.map((tab: string, index: number) => (
setCurrentTab(tab)} className={cn( "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500",