Anticipation
AnticipationPrimitive is a wrapper that plays a short three-beat motion (a small pull-back, an overshoot past the target, then a settle) whenever its trigger value changes. It is built on Motion's motion.div and exposes distance, anticipation, follow-through, duration, and easing controls.
shadcn add · no workarounds · theme neutral (none shipped)Installation
Requires @motion-lexicon in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { AnticipationPrimitive } from "@/components/motion-lexicon/primitives/anticipation";<AnticipationPrimitive trigger={selectedId}> <div>{selectedLabel}</div></AnticipationPrimitive>- Give a physical sense of weight and recoil to a UI element that reacts to a state change, such as a counter, badge, or selected item.
- Emphasize a confirmation or success moment (for example after a submit or a toggle) with a playful overshoot.
- Teach or demonstrate the animation principles of anticipation, follow-through, and squash-and-stretch in a motion design lexicon or portfolio.
- Avoid for dense data tables, frequently updating text streams, or any content where repeated horizontal movement would be distracting.
Examples
Counter that reacts to clicks
Replays the anticipation motion each time the count changes. Changing trigger remounts the wrapper, so the animation restarts from its initial frame.
import { useState } from "react";import { AnticipationPrimitive } from "@/components/motion-lexicon/primitives/anticipation";export default function ClickCounter() { const [count, setCount] = useState(0); return ( <div> <button type="button" onClick={() => setCount((c) => c + 1)}> Add </button> <AnticipationPrimitive trigger={count} distance={24}> <span>Clicked {count} times</span> </AnticipationPrimitive> </div> );}Stronger overshoot for a success badge
Raises distance and anticipation to exaggerate the recoil, and uses a slightly longer duration for a more pronounced settle.
import { AnticipationPrimitive } from "@/components/motion-lexicon/primitives/anticipation";export default function SavedBadge({ savedAt }: { savedAt: number }) { return ( <AnticipationPrimitive trigger={savedAt} distance={48} anticipation={0.3} followThrough={0.2} duration={0.7} className="inline-flex rounded-full bg-emerald-600 px-3 py-1 text-sm text-white" > Saved </AnticipationPrimitive> );}Selected list item with custom easing
Triggers on selection change and uses a custom cubic-bezier easing array for a softer landing.
import { AnticipationPrimitive } from "@/components/motion-lexicon/primitives/anticipation";export default function MenuItem({ id, label, active }: { id: string; label: string; active: boolean }) { return ( <AnticipationPrimitive trigger={active ? id : "idle"} easing={[0.22, 1, 0.36, 1]} distance={16} className="block rounded-md px-3 py-2" > {label} </AnticipationPrimitive> );}API reference
Accessibility
- Under prefers-reduced-motion (detected with useReducedMotion), the horizontal translation and scale are replaced by a short opacity fade from 0.65 to 1 over 0.14 seconds, which avoids large spatial movement.
- The component adds no ARIA roles, labels, or live-region announcements. If the trigger change conveys meaning (for example a new count or a saved state), expose that information in the children text or wrap the component in an element with role="status" or aria-live="polite".
- Because the wrapper is a plain div, it does not alter focus order or keyboard behavior. Keep interactive elements inside children with their own semantics.
- Avoid triggering the animation on rapid, repeated changes to the same content, since constant motion can be distracting for some users.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Anticipation" component (motion-lexicon/primitive-anticipation) from its shadcn registry.1. Install it with: npx shadcn@latest add @motion-lexicon/primitive-anticipation2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: trigger, children, distance, anticipation, followThrough, duration, easing, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { AnticipationPrimitive } from "@/components/motion-lexicon/primitives/anticipation";<AnticipationPrimitive trigger={selectedId}> <div>{selectedLabel}</div></AnticipationPrimitive>```Files & dependencies
- src/registry/primitives/anticipation.tsx→ components/motion-lexicon/primitives/anticipation.tsx