Damage Numbers
NewPro
Floating combat text with arcs, fades and punchy critical hits, fired from a spawn() call and drawn from a fixed pool of elements.
Customize
5
20%
48
1
#ff784f
When to use it
- Action RPG and auto-battler fights with many hits per second
- Idle and clicker games where every tap shows what it earned
- Score, combo or coin popups in casual and arcade games
Good to know
- Plan
- Pro
- Dependencies
- None beyond React
- Rendering
- DOM and CSS
- Reduced motion
- Respected
- Lines of code
- 292
Installation
Damage Numbers is part of Pro. After purchase you're invited to the private mekai-ui/mekai-ui-pro GitHub repository: copy damage-numbers.tsx into components/ui.
Usage
import { useRef } from "react";
import { DamageNumbers, type DamageNumbersHandle } from "@/components/ui/damage-numbers";
export function Arena() {
const numbers = useRef<DamageNumbersHandle>(null);
function hit(e: React.MouseEvent<HTMLElement>) {
const damage = 120 + Math.round(Math.random() * 80);
const crit = Math.random() < 0.2;
numbers.current?.spawnAt(e.currentTarget, { value: crit ? damage * 2 : damage, kind: crit ? "crit" : "hit" });
}
return (
<div className="relative h-80">
<button onClick={hit}>Attack</button>
<DamageNumbers ref={numbers} />
</div>
);
}Props
9 properties| Property | Type | Default | Description |
|---|---|---|---|
| ref | Ref<DamageNumbersHandle> | — | Gives you spawn(), spawnAt(), clear() and active(). |
| poolSize | number | 48 | Most numbers on screen at once. The oldest is reused when a new one needs room. |
| color | string | "#ff784f" | Color of normal hits. |
| critColor | string | "#ffc24a" | Color of critical hits. |
| healColor | string | "#6ee09a" | Color of healing. |
| scale | number | 1 | Size multiplier for all numbers. |
| spread | number | 1 | How far numbers fly out to the sides. 0 sends them straight up. |
| lifetime | number | 0.95 | Seconds a normal hit stays on screen. Other kinds scale from it. |
| className | string | — | Extra classes for the layer. |