How to use the react-spring.useTransition 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 streetmix / streetmix / assets / scripts / streets / EnvironmentEditor.jsx View on Github external
const selected = useSelector(
    (state) => state.street.environment || DEFAULT_ENVIRONS
  )
  const show = useSelector((state) => state.ui.toolboxVisible || false)
  const dispatch = useDispatch()

  const handleClick = (event, env) => {
    dispatch(setEnvironment(env.id))
  }

  const handleClose = (event) => {
    dispatch(toggleToolbox())
  }

  const envs = getAllEnvirons()
  const transitions = useTransition(show, null, {
    from: { opacity: 0, transform: 'scale(0.75)', pointerEvents: 'none' },
    enter: { opacity: 1, transform: 'scale(1)', pointerEvents: 'auto' },
    leave: { opacity: 0, transform: 'scale(0.85)', pointerEvents: 'none' },
    config: { tension: 600, velocity: 20, clamp: true }
  })

  return transitions.map(
    ({ item, key, props }) =>
      item && (
        
          {/* Two containers are necessary because different libraries are applying CSS transforms */}
          {/* Outer container is transformed by Draggable's position */}
          <div>
            {/* Inner container contains transition styles from Transition */}
            </div>
github clarisights / KnitUI / src / components / Alert / AlertsAPI.tsx View on Github external
}, [props.alerts])

  const transitionConfigs: any = {
    from: { height: 0, opacity: 0, life: "100%" },
    enter: (item: AlertProps) => async (next: any) =>
      await next({ height: refMap.get(item).offsetHeight, opacity: 1 }),
    leave: (item: AlertProps) => async (next: any, cancel: any) => {
      cancelMap.set(item, cancel)
      await next({ life: "0%" })
      await next({ opacity: 0 })
      await next({ height: 0 })
    },
    config: config,
  }

  const transitionProps = useTransition(
    alerts,
    item => item.key as string,
    transitionConfigs
  )

  // Return container based on placement prop
  const getWrapper = () => {
    switch (props.placement) {
      case "topLeft":
        return TopLeftBox
      case "topRight":
        return TopRightBox
      case "bottomLeft":
        return BottomLeftBox
      case "bottomRight":
        return BottomRightBox
github pylnata / teddy / src / App.js View on Github external
const App = props =&gt; {
  const { location } = useRouter();
  const transitions = useTransition(location, location =&gt; location.pathname, {
    from: {
      opacity: location.pathname !== "/" ? 0 : 1,
      transform: "translateX(0%)"
    },
    enter: { opacity: 1, transform: "translateX(0%)" },
    leave: { opacity: 0, transform: "translateX(-20%)", delay: 0 }
  });
  return transitions.map(({ item, props, key }) =&gt; (
github monjason23 / burger-dash / src / containers / GameOrder.jsx View on Github external
function GameOrder() {
  const orders = useSelector(state =&gt; state.gameStatus.orders, shallowEqual);

  const ordersTransition = useTransition(orders, item =&gt; item.name, {
    config: config.wobbly,
    trail: 100,
    from: { height: 44, opacity: 1, transform: "scale(1) translateX(-110%)" },
    enter: { transform: "scale(1) translateX(0%)" },
    leave: {
      height: 0,
      opacity: 0,
      transform: "scale(0) translateX(0%)"
    }
  });

  function renderOrders() {
    return ordersTransition.map(({ item, props, key }) =&gt; {
      return (
github LekoArts / gatsby-starter-portfolio-emilia / src / components / Transition.js View on Github external
const Transition = props =&gt; {
  const transitions = useTransition([props], item =&gt; item.location.pathname, {
    from: { opacity: 0, transform: 'translateY(60px)' },
    enter: { opacity: 1, transform: 'translateY(0px)' },
    leave: { opacity: 0, transform: 'translateY(30px)' },
  })

  return transitions.map(({ item, props: styles, key }) =&gt; (
    
      {item.children}
    
  ))
}
github ra-gg / Delir / packages / delir / src / components / ModalOwner / ModalOwner.tsx View on Github external
updateState(draft =&gt; {
        draft[modalId] = {factory(callback)}
      })
    })

    return {
      abort: () =&gt; unmount(),
      promise: promise as Promise,
      then: (fullfiled: any, rejected: any): any =&gt; {
        return promise.then(fullfiled, rejected)
      },
    }
  }, [])

  const modalsArray = useMemo(() =&gt; Object.entries(modals), [modals])
  const transitions = useTransition(modalsArray.length &gt; 0, null, {
    from: {
      backdropFilter: 'blur(0px)',
      opacity: 0,
      pointerEvents: 'none',
    },
    enter: {
      backdropFilter: 'blur(2px)',
      opacity: 1,
      pointerEvents: 'all',
    },
    leave: {
      backdropFilter: 'blur(0px)',
      opacity: 0,
      pointerEvents: 'none',
    },
  })
github ra-gg / Delir / packages / delir / views / RenderingWaiter / index.tsx View on Github external
const [show, setShow] = React.useState(true)

    const { inRendering, status } = useStore([RendererStore], getStore =&gt; ({
        inRendering: getStore(RendererStore).isInRendering(),
        status: getStore(RendererStore).getExportingState(),
    }))

    const handleClickDone = React.useCallback(() =&gt; {
        setShow(false)
    }, [])

    React.useEffect(() =&gt; {
        setShow(true)
    }, [inRendering])

    const transitions = useTransition(show &amp;&amp; !!status, null, {
        from: { opacity: 0 },
        enter: { opacity: 1 },
        leave: { opacity: 0 },
    })

    return (
        &lt;&gt;
            {transitions.map(
                ({ item, key, props: style }) =&gt;
                    item &amp;&amp; (
                        
                            {status.step === RenderingStep.Completed ? (
                                &lt;&gt;
                                    <div>
                                        <img src="{require('./parrot.gif')}">
                                        <div>{statusToText(status)}</div></div>
github microlinkhq / www / src / components / pages / home / screenshots.js View on Github external
const Screenshots = props =&gt; {
  const [index, setIndex] = useState(0)
  const onClick = useCallback(
    () =&gt; setIndex(state =&gt; (state + 1) % screenshotsUrls.length),
    []
  )

  const transitions = useTransition(index, p =&gt; p, {
    from: { opacity: 0 },
    enter: { opacity: 1 },
    leave: { opacity: 0 },
    config: {
      duration: speed.quickly
    }
  })

  const blockOne = (
    <legend title="Turn websites into a snapshot">
  )

  const blockTwo = (
    
      
        </legend>
github react-spring / react-spring-examples / demos / hooks / multistage-transitions / index.js View on Github external
export default function MultiStageTransition() {
  const ref = useRef([])
  const [items, set] = useState([])

  const transitions = useTransition(items, null, {
    from: {
      opacity: 0,
      height: 0,
      innerHeight: 0,
      transform: 'perspective(600px) rotateX(0deg)',
      color: '#8fa5b6',
    },
    enter: [
      { opacity: 1, height: 50, innerHeight: 50 },
      { transform: 'perspective(600px) rotateX(180deg)', color: '#28d79f' },
      { transform: 'perspective(600px) rotateX(0deg)' },
    ],
    leave: [
      { color: '#c23369' },
      { innerHeight: 0 },
      { opacity: 0, height: 0 },