search animation

This commit is contained in:
VividTruthKeeper 2023-02-01 02:57:54 +05:00
parent cd2c6cb691
commit af8eb7ba49
3 changed files with 39 additions and 4 deletions

View File

@ -0,0 +1,15 @@
// Types
import { Variants } from "framer-motion";
export const searchMotion: Variants = {
rest: {
transform: "translateY(0rem)",
opacity: 1,
type: "spring",
},
active: {
transform: "translateX(6rem)",
opacity: 0,
type: "tween",
},
};

View File

@ -1,7 +1,15 @@
// Modules
import { useState } from "react";
import { motion } from "framer-motion";
// Animations
import { searchMotion } from "../../animations/search.animation";
// Icons
import { ReactComponent as Loop } from "../../assets/icons/loop.svg";
const Search = () => {
const [input, setInput] = useState<string>("");
return (
<form
className="search"
@ -9,11 +17,22 @@ const Search = () => {
event.preventDefault()
}
>
<input type="text" />
<div>
<Loop />
<input
type="text"
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setInput(event.target.value)
}
/>
<motion.div
initial={"rest"}
animate={input.length > 0 ? "active" : "rest"}
variants={searchMotion}
>
<motion.svg>
<Loop />
</motion.svg>
<span>Search anything...</span>
</div>
</motion.div>
</form>
);
};

View File

@ -9,6 +9,7 @@
}
.search {
overflow: hidden;
position: relative;
input {
border: 0.1rem solid $gray-dark;