Framer Motion & Animations
Relevant source files
The following files were used as context for generating this wiki page:
The OpenChat project utilizes Framer Motion (via the motion/react package) to provide a delightful, interactive, and high-performance user interface. Animations are strategically implemented to clarify cause-and-effect relationships, such as the appearance of chat suggestions, the expansion of research sources, or the rendering of AI-generated content.
The animation system adheres to strict design guidelines that prioritize accessibility—specifically honoring the prefers-reduced-motion media query—and performance by focusing on compositor-friendly properties like transform and opacity.
Sources: agent_rules/design_guidelines.md:50-58, src/lib/motion.ts
Core Animation Principles
OpenChat follows a specific set of rules to ensure animations enhance rather than detract from the user experience:
- Accessibility: All components MUST provide a reduced-motion variant or disable animations entirely when
prefers-reduced-motionis detected. - Performance: Animations MUST target compositor-friendly properties (
transform,opacity) and NEVER animate layout-triggering properties liketop,left,width, orheightunless necessary for specific UI patterns like morphing. - Intentionality: Motion should only be used to clarify UI state changes or provide deliberate "delight."
- Interruption: Animations are designed to be interruptible and input-driven rather than autoplaying loops.
Sources: agent_rules/design_guidelines.md:50-58
Animation Architecture and State Flow
The animation system is integrated into functional React components using hooks like useReducedMotion. This allows components to dynamically adjust their motion variants based on system settings.
The diagram shows how the system branches animation logic based on user accessibility preferences before committing to GPU-accelerated rendering.
Sources: src/components/chat-input/suggestions.tsx:28-30, agent_rules/design_guidelines.md:50-51
Implementation Patterns
1. Shared Motion Configurations
The project centralizes transition constants to maintain visual consistency across different features.
| Configuration Name | Type | Value / Characteristics |
|---|---|---|
TRANSITION_SUGGESTIONS | Spring | Duration: 0.2s, Bounce: 0 |
STREAMDOWN_ANIMATION | Custom | blurIn, Duration: 220ms, Easing: ease-out, Split by: word |
SPRING_TRANSITION | Spring | Type-based spring for UI interactions |
Sources: src/lib/motion.ts, src/components/prompt-kit/markdown.tsx:18-23
2. Suggestion Grid Animations
The Suggestions component uses AnimatePresence with popLayout mode to handle the transition between the primary suggestion grid and category-specific lists. It applies staggered delays to items using index-based calculations.
Sequence illustrating the smooth handoff between different UI states in the suggestion system.
3. Streamed Content Animations
AI responses are rendered using Streamdown, which applies a blurIn animation as words appear. This mitigates the jarring effect of rapid text insertion during streaming.
const STREAMDOWN_ANIMATION = {
animation: "blurIn",
duration: 220,
easing: "ease-out",
sep: "word" as const,
};
Sources: src/components/prompt-kit/markdown.tsx:18-23, src/components/chat/message-assistant.tsx:500-510
4. Morphing and Dialogs
Complex components like MorphingDialog use coordinated transitions between a trigger (e.g., a thumbnail) and a container (the full dialog). This utilizes framer-motion to interpolate between two different layout states.
Sources: src/components/motion-primitives/morphing-dialog.tsx, src/components/chat/message-assistant.tsx:310-330
Accessibility Integration
Components utilize the useReducedMotion hook from motion/react to switch between elaborate variants (involving y offsets and blur) and simplified variants (simple opacity fades).
variants={
shouldReduceMotion
? {
initial: { opacity: 0 },
animate: { opacity: 1 },
exit: { opacity: 0 },
}
: {
initial: { opacity: 0, y: 10, filter: "blur(4px)" },
animate: { opacity: 1, y: 0, filter: "blur(0px)" },
exit: { opacity: 0, y: -10, filter: "blur(4px)" },
}
}
Sources: src/components/chat-input/suggestions.tsx:88-100
Key Components and Files
src/lib/motion.ts: Central repository for shared motion constants and reusable transition objects.src/components/chat-input/suggestions.tsx: Implements complex grid transitions with staggered item entry.src/components/chat/sources-list.tsx: UsesAnimatePresenceto animate the height and opacity of the search source expansion.src/components/motion-primitives/morphing-dialog.tsx: Provides the structural logic for layout-morphing animations used in image previews.agent_rules/design_guidelines.md: Defines the technical constraints and performance requirements for all animations in the project.
In summary, the animation system in OpenChat is a blend of accessibility-conscious design and modern Framer Motion techniques, ensuring that the interface remains fluid and informative across all device types and user preferences.