-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prince Kumar
committed
Oct 8, 2023
1 parent
a7e4248
commit 7f234f0
Showing
3 changed files
with
71 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, {useEffect, useRef} from "react"; | ||
import { motion, useInView, useAnimation } from "framer-motion"; | ||
|
||
interface Props { | ||
children: JSX.Element; | ||
width?: "fit-content" | "100%"; | ||
} | ||
|
||
export default function Reavel({ children, width = "fit-content" }: Props){ | ||
const mainControls = useAnimation(); | ||
const slideControls = useAnimation(); | ||
const ref = useRef(null); | ||
const isInView = useInView(ref, {once: true}); | ||
useEffect(() => { | ||
if (isInView) { | ||
mainControls.start("visible"); | ||
slideControls.start("visible"); | ||
} | ||
}, [isInView]) | ||
|
||
return ( | ||
<div ref={ref} style={{ position: "relative", width, overflow: "hidden" }}> | ||
<motion.div | ||
ref={ref} | ||
animate={mainControls} | ||
initial="hidden" | ||
transition={{ duration: .2}} | ||
variants={{ | ||
hidden: { opacity: 0, y: 75 }, | ||
visible: { opacity: 1, y: 0 }, | ||
}} | ||
style={{ width }} | ||
> | ||
{children} | ||
</motion.div> | ||
<motion.div | ||
variants={{ | ||
hidden: {left: "0"}, | ||
visible: {left: "100%"}, | ||
}} | ||
|
||
initial="hidden" | ||
animate={slideControls} | ||
transition={{duration: 0.3, ease: "easeInOut"}} | ||
style ={{ | ||
position: "absolute", | ||
top: 4, | ||
bottom: 4, | ||
left: 0, | ||
right: 0, | ||
background: "#b6d3e930", | ||
zIndex: 20, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |