— 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.
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.
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.
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.
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.
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.
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.
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.
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} /> // slideUppress "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,enterTransitionand their leave twins, applied inline - .enterClass() · .leaveClass()
class-based transitions with
active,fromandto, the shape Tailwind utilities fit - .collapse()
height from 0 to the measured content height, then
auto;height 300ms easeunless you pass a transition - .stagger()
children enter one after another, 50 ms apart by default;
reverseLeaveflips the order on the way out - --stagger-index
each staggered child gets
--stagger-indexand--stagger-intervalCSS 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: noneinstead of removing it - .on() · callbacks
onEnter,onAfterEnter,onLeave,onAfterLeaveon the chain or as props; props win - Typed per mode
.group()drops theshowprop,.stagger()requires element children, HTML props follow the tag - useTransitionState
the
hidden → entering → entered → leavingstate 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
Animatedfrom 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 adiv.Importing many presets in one bundle
kinetic-presetsships 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 thepresetsobject, 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.
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.
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>
)
}A staggered list from the preset library
Presets are plain objects, so the helpers in kinetic-presets adjust them before they reach the chain.
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>
)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.
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>
)Tailwind classes instead of styles
from is applied for the first frame, to from the second, and active for the whole phase.
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/coreSources · 46 claims, each traced to v2.9.1 code or docs
- kinetic(tag) creates the component; transition is the default modeui-system:packages/kinetic/src/kinetic.ts
- Four modes: transition, collapse, stagger, groupui-system:packages/kinetic/src/kinetic/types.ts
- Package exports only kinetic(), useTransitionState, useAnimationEnd and six presets (renderers are internal)ui-system:packages/kinetic/src/index.ts
- Six built-in presets: fade, scaleIn, slideUp, slideDown, slideLeft, slideRightui-system:packages/kinetic/src/presets.ts
- kinetic-presets count (122) is facts.presets = keys of kinetic-presets' presets objectsite:src/lib/facts.ts
- Start state applied, then the 'to' state two frames later (double rAF) so the CSS transition triggersui-system:packages/kinetic/src/utils.ts
- Interpolation is the browser's CSS transition engine; kinetic only orchestrates (compositor for transform/opacity)npm:@vitus-labs/kinetic/README.md
- Completion listens to transitionend, transitioncancel, animationendui-system:packages/kinetic/src/useAnimationEnd.ts
- Bubbled events from children ignoredui-system:packages/kinetic/src/useAnimationEnd.ts
- With several transitioning properties, waits for the longestui-system:packages/kinetic/src/useAnimationEnd.ts
- Safety timeout defaults to 5000 msui-system:packages/kinetic/src/useAnimationEnd.ts
- Reversing an in-flight phase skips the start state (no flash)ui-system:packages/kinetic/src/utils.ts
- Collapse reversal starts from the current rendered heightui-system:packages/kinetic/src/utils.ts
- Reduced motion: phase completes at once, callbacks still fire, also when it flips on mid-phaseui-system:packages/kinetic/src/utils.ts
- Under reduced motion, stagger's onAfterLeave waits until every child has leftui-system:packages/kinetic/src/utils.ts
- Renderers read useReducedMotion from @vitus-labs/hooksui-system:packages/kinetic/src/kinetic/TransitionRenderer.tsx
- useReducedMotion is the prefers-reduced-motion media queryui-system:packages/hooks/src/useReducedMotion.ts
- Preset shape: enterStyle/enterToStyle/enterTransition + leave counterparts; classes enter/enterFrom/enterToui-system:packages/kinetic/src/types.ts
- .enterClass/.leaveClass take { active, from, to }ui-system:packages/kinetic/src/kinetic/createKineticComponent.tsx
- from applied first frame, to from second frame, active for the whole phaseui-system:packages/kinetic/src/types.ts
- Collapse: height from 0 to scrollHeight, default 'height 300ms ease', auto when enteredui-system:packages/kinetic/src/kinetic/CollapseRenderer.tsx
- Collapse sets height auto after enteringui-system:packages/kinetic/src/kinetic/CollapseRenderer.tsx
- Collapse measures content scrollHeightui-system:packages/kinetic/src/utils.ts
- Stagger interval default 50 ms; reverseLeave default falseui-system:packages/kinetic/src/kinetic/StaggerRenderer.tsx
- Staggered children get --stagger-index and --stagger-intervalui-system:packages/kinetic/src/kinetic/StaggerRenderer.tsx
- Group: new keys animate in, removed keys stay in DOM during leave, then unmount; no show propui-system:packages/kinetic/src/kinetic/GroupRenderer.tsx
- Leaving group entries kept at their previous positionui-system:packages/kinetic/src/utils.ts
- appear: first render (incl. SSR) renders the enter start state so hydration matchesui-system:packages/kinetic/src/types.ts
- unmount defaults to true; false keeps the element with display:noneui-system:packages/kinetic/src/types.ts
- Callback props override chain callbacksui-system:packages/kinetic/src/kinetic/createKineticComponent.tsx
- Prop types narrow per mode: group drops show, stagger requires element childrenui-system:packages/kinetic/src/kinetic/types.ts
- useTransitionState: hidden/entering/entered/leaving state machineui-system:packages/kinetic/src/types.ts
- React Native renderers drive Animated from style presetsui-system:packages/kinetic/src/kinetic/TransitionRenderer.native.tsx
- Native animation built from from/to styles and the transition string's duration/easingui-system:packages/kinetic/src/nativeAnimations.ts
- Package exposes a react-native entrynpm:@vitus-labs/kinetic/package.json
- Ref comes in as a regular prop (React 19) and is merged onto the elementui-system:packages/kinetic/src/kinetic/createKineticComponent.tsx
- Stagger/group children are cloned with a ref; classes and inline styles are set on the DOM nodeui-system:packages/kinetic/src/Transition.tsx
- A child that doesn't attach the ref completes via timeout only; dev warningui-system:packages/kinetic/src/useAnimationEnd.ts
- No spring physics, no gesture-driven values; use Motion or react-springnpm:@vitus-labs/kinetic/README.md
- 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
- This site animates a styled grid with kinetic(GridBox).preset(slideUp).stagger()site:src/ui/Stagger.tsx
- Peer dependencies react >= 19 and @vitus-labs/hooksnpm:@vitus-labs/kinetic/package.json
- @vitus-labs/hooks peers on @vitus-labs/core (hence the install line)npm:@vitus-labs/hooks/package.json
- kinetic-presets: factories createFade/Slide/Scale/Rotate/Blur and utilities compose/withDuration/withEasing/withDelay/reverseui-system:packages/kinetic-presets/src/index.ts
- withDuration(preset, enterMs, leaveMs?)ui-system:packages/kinetic-presets/src/utils.ts
- fadeUp exists in kinetic-presetsnpm:@vitus-labs/kinetic-presets/lib/index.d.ts