MCPcopy Create free account
hub / github.com/WinterCore/react-text-transition / TextTransition

Function TextTransition

src/components/TextTransition.tsx:6–71  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

4import {useSpring, useTransition, animated, config, SpringConfig} from "react-spring";
5
6const TextTransition: React.FC<TextTransitionProps> = (props) => {
7 const {
8 direction = "up",
9 inline = false,
10 springConfig = config.default,
11 delay = 0,
12 className,
13 style,
14 children,
15 } = props;
16
17 const initialRun = React.useRef(true);
18
19 const transitions = useTransition([children], {
20 from: { opacity : 0, transform : `translateY(${direction === "down" ? "-100%" : "100%"})` },
21 enter: { opacity : 1, transform : "translateY(0%)" },
22 leave: { opacity : 0, transform : `translateY(${direction === "down" ? "100%" : "-100%"})`, position: "absolute" },
23 config: springConfig,
24 immediate: initialRun.current,
25 delay: ! initialRun.current ? delay : undefined,
26 });
27
28 const [width, setWidth] = React.useState<number>(0);
29 const currentRef = React.useRef<HTMLDivElement>(null);
30 const heightRef = React.useRef<number | string>("auto");
31
32 React.useEffect(() => {
33 initialRun.current = false;
34
35 const elem = currentRef.current;
36
37 if (! elem) {
38 return;
39 }
40
41 const { width, height } = elem.getBoundingClientRect();
42 setWidth(width);
43 heightRef.current = height;
44 }, [children, setWidth, currentRef]);
45
46 const widthTransition = useSpring({
47 to: { width },
48 config: springConfig,
49 immediate: initialRun.current,
50 delay: ! initialRun.current ? delay : undefined,
51 });
52
53 return (
54 <animated.div
55 className={`text-transition ${className}`}
56 style={{
57 ...(inline && ! initialRun.current ? widthTransition : undefined),
58 ...style,
59 whiteSpace: inline ? "nowrap" : "normal",
60 display: inline ? "inline-flex" : "flex",
61 height: heightRef.current,
62 }}
63 >

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…