import { ChevronDoubleLeft, ChevronDoubleRight } from '@/components/HeroIcons' import { useGlobal } from '@/lib/global' import Link from 'next/link' import { useRouter } from 'next/router' import { useRef, useState } from 'react' /** * 博客列表上方嵌入条 * @param {*} props * @returns */ export default function CategoryBar(props) { const { categoryOptions, border = true } = props const { locale } = useGlobal() const [scrollRight, setScrollRight] = useState(false) // 创建一个ref引用 const categoryBarItemsRef = useRef(null) // 点击#right时,滚动#category-bar-items到最右边 const handleToggleScroll = () => { if (categoryBarItemsRef.current) { const { scrollWidth, clientWidth } = categoryBarItemsRef.current if (scrollRight) { categoryBarItemsRef.current.scrollLeft = 0 } else { categoryBarItemsRef.current.scrollLeft = scrollWidth - clientWidth } setScrollRight(!scrollRight) } } return