Search

Back

Copy Link

Library

/

Free

/

29

Random Border Color

29

Random Border Color

Not loading? Preview

Made by

Nabeel

override

hover

Override

Random Border Color

Copy

Override

Copied to Clipboard!

Instructions

Don't apply any strokes to the item that you add this effect

Code Preview

import type { ComponentType } from "react"
import { createStore } from "https://framer.com/m/framer/store.js@^1.0.0"
import { randomColor } from "https://framer.com/m/framer/utils.js@^0.9.0"

// Learn more: https://www.framer.com/docs/guides/overrides/

const useStore = createStore({
    border: "none",
})

export function withRainbowBorder(Component: ComponentType): ComponentType {
    const rainbowColors = [
        "red",
        "orange",
        "yellow",
        "green",
        "blue",
        "indigo",
        "violet",
    ]
    let currentIndex = 0
    const getNextColor = () => {
        currentIndex = (currentIndex + 1) % rainbowColors.length
        return rainbowColors[currentIndex]
    }

    return (props) => {
        const [store, setStore] = useStore()

        const animateBorder = () => {
            const nextColor = getNextColor()
            setStore({ border: `5px solid ${nextColor}` })
        }

        return (
            <Component
                {...props}
                style={{
                    border: store.border,
                }}
                onMouseEnter={animateBorder}
                onTouchStart={animateBorder}
            />
        )
    }
}

Previous

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.