-
Notifications
You must be signed in to change notification settings - Fork 185
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
5 changed files
with
187 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": "0.2", | ||
"ignorePaths": [], | ||
"dictionaryDefinitions": [], | ||
"dictionaries": [], | ||
"words": [], | ||
"ignoreWords": [], | ||
"import": [] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useRef } from 'react' | ||
import { motion, useAnimationFrame, useMotionValue } from 'motion/react' | ||
import clsx from 'clsx' | ||
|
||
const FloatAny = ({ | ||
children, | ||
speed = 0.5, | ||
amplitude = [10, 30, 30], | ||
rotationRange = [15, 15, 7.5], | ||
timeOffset = 0, | ||
className, | ||
}) => { | ||
const x = useMotionValue(0) | ||
const y = useMotionValue(0) | ||
const z = useMotionValue(0) | ||
const rotateX = useMotionValue(0) | ||
const rotateY = useMotionValue(0) | ||
const rotateZ = useMotionValue(0) | ||
|
||
// Use refs for animation values to avoid recreating the animation frame callback | ||
const time = useRef(0) | ||
|
||
useAnimationFrame(() => { | ||
time.current += speed * 0.02 | ||
|
||
// Smooth floating motion on all axes | ||
const newX = Math.sin(time.current * 0.7 + timeOffset) * amplitude[0] | ||
const newY = Math.sin(time.current * 0.6 + timeOffset) * amplitude[1] | ||
const newZ = Math.sin(time.current * 0.5 + timeOffset) * amplitude[2] | ||
|
||
// 3D rotations with different frequencies for more organic movement | ||
const newRotateX = Math.sin(time.current * 0.5 + timeOffset) * rotationRange[0] | ||
const newRotateY = Math.sin(time.current * 0.4 + timeOffset) * rotationRange[1] | ||
const newRotateZ = Math.sin(time.current * 0.3 + timeOffset) * rotationRange[2] | ||
|
||
x.set(newX) | ||
y.set(newY) | ||
z.set(newZ) | ||
rotateX.set(newRotateX) | ||
rotateY.set(newRotateY) | ||
rotateZ.set(newRotateZ) | ||
}) | ||
|
||
return ( | ||
<motion.div | ||
style={{ | ||
x, | ||
y, | ||
z, | ||
rotateX, | ||
rotateY, | ||
rotateZ, | ||
transformStyle: 'preserve-3d', | ||
}} | ||
className={clsx('will-change-transform', className)} | ||
> | ||
{children} | ||
</motion.div> | ||
) | ||
} | ||
|
||
export default FloatAny |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { useState, useEffect } from 'react' | ||
|
||
import { motion, AnimatePresence } from 'motion/react' | ||
|
||
export function LoadingText({ text, dots }) { | ||
return ( | ||
<div className="relative"> | ||
<AnimatePresence mode="wait"> | ||
<motion.div | ||
key={text} | ||
initial={{ opacity: 0, y: 10 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
exit={{ opacity: 0, y: -10 }} | ||
transition={{ duration: 0.3 }} | ||
className="w-full text-lg font-medium" | ||
> | ||
{text} | ||
{dots} | ||
</motion.div> | ||
</AnimatePresence> | ||
</div> | ||
) | ||
} | ||
|
||
const TextLoader = ({ messages, interval = 2000, dotCount = 3, direction = 'vertical' }) => { | ||
const [currentIndex, setCurrentIndex] = useState(0) | ||
const [dots, setDots] = useState('') | ||
|
||
useEffect(() => { | ||
const messageInterval = setInterval(() => { | ||
setCurrentIndex((prev) => (prev + 1) % messages.length) | ||
}, interval) | ||
|
||
const dotInterval = setInterval(() => { | ||
setDots((prev) => (prev.length >= dotCount ? '' : `${prev}.`)) | ||
}, 500) | ||
|
||
return () => { | ||
clearInterval(messageInterval) | ||
clearInterval(dotInterval) | ||
} | ||
}, [messages.length, interval, dotCount]) | ||
|
||
if (direction === 'horizontal') { | ||
return ( | ||
<div className="flex items-center justify-start w-full gap-3 px-3 py-2 border rounded-sm"> | ||
<motion.div | ||
className="size-5 md:size-6 border-[3px] text-primary-foreground border-t-transparent rounded-full" | ||
animate={{ rotate: 360 }} | ||
transition={{ | ||
duration: 1, | ||
repeat: Number.POSITIVE_INFINITY, | ||
ease: 'linear', | ||
}} | ||
/> | ||
<LoadingText text={messages[currentIndex]} dots={dots} /> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center gap-4 py-1"> | ||
<motion.div | ||
className="size-10 md:size-12 border-[3px] text-primary-foreground border-t-transparent rounded-full" | ||
animate={{ rotate: 360 }} | ||
transition={{ | ||
duration: 1, | ||
repeat: Number.POSITIVE_INFINITY, | ||
ease: 'linear', | ||
}} | ||
/> | ||
<LoadingText text={messages[currentIndex]} dots={dots} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default TextLoader |
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