Keyframes
Rotating an Element
Example of how to use frame motion Keyframes.
Rotating
rotating.tsx
import Rotating from '@/components/animations/rotating' import React from 'react' const Keyframes = () => { return ( <div className="p-5"> <Rotating refresh rotate={[0,90, 180, 270, 360]} transition={{duration:2,repeat:Infinity}}> <div className="w-52 h-52 rounded-[24px] from-rose-500 via-pink-500 to-purple-500 bg-gradient-to-t" /> </Rotating> </div> ) } export default Keyframes "use client" import React, { useState } from 'react'; import { Preview } from '../common/display'; import { motion } from "framer-motion"; interface transitionProps{ repeat: number; duration: number; } interface RotateProps{ children: React.ReactNode; rotate: number[]; transition:transitionProps; refresh:boolean; } const Rotating = ({ children, rotate,transition, refresh }:RotateProps) => { const [count, setCount] = useState(0); return ( <Preview SetCount={setCount} isRefreshing={refresh} animeName='Rotating'> <motion.div key={count} animate={{ rotate: rotate}} transition={{duration: transition.duration, repeat: transition.repeat}} > {children} </motion.div> </Preview> ); }; export default Rotating; interface PreviewerProps { children: React.ReactNode; SetCount: (count: number) => void; isRefreshing: boolean; animeName:string } export const Preview = ({ children, SetCount, isRefreshing, animeName }: PreviewerProps) => { const [count, setCount] = useState(0); const [isLoading, setIsLoading] = useState(false); const handleClick = () => { setIsLoading(true); setCount(count + 1); SetCount(count + 1); setTimeout(() => { setIsLoading(false); }, 400); // Timeout duration matches the animation duration }; return ( <div className="w-full h-full flex flex-col"> <div className="w-full flex-1 flex justify-center items-center"> {children} </div> {isRefreshing && <div onClick={handleClick} className="h-[50px] w-full px-6 rounded-b-[24px] flex justify-between"> <span>{animeName}</span><RotateCw className={isLoading ? 'animate-spin duration-200' : 'animate-none'} /> </div> } </div> ) };