How to use the react-spring.useTrail function in react-spring

To help you get started, we’ve selected a few react-spring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-spring / react-spring-examples / demos / hooks / trails / index.js View on Github external
export default function Trail() {
  const [toggle, set] = useState(true)
  const trail = useTrail(items.length, {
    // items,
    opacity: toggle ? 1 : 0,
    x: toggle ? 0 : 20,
    height: toggle ? 50 : 0,
    from: { opacity: 0, x: 20, height: 0 },
    config: { mass: 5, tension: 2000, friction: 200 },
    reverse: !toggle,
  })

  return (
    <div> set(state =&gt; !state)}&gt;
      <div>
        {trail.map(({ x, height, ...rest }, index) =&gt; (
          </div></div>
github bmcmahen / captioner / src / Editor.tsx View on Github external
// setTime(seconds);
      player.current.seekTo(seconds);
    }
  }

  function editName() {
    setEditNameMode(true);
  }

  function changeName(e: React.FormEvent) {
    e.preventDefault();
    meta!.ref.set({ title: name, customName: true }, { merge: true });
    setEditNameMode(false);
  }

  const trail = useTrail(2, {
    from: { opacity: 0, y: 3 },
    opacity: 1,
    y: 0,
    onRest: () =&gt; setRenderMain(true)
  });

  // error is loading errors or the document doesn't exist

  if (error || (meta &amp;&amp; !meta.exists)) {
    return (
github LekoArts / gatsby-starter-portfolio-jodie / src / pages / instagram.tsx View on Github external
const Instagram: React.FunctionComponent = ({
  data: {
    instagram: { nodes: instagram },
  },
}) =&gt; {
  const pageAnimation = useSpring({
    config: config.default,
    from: { opacity: 0 },
    to: { opacity: 1 },
  })

  const trail = useTrail(instagram.length, {
    config: {
      mass: 1,
      tension: 210,
      friction: 23,
    },
    from: { opacity: 0 },
    to: { opacity: 1 },
  })

  return (
    
      
      
        {trail.map((style, index) =&gt; {
          // Grab everything before the first hashtag (because I write my captions like that)
          const post = instagram[index]
github bmcmahen / captioner / src / Login.tsx View on Github external
const { email, password } = form;

    const fn = isRegistering ? createUserWithEmail : loginWithEmail;

    try {
      setError("");
      setLoading(true);
      await fn(email, password);
      setRedirectToReferrer(true);
    } catch (err) {
      setLoading(false);
      setError(err.message || "Please try again.");
    }
  }

  const animation = useTrail(1, {
    config: config.slow,
    from: { opacity: 0, transform: `translateY(-5%)` },
    opacity: 1,
    transform: `translateY(0)`
  });

  if (redirectToReferrer) {
    return ;
  }

  return (
github LekoArts / gatsby-themes / themes / gatsby-theme-emma / src / components / projects.tsx View on Github external
const Projects = ({ projects }: Props) =&gt; {
  const trail = useTrail(projects.length, {
    from: { height: `0%` },
    to: { height: `100%` },
  })

  if (projects.length === 0) {
    return (
      
        
          
            Hi!{` `}
            <span aria-label="Wave emoji" role="img">
              👋
            </span>
            {` `}
            <br>
            Thanks for using <b>@lekoarts/gatsby-theme-emma</b>. You currently don't have any content in your{` `}
github GenesisVision / web-client / packages / social-trader / src / routes / ssr / landing-page / containers / advantages-container / advantages-container.tsx View on Github external
const AdvantagesContainer: React.FC = () =&gt; {
  const section = useRef(null);
  const [trail, set] = useTrail(1, () =&gt; ({
    xy: [600, 600],
    config: config
  }));
  useEffect(() =&gt; {
    if (section.current) {
      const posSection = section.current.getBoundingClientRect();
      //@ts-ignore
      set({ xy: [posSection.width / 2, posSection.height - 100] });
    }
  }, []);
  const handleMouseMove = useCallback(
    (event: React.MouseEvent) =&gt; {
      if (section.current) {
        const posSection = section.current.getBoundingClientRect();
        const deltaX = event.clientX - posSection.x;
        const deltaY = event.clientY - posSection.y;
github react-spring / react-spring-examples / demos / hooks / goo / index.js View on Github external
export default function Goo() {
  const ref = useRef(null)
  const [trail, set] = useTrail(3, () =&gt; ({
    xy: [0, 0],
    config: i =&gt; (i === 0 ? fast : slow),
  }))

  return (
    <div> {
        const rect = ref.current.getBoundingClientRect()
        set({ xy: [e.clientX - rect.left, e.clientY - rect.top] })
      }}&gt;
      <svg style="{{">
        <filter id="goo">
          <feGaussianBlur stdDeviation="30" result="blur" in="SourceGraphic"></feGaussianBlur>
          </filter></svg></div>
github LekoArts / gatsby-starter-portfolio-emma / src / pages / index.jsx View on Github external
const Index = ({
  data: {
    allMdx: { nodes: projectEdges },
  },
  location,
}) =&gt; {
  const trail = useTrail(projectEdges.length, {
    from: { height: '0%' },
    to: { height: '100%' },
  })

  return (
    
      
        {trail.map((style, index) =&gt; (
          
        ))}
github vanilla / vanilla / library / src / scripts / flyouts / NewPostMenu.tsx View on Github external
o: state.open ? vars.toggle.opacity.open : vars.toggle.opacity.close,
        d: state.open ? vars.toggle.degree.open : vars.toggle.degree.close,
        s: state.open ? vars.toggle.scale.open : vars.toggle.scale.close,
        from: { o: vars.toggle.opacity.close, d: vars.toggle.degree.close, s: vars.toggle.scale.close },
    });

    const menu = useSpring({
        ref: menuRef,
        config: { duration: 150 },
        opacity: state.open ? vars.menu.opacity.open : vars.menu.opacity.close,
        display: state.open ? vars.menu.display.open : vars.menu.display.close,
        from: { opacity: vars.menu.opacity.close, display: vars.menu.display.close },
        onRest: () =&gt; handleAccessibility(items),
    });

    const trail = useTrail(items.length, {
        ref: itemsRef,
        config: { mass: 2, tension: 3500, friction: 100 },
        opacity: state.open ? vars.item.opacity.open : vars.item.opacity.close,
        transform: state.open
            ? `translate3d(0, ${vars.item.transformY.open}, 0)`
            : `translate3d(0, ${vars.item.transformY.close}%, 0)`,
        from: { opacity: vars.item.opacity.close, transform: `translate3d(0, ${vars.item.transformY.close}%, 0)` },
    });

    useChain(
        state.open ? [menuRef, itemsRef, backgroundRef] : [itemsRef, menuRef, backgroundRef],
        state.open ? [0.2, 0.2, 0.15] : [0.2, 0.25, 0.15],
    );

    return (
github react-spring / react-spring / examples / demos / goo / index.js View on Github external
export default function Goo() {
  const ref = useRef(null)
  const [trail, set] = useTrail(3, () =&gt; ({
    xy: [0, 0],
    config: i =&gt; (i === 0 ? fast : slow),
  }))

  return (
    <div> {
        const rect = ref.current.getBoundingClientRect()
        set({ xy: [e.clientX - rect.left, e.clientY - rect.top] })
      }}&gt;
      <svg style="{{">
        <filter id="goo">
          <feGaussianBlur stdDeviation="30" result="blur" in="SourceGraphic"></feGaussianBlur>
          </filter></svg></div>