Join our Discord community
Interactive

Counter

Interactive counter component with animated number display and increment/decrement buttons. Perfect for React applications requiring numeric input controls with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/counter.json
npx shadcn@latest add https://www.shadcn.io/registry/counter.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/counter.json
bunx shadcn@latest add https://www.shadcn.io/registry/counter.json

Features

  • Animated number display using the SlidingNumber component for smooth digit transitions
  • Interactive buttons with hover and tap animations using Motion for engaging feedback
  • Customizable styling with flexible button and number display configuration options
  • Layout animations with automatic resizing and smooth transitions between states
  • TypeScript support with complete interface definitions and prop validation
  • shadcn/ui integration using Button components and consistent design patterns

Use Cases

This free open source React component works well for:

  • Quantity selectors - Product quantity controls in e-commerce built with Next.js
  • Settings panels - Numeric configuration options using TypeScript and Tailwind CSS
  • Form inputs - Stepper inputs for numeric values with validation
  • Gaming interfaces - Score counters and game statistics with animated updates

API Reference

Counter

PropTypeDefaultDescription
numbernumberrequiredCurrent counter value to display
setNumber(number: number) => voidrequiredFunction to update the counter value
slidingNumberPropsOmit<SlidingNumberProps, 'number'>-Props passed to the SlidingNumber component
buttonPropsOmit<React.ComponentProps<typeof Button>, 'onClick'>-Props passed to both increment and decrement buttons
transitionTransition{type: 'spring', bounce: 0, stiffness: 300, damping: 30}Motion transition configuration for layout animations

Button Styling

The component uses shadcn/ui Button components with default styling:

  • Background: White (light mode) / Neutral-950 (dark mode)
  • Hover effects: Reduced opacity with smooth transitions
  • Size: Icon size with centered +/- symbols
  • Animations: Scale effects on hover (1.05x) and tap (0.95x)

Implementation Notes

  • Uses controlled state pattern requiring external state management
  • Integrates SlidingNumber component for smooth digit transitions
  • Motion animations provide tactile feedback on button interactions
  • Layout prop enables automatic container resizing animations
  • Compatible with shadcn/ui theming and design tokens
  • Optimized for accessibility with proper button semantics