Skip to content

Commit af48ed6

Browse files
committed
animation shop menu
1 parent 79fcf21 commit af48ed6

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

src/components/ShopMenu/ShopMenu.jsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ChevronDown, ChevronUp, ArrowRight } from 'lucide-react';
44
const ShopMenu = ({ shopOpen, setShopOpen, onShopClick, onShopKeyDown }) => {
55
const [focusedIndex, setFocusedIndex] = useState(-1);
66
const [animationState, setAnimationState] = useState('closed'); // 'closed', 'opening', 'open', 'closing'
7+
const [showScrollToTop, setShowScrollToTop] = useState(false);
78
const menuItemsRef = useRef([]);
89
const shopButtonRef = useRef(null);
910

@@ -87,6 +88,24 @@ const ShopMenu = ({ shopOpen, setShopOpen, onShopClick, onShopKeyDown }) => {
8788
}
8889
}, [shopOpen, animationState]);
8990

91+
// Handle scroll to top functionality
92+
useEffect(() => {
93+
const handleScroll = () => {
94+
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
95+
setShowScrollToTop(scrollTop > 300); // Show arrow when scrolled down 300px
96+
};
97+
98+
window.addEventListener('scroll', handleScroll);
99+
return () => window.removeEventListener('scroll', handleScroll);
100+
}, []);
101+
102+
const scrollToTop = () => {
103+
window.scrollTo({
104+
top: 0,
105+
behavior: 'smooth'
106+
});
107+
};
108+
90109
// Keyboard accessibility
91110
useEffect(() => {
92111
const handleKeyDown = (event) => {
@@ -244,7 +263,7 @@ const ShopMenu = ({ shopOpen, setShopOpen, onShopClick, onShopKeyDown }) => {
244263
<div className="flex items-center justify-between mb-4">
245264
<button
246265
onClick={() => handleCollectionClick('all-products')}
247-
className="group flex items-center gap-3 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 rounded-lg px-2 py-1"
266+
className="group flex items-center gap-3 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 rounded-lg cursor-pointer"
248267
>
249268
<h2
250269
className="font-bold text-black uppercase group-hover:text-gray-600 transition-colors duration-300"
@@ -255,7 +274,7 @@ const ShopMenu = ({ shopOpen, setShopOpen, onShopClick, onShopKeyDown }) => {
255274
fontWeight: '700',
256275
}}
257276
>
258-
SHOP ALL
277+
ALL PRODUCTS
259278
</h2>
260279
<ArrowRight className="h-5 w-5 text-black group-hover:translate-x-1 transition-transform duration-300" />
261280
</button>
@@ -500,6 +519,17 @@ const ShopMenu = ({ shopOpen, setShopOpen, onShopClick, onShopKeyDown }) => {
500519
</div>
501520
</div>
502521
)}
522+
523+
{/* Scroll to Top Arrow */}
524+
{showScrollToTop && (
525+
<button
526+
onClick={scrollToTop}
527+
className="fixed bottom-8 right-8 bg-[#0D1B2A] text-white p-3 rounded-full shadow-lg hover:bg-gray-800 transition-all duration-300 z-50 group"
528+
aria-label="Scroll to top"
529+
>
530+
<ChevronUp className="h-6 w-6 group-hover:scale-110 transition-transform duration-300" />
531+
</button>
532+
)}
503533
</>
504534
);
505535
};

0 commit comments

Comments
 (0)