— Motion · @vitus-labs/kinetic · @vitus-labs/kinetic-presets

Enter and leave, on CSS transitions.

kinetic(tag) returns a component that animates in and out. The browser's transition engine does the interpolation; kinetic only times the mount, the unmount and the style changes. One chain picks the mode: .collapse() for height, .stagger() for lists, .group() for keyed children. 122 more presets live in @vitus-labs/kinetic-presets.

@vitus-labs/kineticv2.9.1 · MIT
npm i @vitus-labs/kinetic @vitus-labs/hooks @vitus-labs/core
modes from one factory
4
presets in kinetic-presets
122
values interpolated in JS
0

— Why kinetic

Let the browser run the frames.

01

CSS does the motion

Kinetic applies the start styles, waits two animation frames so they paint, then applies the end styles. Everything between is a plain CSS transition, so transform and opacity can run on the compositor while your JavaScript is busy.

02

Unmounts when it's really done

Completion comes from transitionend, transitioncancel and animationend on the element itself. Bubbled events from children are ignored, and with several transitioning properties it waits for the longest. A timeout (5 s by default) is the safety net.

03

Reverses without a flash

Toggle mid-animation and the new phase starts from where the element is, instead of snapping to its start state. .collapse() reverses from the height it has reached.

04

Reduced motion by default

When the user asks for reduced motion, each phase completes at once. Lifecycle callbacks still fire, so focus handling and analytics behave the same. No configuration.

— Before / after

Same fade. Half the wiring.

A panel that fades in when it opens and unmounts after fading out.

beforereact-transition-group
Panel.tsx · fade.css
import { useRef } from 'react'
import { CSSTransition } from 'react-transition-group'
import './fade.css' // .fade-enter, .fade-enter-active, .fade-exit, .fade-exit-active

export function Panel({ open, children }) {
  const nodeRef = useRef(null)
  return (
    <CSSTransition
      in={open}
      nodeRef={nodeRef}
      timeout={{ enter: 300, exit: 200 }}
      classNames="fade"
      unmountOnExit
    >
      <div ref={nodeRef}>{children}</div>
    </CSSTransition>
  )
}

The durations live twice, in the stylesheet and in timeout, the four class names live in a separate file, and the ref is yours to wire.

after@vitus-labs/kinetic
Panel.tsx
import { kinetic, fade } from '@vitus-labs/kinetic'

const FadePanel = kinetic('div').preset(fade)

export function Panel({ open, children }) {
  return <FadePanel show={open}>{children}</FadePanel>
}

The preset holds the start state, the end state and the transition. The end is read from the DOM, the ref is attached for you, and the panel unmounts once it has faded out.

— Live, not a screenshot

Toggle it, read the lifecycle.

Real kinetic components with kinetic's built-in presets. The log is written by kinetic's own onEnter / onAfterEnter / onLeave / onAfterLeave callbacks, timed from your click. With reduced motion on, the after-callbacks arrive at once.

kinetic(Tile).preset(slideUp)
mode
preset
show
Reveal.tsx
import { kinetic, fade, scaleIn, slideLeft, slideUp } from '@vitus-labs/kinetic'

// Tile / Stack / Body: plain styled() components (styling omitted)
const Card  = kinetic(Tile).preset(slideUp)
const List  = kinetic(Stack).preset(slideUp).stagger({ interval: 70 })
const Panel = kinetic('div').collapse({ transition: 'height 320ms ease' })

<Card show={show} onEnter={log} onAfterEnter={log}
      onLeave={log} onAfterLeave={log}>…</Card>
<Card show={true} />  // slideUp
lifecycle callbackslive
press "hide it" to run a phase

in DOMreduced motion: off

— Features

Four modes, one chain.

  • kinetic(tag)

    any HTML tag or component, including styled and rocketstyle ones; the result renders and chains

  • .preset()

    style-object presets: enterStyle, enterToStyle, enterTransition and their leave twins, applied inline

  • .enterClass() · .leaveClass()

    class-based transitions with active, from and to, the shape Tailwind utilities fit

  • .collapse()

    height from 0 to the measured content height, then auto; height 300ms ease unless you pass a transition

  • .stagger()

    children enter one after another, 50 ms apart by default; reverseLeave flips the order on the way out

  • --stagger-index

    each staggered child gets --stagger-index and --stagger-interval CSS variables for your own effects

  • .group()

    keyed children animate in when added and out when removed; a leaving node keeps its place until it's gone

  • appear

    animates on mount; the first render (and the server HTML) carries the start state, so hydration matches

  • unmount: false

    keeps a hidden element mounted with display: none instead of removing it

  • .on() · callbacks

    onEnter, onAfterEnter, onLeave, onAfterLeave on the chain or as props; props win

  • Typed per mode

    .group() drops the show prop, .stagger() requires element children, HTML props follow the tag

  • useTransitionState

    the hidden → entering → entered → leaving state machine, exported for custom renderers

  • useAnimationEnd

    end detection with the bubbling, multi-property and timeout handling built in

  • React Native

    native builds of the renderers drive Animated from the same style presets

— API

One factory, five helpers.

Every name links to its reference in the docs.

— Honest limits

When CSS transitions aren't enough.

Where it isn't the right fit, and what to reach for instead.

  • Springs, gestures, drag

    A CSS transition goes from A to B along an easing curve. There is no spring physics and no value tied to a pointer. For those, use Motion or react-spring.

  • Animating siblings into place

    .group() animates items entering and leaving, not the reflow of the items around them. For layout (FLIP) animation, use AutoAnimate or Motion's layout animations.

  • Children that drop the ref

    Stagger and group clone each child with a ref, then set classes and inline styles on the DOM node it points to. A component that doesn't forward that ref can't be animated: kinetic waits for the timeout and warns in development. Forward it, or wrap the child in a div.

  • Importing many presets in one bundle

    kinetic-presets ships as a single module. Bundlers that tree-shake named exports keep only what you import, but this site's Turbopack build couldn't, so it uses kinetic's six built-in presets. Import presets by name, not the presets object, and check your bundle.

  • You're on React 18

    The peer range is react >= 19 (refs arrive as a regular prop), and kinetic also peers on @vitus-labs/hooks. On React 18, stay with your current animation library.

— Recipes

Copy, paste, ship.

01

An accordion that measures itself

No fixed heights: .collapse() measures the content each time it opens, and settles on height: auto so the panel can grow afterwards.

Accordion.tsx
import { useState } from 'react'
import { kinetic } from '@vitus-labs/kinetic'

const Collapse = kinetic('section').collapse({
  transition: 'height 250ms ease-out',
})

export function Faq({ q, children }) {
  const [open, setOpen] = useState(false)
  return (
    <div>
      <button aria-expanded={open} onClick={() => setOpen((o) => !o)}>
        {q}
      </button>
      <Collapse show={open}>{children}</Collapse>
    </div>
  )
}
02

A staggered list from the preset library

Presets are plain objects, so the helpers in kinetic-presets adjust them before they reach the chain.

Results.tsx
import { kinetic } from '@vitus-labs/kinetic'
import { fadeUp, withDuration } from '@vitus-labs/kinetic-presets'

const List = kinetic('ul')
  .preset(withDuration(fadeUp, 400, 200))
  .stagger({ interval: 40, reverseLeave: true })

export const Results = ({ items, visible }) => (
  <List show={visible}>
    {items.map((item) => (
      <li key={item.id}>{item.title}</li>
    ))}
  </List>
)
03

Toasts that leave in place

.group() needs no show prop: render the toasts you have, keyed. A removed key animates out at its old position before it unmounts.

Toasts.tsx
import { kinetic, slideLeft } from '@vitus-labs/kinetic'

const Stack = kinetic('ol').preset(slideLeft).group()

export const Toasts = ({ toasts, dismiss }) => (
  <Stack aria-live="polite">
    {toasts.map((t) => (
      <li key={t.id} onClick={() => dismiss(t.id)}>
        {t.message}
      </li>
    ))}
  </Stack>
)
04

Tailwind classes instead of styles

from is applied for the first frame, to from the second, and active for the whole phase.

Dialog.tsx
import { kinetic } from '@vitus-labs/kinetic'

export const DialogPanel = kinetic('div')
  .enterClass({
    active: 'transition duration-300 ease-out',
    from: 'opacity-0 scale-95',
    to: 'opacity-100 scale-100',
  })
  .leaveClass({
    active: 'transition duration-200 ease-in',
    from: 'opacity-100 scale-100',
    to: 'opacity-0 scale-95',
  })

// <DialogPanel show={open}>…</DialogPanel>

— FAQ

Questions, answered.

Where are Transition, Stagger, Collapse and TransitionGroup?

They are internal renderers. The package exports the kinetic() factory, two hooks and six presets; you reach each renderer through the chain: kinetic(tag) for a transition, then .collapse(), .stagger() or .group().

Does it work with server rendering?

Yes. Without appear, the server renders the element as it is. With appear, the first render, server included, carries the enter start state, so the markup exists and hydration matches before the animation starts on the client.

Can I animate my own components?

Pass them as the tag: kinetic(Button).preset(fade). The component receives ref, className and style and has to put them on its DOM element. Styled and rocketstyle components already do; this site animates a styled grid this way.

What happens with reduced motion?

Kinetic reads prefers-reduced-motion through useReducedMotion from @vitus-labs/hooks. When it's on, each phase completes immediately and the after-callbacks still fire. If the preference turns on mid-animation, the running phase completes right away. A .stagger() list still fires its onAfterLeave once, after the last child has left.

Does it run on React Native?

Yes. The package ships native renderers that drive Animated from the same style presets and transition strings. Class-based transitions are web-only, since React Native has no CSS classes.

— @vitus-labs/kinetic · @vitus-labs/kinetic-presets

Mount it. Kinetic times the rest.

npm i @vitus-labs/kinetic @vitus-labs/hooks @vitus-labs/core
Sources · 46 claims, each traced to v2.9.1 code or docs
  1. kinetic(tag) creates the component; transition is the default modeui-system:packages/kinetic/src/kinetic.ts
  2. Four modes: transition, collapse, stagger, groupui-system:packages/kinetic/src/kinetic/types.ts
  3. Package exports only kinetic(), useTransitionState, useAnimationEnd and six presets (renderers are internal)ui-system:packages/kinetic/src/index.ts
  4. Six built-in presets: fade, scaleIn, slideUp, slideDown, slideLeft, slideRightui-system:packages/kinetic/src/presets.ts
  5. kinetic-presets count (122) is facts.presets = keys of kinetic-presets' presets objectsite:src/lib/facts.ts
  6. Start state applied, then the 'to' state two frames later (double rAF) so the CSS transition triggersui-system:packages/kinetic/src/utils.ts
  7. Interpolation is the browser's CSS transition engine; kinetic only orchestrates (compositor for transform/opacity)npm:@vitus-labs/kinetic/README.md
  8. Completion listens to transitionend, transitioncancel, animationendui-system:packages/kinetic/src/useAnimationEnd.ts
  9. Bubbled events from children ignoredui-system:packages/kinetic/src/useAnimationEnd.ts
  10. With several transitioning properties, waits for the longestui-system:packages/kinetic/src/useAnimationEnd.ts
  11. Safety timeout defaults to 5000 msui-system:packages/kinetic/src/useAnimationEnd.ts
  12. Reversing an in-flight phase skips the start state (no flash)ui-system:packages/kinetic/src/utils.ts
  13. Collapse reversal starts from the current rendered heightui-system:packages/kinetic/src/utils.ts
  14. Reduced motion: phase completes at once, callbacks still fire, also when it flips on mid-phaseui-system:packages/kinetic/src/utils.ts
  15. Under reduced motion, stagger's onAfterLeave waits until every child has leftui-system:packages/kinetic/src/utils.ts
  16. Renderers read useReducedMotion from @vitus-labs/hooksui-system:packages/kinetic/src/kinetic/TransitionRenderer.tsx
  17. useReducedMotion is the prefers-reduced-motion media queryui-system:packages/hooks/src/useReducedMotion.ts
  18. Preset shape: enterStyle/enterToStyle/enterTransition + leave counterparts; classes enter/enterFrom/enterToui-system:packages/kinetic/src/types.ts
  19. .enterClass/.leaveClass take { active, from, to }ui-system:packages/kinetic/src/kinetic/createKineticComponent.tsx
  20. from applied first frame, to from second frame, active for the whole phaseui-system:packages/kinetic/src/types.ts
  21. Collapse: height from 0 to scrollHeight, default 'height 300ms ease', auto when enteredui-system:packages/kinetic/src/kinetic/CollapseRenderer.tsx
  22. Collapse sets height auto after enteringui-system:packages/kinetic/src/kinetic/CollapseRenderer.tsx
  23. Collapse measures content scrollHeightui-system:packages/kinetic/src/utils.ts
  24. Stagger interval default 50 ms; reverseLeave default falseui-system:packages/kinetic/src/kinetic/StaggerRenderer.tsx
  25. Staggered children get --stagger-index and --stagger-intervalui-system:packages/kinetic/src/kinetic/StaggerRenderer.tsx
  26. Group: new keys animate in, removed keys stay in DOM during leave, then unmount; no show propui-system:packages/kinetic/src/kinetic/GroupRenderer.tsx
  27. Leaving group entries kept at their previous positionui-system:packages/kinetic/src/utils.ts
  28. appear: first render (incl. SSR) renders the enter start state so hydration matchesui-system:packages/kinetic/src/types.ts
  29. unmount defaults to true; false keeps the element with display:noneui-system:packages/kinetic/src/types.ts
  30. Callback props override chain callbacksui-system:packages/kinetic/src/kinetic/createKineticComponent.tsx
  31. Prop types narrow per mode: group drops show, stagger requires element childrenui-system:packages/kinetic/src/kinetic/types.ts
  32. useTransitionState: hidden/entering/entered/leaving state machineui-system:packages/kinetic/src/types.ts
  33. React Native renderers drive Animated from style presetsui-system:packages/kinetic/src/kinetic/TransitionRenderer.native.tsx
  34. Native animation built from from/to styles and the transition string's duration/easingui-system:packages/kinetic/src/nativeAnimations.ts
  35. Package exposes a react-native entrynpm:@vitus-labs/kinetic/package.json
  36. Ref comes in as a regular prop (React 19) and is merged onto the elementui-system:packages/kinetic/src/kinetic/createKineticComponent.tsx
  37. Stagger/group children are cloned with a ref; classes and inline styles are set on the DOM nodeui-system:packages/kinetic/src/Transition.tsx
  38. A child that doesn't attach the ref completes via timeout only; dev warningui-system:packages/kinetic/src/useAnimationEnd.ts
  39. No spring physics, no gesture-driven values; use Motion or react-springnpm:@vitus-labs/kinetic/README.md
  40. kinetic-presets is a single module; this site's Turbopack build couldn't tree-shake it, so the site uses kinetic's built-in slideUpsite:src/ui/Stagger.tsx
  41. This site animates a styled grid with kinetic(GridBox).preset(slideUp).stagger()site:src/ui/Stagger.tsx
  42. Peer dependencies react >= 19 and @vitus-labs/hooksnpm:@vitus-labs/kinetic/package.json
  43. @vitus-labs/hooks peers on @vitus-labs/core (hence the install line)npm:@vitus-labs/hooks/package.json
  44. kinetic-presets: factories createFade/Slide/Scale/Rotate/Blur and utilities compose/withDuration/withEasing/withDelay/reverseui-system:packages/kinetic-presets/src/index.ts
  45. withDuration(preset, enterMs, leaveMs?)ui-system:packages/kinetic-presets/src/utils.ts
  46. fadeUp exists in kinetic-presetsnpm:@vitus-labs/kinetic-presets/lib/index.d.ts