Counting Number
Animated counting number with spring transitions and in-view detection. Perfect for React applications requiring smooth number animations with Next.js integration and TypeScript support.
Powered by
Installation
npx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
npx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
bunx shadcn@latest add https://www.shadcn.io/registry/counting-number.json
Features
- Spring animations with customizable stiffness and damping using Motion's useSpring hook
- In-view detection triggers animations when component enters viewport with configurable margins
- Decimal support with customizable separators and precision control for international formatting
- Padding options for consistent width displays with leading zeros and number alignment
- TypeScript support with complete interface definitions for all animation and formatting props
- Performance optimized using Motion values for smooth 60fps animations without re-renders
Examples
Decimal Numbers
Numbers with decimal places and custom separators for international formatting.
From Number Animation
Count down from a starting number to demonstrate reverse animations.
Use Cases
This free open source React component works well for:
- Statistics dashboards - Animated counters for metrics and KPIs in Next.js applications
- Landing pages - Eye-catching number reveals for achievements using TypeScript and Tailwind CSS
- Progress indicators - Dynamic counting for completion percentages and user milestones
- Financial displays - Currency amounts with proper decimal formatting and animations
API Reference
CountingNumber
Prop | Type | Default | Description |
---|---|---|---|
number | number | required | Target number to count towards |
fromNumber | number | 0 | Starting number for the animation |
decimalPlaces | number | 0 | Number of decimal places to display |
decimalSeparator | string | "." | Character used for decimal separation |
padStart | boolean | false | Pad with leading zeros to maintain consistent width |
inView | boolean | false | Only animate when component enters viewport |
inViewMargin | string | "0px" | Margin for in-view detection trigger |
inViewOnce | boolean | true | Only trigger in-view animation once |
transition | SpringOptions | { stiffness: 90, damping: 50 } | Motion spring configuration for animation timing |
className | string | - | CSS classes for styling the number display |
Animation Configuration
- stiffness - Controls animation speed (higher = faster)
- damping - Controls bounce/oscillation (higher = less bounce)
- mass - Controls animation weight (higher = slower start/stop)
Implementation Notes
- Uses Motion's useMotionValue for performance optimization
- In-view detection uses Intersection Observer API
- Number formatting handles negative values and edge cases
- Supports all standard span HTML attributes and events
- Animation automatically cleans up on component unmount
- Decimal separator replacement works with any Unicode character
Theme Toggle Button
Animated dark mode switch with View Transitions API. Beautiful theme toggles for React applications with multiple animation effects and Next.js integration.
Gradient Text
Animated gradient text with flowing color effects and optional neon glow. Perfect for React applications requiring eye-catching typography with Next.js integration and TypeScript support.