Motion tokens
Durations, easings, springs (snappy, smooth, morph), staggers and blur radii for motion/react. The same values back foundation's --duration-* and --ease-* CSS variables. From Arc's free arc-motion-tokens (MIT).
The one clock for motion/react. Reach for spring.snappy on presses and toggles, spring.smooth on panels and height changes, spring.morph on shared highlights and widths that follow their content; ease.enter brings something in, ease.exit takes it out faster, ease.inOut moves what is already on screen. foundation carries the same durations and curves as --duration-* and --ease-* for CSS transitions. Animate with m from motion/react-m under @khaeli/motion-provider, which drops movement for readers who ask for reduced motion; branch on useReducedMotion for blur and for anything you move yourself.
Durations and eases
"use client"
import * as m from "motion/react-m"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { SegmentedToggleGroup } from "@/components/ui/segmented-toggle-group"
import { ToggleGroupItem } from "@/components/ui/toggle-group"
import { motionTokens } from "@/lib/motion-tokens"
type Duration = keyof typeof motionTokens.duration
type Ease = keyof typeof motionTokens.ease
export default function MotionTokensDurationsAndEases() {
const [duration, setDuration] = useState<Duration>("standard")
const [ease, setEase] = useState<Ease>("standard")
const [moved, setMoved] = useState(false)
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<SegmentedToggleGroup
aria-label="Duration"
value={[duration]}
onValueChange={([next]) => next && setDuration(next as Duration)}
>
<ToggleGroupItem value="instant">Instant</ToggleGroupItem>
<ToggleGroupItem value="fast">Fast</ToggleGroupItem>
<ToggleGroupItem value="standard">Standard</ToggleGroupItem>
<ToggleGroupItem value="considered">Considered</ToggleGroupItem>
</SegmentedToggleGroup>
<SegmentedToggleGroup aria-label="Ease" value={[ease]} onValueChange={([next]) => next && setEase(next as Ease)}>
<ToggleGroupItem value="enter">Enter</ToggleGroupItem>
<ToggleGroupItem value="standard">Standard</ToggleGroupItem>
<ToggleGroupItem value="inOut">In out</ToggleGroupItem>
<ToggleGroupItem value="exit">Exit</ToggleGroupItem>
</SegmentedToggleGroup>
<div className={`flex rounded-control bg-muted p-1 ${moved ? "justify-end" : "justify-start"}`}>
{/* Under MotionProvider, reduced motion drops the travel and keeps the fade. */}
<m.div
layout
animate={{ opacity: moved ? 1 : 0.5 }}
transition={{ duration: motionTokens.duration[duration], ease: motionTokens.ease[ease] }}
className="size-8 rounded-small bg-primary"
/>
</div>
<Button variant="outline" className="self-start" onClick={() => setMoved(!moved)}>
Play
</Button>
</div>
)
}
Springs
responsivegentlesnappysmoothmorph
"use client"
import * as m from "motion/react-m"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { motionTokens } from "@/lib/motion-tokens"
const springs = ["responsive", "gentle", "snappy", "smooth", "morph"] as const
export default function MotionTokensSprings() {
const [moved, setMoved] = useState(false)
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<ul className="flex flex-col gap-2">
{springs.map((spring) => (
<li key={spring} className="grid grid-cols-[6rem_1fr] items-center gap-3">
<code className="font-mono text-sm text-muted-foreground">{spring}</code>
<div className={`flex rounded-control bg-muted p-1 ${moved ? "justify-end" : "justify-start"}`}>
{/* Under MotionProvider, reduced motion drops the travel and keeps the fade. */}
<m.div
layout
animate={{ opacity: moved ? 1 : 0.5 }}
transition={motionTokens.spring[spring]}
className="size-6 rounded-small bg-primary"
/>
</div>
</li>
))}
</ul>
<Button variant="outline" className="self-start" onClick={() => setMoved(!moved)}>
Play
</Button>
</div>
)
}
Stagger and blur
- Write the migration guide
- Add shortcuts to the editor
- Fix the export time zone
- Review the pricing page copy
- Confirm the launch date
"use client"
import { useReducedMotion } from "motion/react"
import * as m from "motion/react-m"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { motionTokens } from "@/lib/motion-tokens"
const { blur, duration, ease, stagger } = motionTokens
const tasks = [
"Write the migration guide",
"Add shortcuts to the editor",
"Fix the export time zone",
"Review the pricing page copy",
"Confirm the launch date",
]
export default function MotionTokensStaggerAndBlur() {
const [run, setRun] = useState(0)
const reduce = useReducedMotion()
// Movement and blur go with reduced motion; the fade stays.
const hidden = reduce ? { opacity: 0 } : { opacity: 0, y: 8, filter: `blur(${blur.soft}px)` }
return (
<div className="flex w-full max-w-sm flex-col items-start gap-4">
<ul key={run} className="flex w-full flex-col divide-y divide-border border-y border-border">
{tasks.map((task, index) => (
<m.li
key={task}
initial={run === 0 ? false : hidden}
animate={{ opacity: 1, y: 0, filter: "blur(0px)" }}
transition={{ duration: duration.standard, ease: ease.enter, delay: index * stagger.item }}
className="py-2"
>
{task}
</m.li>
))}
</ul>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Play
</Button>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/motion-tokensbunx --bun shadcn@latest add @khaeli/motion-tokensInstalls with
Nothing else. This item needs no other Registry item and no npm package.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/motion-tokens.json