parent
e577a90e65
commit
421e53fd20
@ -0,0 +1,22 @@ |
|||||||
|
import { useSpring, animated } from "@react-spring/web"; |
||||||
|
import React from "react"; |
||||||
|
|
||||||
|
type Props = { |
||||||
|
children: string; |
||||||
|
}; |
||||||
|
|
||||||
|
const MysteriousText = ({ children, ...props }: Props) => { |
||||||
|
const animation = (i: any) => |
||||||
|
useSpring({ opacity: 1, from: { opacity: 0 }, delay: Math.random() * 500 }); |
||||||
|
return ( |
||||||
|
<> |
||||||
|
{children.split("").map((item, index) => ( |
||||||
|
<animated.span key={index} style={animation(index)} {...props}> |
||||||
|
{item} |
||||||
|
</animated.span> |
||||||
|
))} |
||||||
|
</> |
||||||
|
); |
||||||
|
}; |
||||||
|
|
||||||
|
export default MysteriousText; |
@ -1,30 +0,0 @@ |
|||||||
import { a, useTrail } from "@react-spring/web"; |
|
||||||
import React from "react"; |
|
||||||
import styles from "./styles.module.css"; |
|
||||||
|
|
||||||
type Props = { |
|
||||||
open: boolean; |
|
||||||
children: React.ReactNode; |
|
||||||
}; |
|
||||||
|
|
||||||
const Trail: React.FC<Props> = ({ open, children }) => { |
|
||||||
const items = React.Children.toArray(children); |
|
||||||
const trail = useTrail(items.length, { |
|
||||||
config: { mass: 5, tension: 2000, friction: 200 }, |
|
||||||
opacity: open ? 1 : 0, |
|
||||||
x: open ? 0 : 20, |
|
||||||
height: open ? 110 : 0, |
|
||||||
from: { opacity: 0, x: 20, height: 0 }, |
|
||||||
}); |
|
||||||
return ( |
|
||||||
<div> |
|
||||||
{trail.map(({ height, ...style }, index) => ( |
|
||||||
<a.div key={index} className="will-change-auto" style={style}> |
|
||||||
<a.div style={{ height }}>{items[index]}</a.div> |
|
||||||
</a.div> |
|
||||||
))} |
|
||||||
</div> |
|
||||||
); |
|
||||||
}; |
|
||||||
|
|
||||||
export default Trail; |
|
Loading…
Reference in new issue