Skip to main content

TypewriterText Component

The TypewriterText component provides an animated typing effect with adaptive speed based on text length. It supports markdown rendering, customizable delays, and optional prefix styling.

Features

  • Adaptive Speed: Automatically adjusts typing speed based on text length
  • Markdown Support: Built-in markdown rendering with prefix support
  • Customizable Cursor: Optional blinking cursor with styling
  • Prefix Support: Special styling for prefixed content
  • Performance Optimized: Uses Framer Motion for smooth animations

Import

Basic Usage

Props

Adaptive Speed

The component automatically adjusts typing speed based on text length:
  • Short texts (≤30 words): Use maxCharDelay (slower)
  • Long texts (≥400 characters): Use minCharDelay (faster)
  • Medium texts: Exponential interpolation between min and max

Custom Speed

Override adaptive speed by setting a custom charDelay:

Prefix Styling

Use prefixes for special highlighting (useful for chat interfaces):

Callbacks

Markdown Support

The component supports full markdown rendering when renderAsMarkdown is true:

Custom Cursor

Advanced Example

Integration with Cedar OS

The component automatically integrates with Cedar OS styling system:
  • Uses useStyling() hook for consistent theming
  • Cursor color matches the current color scheme
  • Prefix styling uses accent colors
  • Markdown rendering follows Cedar OS design patterns

Performance Notes

  • Uses Framer Motion’s animate function for optimal performance
  • Automatically cleans up animations on unmount
  • Efficient re-rendering with dependency tracking
  • Smooth 60fps animations with hardware acceleration