-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c02acfc
commit 4ab0452
Showing
6 changed files
with
130 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react' | ||
import {motion} from 'framer-motion' | ||
const AnimatedText = ({title,hover}:{title:string,hover:boolean}) => { | ||
return ( | ||
<motion.div className='relative overflow-hidden'> | ||
<AnimatedWord title={title} animation={letterAnimation} hover={hover}/> | ||
<div className='absolute top-0'> | ||
<AnimatedWord title={title} animation={letterAnimationTwo} hover={hover}/> | ||
</div> | ||
</motion.div> | ||
) | ||
} | ||
const titleAnimation ={ | ||
rest:{ | ||
transition:{ | ||
staggerChildren:0.003 | ||
} | ||
}, | ||
hover:{ | ||
transition:{ | ||
staggerChildren:0.003 | ||
} | ||
} | ||
} | ||
const letterAnimation ={ | ||
rest:{ | ||
y:0, | ||
},hover:{ | ||
y:-25, | ||
transition:{ | ||
duration:0.3, | ||
ease:[0.6,0.01,0.05,0.95], | ||
type:'tween' | ||
} | ||
} | ||
} | ||
const letterAnimationTwo ={ | ||
rest:{ | ||
y:25, | ||
},hover:{ | ||
y:0, | ||
transition:{ | ||
duration:0.3, | ||
ease:[0.6,0.01,0.05,0.95], | ||
type:'tween' | ||
} | ||
} | ||
} | ||
const AnimatedWord =({title,animation,hover}:{title:string,animation:any,hover:boolean})=>{ | ||
return( | ||
<motion.span variants={titleAnimation} initial="rest" animate={hover ? 'hover' : 'rest'} className='whitespace-nowrap relative'> | ||
{ | ||
title.split("").map((item,index)=> | ||
item === " " ? <span key={index}> </span> | ||
: <motion.span key={index} variants={animation} className='relative inline-block whitespace-nowrap' >{item}</motion.span> | ||
) | ||
} | ||
</motion.span> | ||
) | ||
} | ||
export default AnimatedText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import { navItems } from '@/constants' | ||
import Link from 'next/link' | ||
import React from 'react' | ||
import { navItems } from '@/constants'; | ||
import Link from 'next/link'; | ||
import AnimatedText from './AnimatedText'; | ||
import { useState } from 'react'; | ||
|
||
const NavItems: React.FC = () => { | ||
// Initialize an array of hover states, initially all set to false | ||
const [hoverStates, setHoverStates] = useState<boolean[]>(Array(navItems.length).fill(false)); | ||
|
||
// Function to handle hover state change for a specific item | ||
const handleHoverChange = (index: number, isHovered: boolean): void => { | ||
const newHoverStates = [...hoverStates]; // Create a copy of the array | ||
newHoverStates[index] = isHovered; // Update the hover state for the specific item | ||
setHoverStates(newHoverStates); // Update the state | ||
}; | ||
|
||
const NavItems = () => { | ||
return ( | ||
<div className='bg-gray-200/70 flex rounded-full p-1'> | ||
{ | ||
navItems.map((item,index)=>( | ||
<Link className='flex-center text-black px-5 hover:bg-white rounded-full' key={index} href={item.href}> | ||
{item.title} | ||
</Link> | ||
)) | ||
} | ||
</div> | ||
) | ||
} | ||
<div className='bg-gray-200/70 flex rounded-full p-1'> | ||
{navItems.map((item, index) => ( | ||
<Link | ||
key={index} | ||
href={item.href} | ||
onMouseEnter={() => handleHoverChange(index, true)} // Set hover state to true on mouse enter | ||
onMouseLeave={() => handleHoverChange(index, false)} // Set hover state to false on mouse leave | ||
className='flex-center text-black px-5 hover:bg-white rounded-full' | ||
> | ||
<AnimatedText hover={hoverStates[index]} title={item.title} /> {/* Pass the hover state for the specific item */} | ||
</Link> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default NavItems | ||
export default NavItems; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters