Search

Back

Copy Link

Library

/

Free

/

26

Spin 360

26

Spin 360

FREE

Not loading? Preview

Made by

@frameroverrides

override

click

Override

Spin 360

Copy

Override

Copied to Clipboard!

Instructions

Code Preview

import type { ComponentType } from "react"
import { motion } from "framer-motion"
import { useState } from "react"

const rotateOnClickVariants = {
    initial: { rotate: 0 },
    rotate: (custom) => ({ rotate: custom.degrees }),
}

export function withClick(Component): ComponentType {
    return (props) => {
        const [degrees, setDegrees] = useState(0)

        const handleClick = () => {
            setDegrees((prevDegrees) => prevDegrees + 360)
        }

        return (
            <Component
                {...props}
                as={motion.div}
                onClick={handleClick}
                custom={{ degrees }}
                animate="rotate"
                variants={rotateOnClickVariants}
                initial="initial"
                transition={{ type: "tween", duration: 0.5, ease: "easeInOut" }}
            />
        )
    }
}

export function withHover(Component): ComponentType {
    return (props) => {
        const [degrees, setDegrees] = useState(0)

        const handleMouseEnter = () => {
            setDegrees((prevDegrees) => prevDegrees + 360)
        }

        return (
            <Component
                {...props}
                as={motion.div}
                onMouseEnter={handleMouseEnter}
                custom={{ degrees }}
                animate="rotate"
                variants={rotateOnClickVariants}
                initial="initial"
                transition={{ type: "tween", duration: 0.5, ease: "easeInOut" }}
            />
        )
    }
}

Next

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.