-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
6 changed files
with
57 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version: "0.2" | ||
version: '0.2' | ||
ignorePaths: [] | ||
dictionaryDefinitions: [] | ||
dictionaries: [] | ||
|
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 |
---|---|---|
|
@@ -17,4 +17,4 @@ | |
"examples": "@/components/examples", | ||
"blocks": "@/components/blocks" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,99 +1,98 @@ | ||
"use client"; | ||
import React, { useState, useEffect, useRef } from "react"; | ||
'use client' | ||
import { cn } from '@/lib/utils' | ||
import { motion } from 'framer-motion' | ||
import React, { useEffect, useState } from 'react' | ||
|
||
import { motion } from "framer-motion"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
type Direction = "TOP" | "LEFT" | "BOTTOM" | "RIGHT"; | ||
type Direction = 'BOTTOM' | 'LEFT' | 'RIGHT' | 'TOP' | ||
|
||
export function HoverBorderGradient({ | ||
as: Tag = 'button', | ||
children, | ||
containerClassName, | ||
className, | ||
as: Tag = "button", | ||
duration = 1, | ||
clockwise = true, | ||
containerClassName, | ||
duration = 1, | ||
...props | ||
}: React.PropsWithChildren< | ||
{ | ||
as?: React.ElementType; | ||
containerClassName?: string; | ||
className?: string; | ||
duration?: number; | ||
clockwise?: boolean; | ||
as?: React.ElementType | ||
className?: string | ||
clockwise?: boolean | ||
containerClassName?: string | ||
duration?: number | ||
} & React.HTMLAttributes<HTMLElement> | ||
>) { | ||
const [hovered, setHovered] = useState<boolean>(false); | ||
const [direction, setDirection] = useState<Direction>("TOP"); | ||
const [hovered, setHovered] = useState<boolean>(false) | ||
const [direction, setDirection] = useState<Direction>('TOP') | ||
|
||
const rotateDirection = (currentDirection: Direction): Direction => { | ||
const directions: Direction[] = ["TOP", "LEFT", "BOTTOM", "RIGHT"]; | ||
const currentIndex = directions.indexOf(currentDirection); | ||
const directions: Direction[] = ['TOP', 'LEFT', 'BOTTOM', 'RIGHT'] | ||
const currentIndex = directions.indexOf(currentDirection) | ||
const nextIndex = clockwise | ||
? (currentIndex - 1 + directions.length) % directions.length | ||
: (currentIndex + 1) % directions.length; | ||
return directions[nextIndex]; | ||
}; | ||
: (currentIndex + 1) % directions.length | ||
return directions[nextIndex] | ||
} | ||
|
||
const movingMap: Record<Direction, string> = { | ||
TOP: "radial-gradient(20.7% 50% at 50% 0%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)", | ||
LEFT: "radial-gradient(16.6% 43.1% at 0% 50%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)", | ||
BOTTOM: | ||
"radial-gradient(20.7% 50% at 50% 100%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)", | ||
'radial-gradient(20.7% 50% at 50% 100%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)', | ||
LEFT: 'radial-gradient(16.6% 43.1% at 0% 50%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)', | ||
RIGHT: | ||
"radial-gradient(16.2% 41.199999999999996% at 100% 50%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)", | ||
}; | ||
'radial-gradient(16.2% 41.199999999999996% at 100% 50%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)', | ||
TOP: 'radial-gradient(20.7% 50% at 50% 0%, hsl(0, 0%, 100%) 0%, rgba(255, 255, 255, 0) 100%)', | ||
} | ||
|
||
const highlight = | ||
"radial-gradient(75% 181.15942028985506% at 50% 50%, #3275F8 0%, rgba(255, 255, 255, 0) 100%)"; | ||
const highlight | ||
= 'radial-gradient(75% 181.15942028985506% at 50% 50%, #3275F8 0%, rgba(255, 255, 255, 0) 100%)' | ||
|
||
useEffect(() => { | ||
if (!hovered) { | ||
const interval = setInterval(() => { | ||
setDirection((prevState) => rotateDirection(prevState)); | ||
}, duration * 1000); | ||
return () => clearInterval(interval); | ||
setDirection(prevState => rotateDirection(prevState)) | ||
}, duration * 1000) | ||
return () => clearInterval(interval) | ||
} | ||
}, [hovered]); | ||
}, [hovered]) | ||
return ( | ||
<Tag | ||
onMouseEnter={(event: React.MouseEvent<HTMLDivElement>) => { | ||
setHovered(true); | ||
}} | ||
onMouseLeave={() => setHovered(false)} | ||
className={cn( | ||
"relative flex rounded-full border content-center bg-black/20 hover:bg-black/10 transition duration-500 dark:bg-white/20 items-center flex-col flex-nowrap gap-10 h-min justify-center overflow-visible p-px decoration-clone w-fit", | ||
containerClassName | ||
'relative flex rounded-full border content-center bg-black/20 hover:bg-black/10 transition duration-500 dark:bg-white/20 items-center flex-col flex-nowrap gap-10 h-min justify-center overflow-visible p-px decoration-clone w-fit', | ||
containerClassName, | ||
)} | ||
onMouseEnter={(_: React.MouseEvent<HTMLDivElement>) => { | ||
setHovered(true) | ||
}} | ||
onMouseLeave={() => setHovered(false)} | ||
{...props} | ||
> | ||
<div | ||
className={cn( | ||
"w-auto text-white z-10 bg-black px-4 py-2 rounded-[inherit]", | ||
className | ||
'w-auto text-white z-10 bg-black px-4 py-2 rounded-[inherit]', | ||
className, | ||
)} | ||
> | ||
{children} | ||
</div> | ||
<motion.div | ||
className={cn( | ||
"flex-none inset-0 overflow-hidden absolute z-0 rounded-[inherit]" | ||
)} | ||
style={{ | ||
filter: "blur(2px)", | ||
position: "absolute", | ||
width: "100%", | ||
height: "100%", | ||
}} | ||
initial={{ background: movingMap[direction] }} | ||
animate={{ | ||
background: hovered | ||
? [movingMap[direction], highlight] | ||
: movingMap[direction], | ||
}} | ||
transition={{ ease: "linear", duration: duration ?? 1 }} | ||
className={cn( | ||
'flex-none inset-0 overflow-hidden absolute z-0 rounded-[inherit]', | ||
)} | ||
initial={{ background: movingMap[direction] }} | ||
style={{ | ||
filter: 'blur(2px)', | ||
height: '100%', | ||
position: 'absolute', | ||
width: '100%', | ||
}} | ||
transition={{ duration: duration ?? 1, ease: 'linear' }} | ||
/> | ||
<div className="bg-black absolute z-1 flex-none inset-[2px] rounded-[100px]" /> | ||
</Tag> | ||
); | ||
) | ||
} |
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