File tree Expand file tree Collapse file tree 1 file changed +73
-0
lines changed
Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { motion , useInView , HTMLMotionProps } from "framer-motion" ;
4+ import { useRef } from "react" ;
5+ import { useIsMobile } from "../hooks/useIsMobile" ;
6+
7+ type MotionTags = keyof typeof motion ;
8+
9+ interface TProps extends HTMLMotionProps < any > {
10+ tag : MotionTags ;
11+ children : React . ReactNode ;
12+ variants : any ;
13+ initial : any ;
14+ animate : any ;
15+ className ?: string ;
16+ once ?: boolean ;
17+ transition ?: any ;
18+ }
19+
20+ export default function MotionTag ( {
21+ tag,
22+ children,
23+ variants,
24+ initial,
25+ animate,
26+ className,
27+ once = true ,
28+ transition = { duration : 0.3 } ,
29+ ...props
30+ } : TProps ) {
31+ const isMobile = useIsMobile ( ) ;
32+ const ref = useRef ( null ) ;
33+ const isInView = useInView ( ref , {
34+ once,
35+ margin : "-150px" ,
36+ } ) ;
37+
38+ return (
39+ < >
40+ { tag === "div" ? (
41+ < motion . div
42+ ref = { ref }
43+ variants = { variants }
44+ initial = { ! isMobile ? initial : "visible" }
45+ animate = { isInView ? animate : initial }
46+ transition = { transition }
47+ className = { className }
48+ >
49+ { children }
50+ </ motion . div >
51+ ) : (
52+ < motion . h1
53+ ref = { ref }
54+ variants = { variants }
55+ initial = { ! isMobile ? initial : "visible" }
56+ animate = { isInView ? animate : initial }
57+ transition = { transition }
58+ className = { className }
59+ >
60+ { children }
61+ </ motion . h1 >
62+ ) }
63+ </ >
64+ ) ;
65+ }
66+
67+ // ref={ref}
68+ // variants={variants}
69+ // initial={initial}
70+ // animate={isInView ? animate : initial}
71+ // transition={transition}
72+ // className={className}
73+ // viewport={{ once }}
You can’t perform that action at this time.
0 commit comments