diff --git a/src/animations/header.animations.ts b/src/animations/header.animations.ts new file mode 100644 index 0000000..e2dc2d6 --- /dev/null +++ b/src/animations/header.animations.ts @@ -0,0 +1,20 @@ +export const searchFormAnimation: Record< + string, + Record> +> = { + rest: { + opacity: 1, + duration: 0.2, + type: 'tween', + x: 0, + }, + + hover: { + y: -10, + opacity: 0, + transition: { + duration: 0.1, + type: 'spring', + }, + }, +}; diff --git a/src/components/header/SearchForm.tsx b/src/components/header/SearchForm.tsx new file mode 100644 index 0000000..f0dcb95 --- /dev/null +++ b/src/components/header/SearchForm.tsx @@ -0,0 +1,35 @@ +// Modules +import { useState } from 'react'; +import { motion } from 'framer-motion'; + +// Icons +import LoopGray from '../../assets/icons/loop-gray.svg'; + +// Animations +import { searchFormAnimation } from '../../animations/header.animations'; + +const SearchForm = () => { + const [input, setInput] = useState(''); + return ( + +
) => { + event.preventDefault(); + }}> + 0 ? searchFormAnimation.hover : searchFormAnimation.rest}> + + Search anything + + ) => setInput(event.target.value)} + /> +
+
+ ); +}; + +export default SearchForm; diff --git a/src/components/header/SubHeader.tsx b/src/components/header/SubHeader.tsx index 976ecc5..81fd17e 100644 --- a/src/components/header/SubHeader.tsx +++ b/src/components/header/SubHeader.tsx @@ -1,50 +1,16 @@ // Modules -import { motion } from "framer-motion"; -import { Link } from "react-router-dom"; -import { useState } from "react"; +import { Link } from 'react-router-dom'; // Images -import Logo from "../../assets/images/logo.png"; +import Logo from '../../assets/images/logo.png'; // Icons -import ArrowDownBlack from "../../assets/icons/arrow-down-black.svg"; -import LoopGray from "../../assets/icons/loop-gray.svg"; +import ArrowDownBlack from '../../assets/icons/arrow-down-black.svg'; -const loopMotion = { - rest: { - opacity: 0, - ease: "ease", - duration: 0.2, - type: "tween", - }, - hover: { - opacity: 1, - ease: "ease", - duration: 0.2, - type: "tween", - }, -}; - -const blockMotion = { - rest: { - opacity: 1, - duration: 0.2, - type: "tween", - x: 0, - }, - - hover: { - y: -10, - opacity: 0, - transition: { - duration: 0.1, - type: "spring", - }, - }, -}; +// Components +import SearchForm from './SearchForm'; const SubHeader = () => { - const [isTyping, setIsTyping] = useState(false); return (
@@ -78,29 +44,7 @@ const SubHeader = () => {
- -
) => { - event.preventDefault(); - }} - > - - - Search anything - - ) => { - event.target.value.length > 0 - ? setIsTyping(true) - : setIsTyping(false); - }} - /> -
-
+