bigbullui logobigbullui
Componentform

Char Counter

Character counter with near-limit and over-limit states.

Preview

Live Preview
13/140

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add char-counter

Or install the full npm package:

npm install bigbullui

Usage

import { CharCounter } from "@/components/ui/char-counter";

<CharCounter />

Source code

char-counter.tsx

Zero dependencies (only React + utils). Copy and paste directly into your project:

"use client";

import * as React from "react";
import { cn } from "./lib/utils";

export interface CharCounterProps extends React.HTMLAttributes<HTMLSpanElement> {
  value: string;
  max: number;
  label?: string;
}

/** Karakter sayacı: limit aşımında uyarı animasyonu. */
export function CharCounter({ value, max, label, className, ...props }: CharCounterProps) {
  const count = value.length;
  const over = count > max;
  const near = !over && count >= max * 0.9;

  return (
    <span
      className={cn(
        "inline-flex items-center gap-1 font-mono text-[10px] tabular-nums transition-colors duration-200 motion-reduce:transition-none",
        over ? "text-destructive" : near ? "text-amber-600" : "text-muted-foreground",
        over && "animate-pulse motion-reduce:animate-none",
        className
      )}
      aria-live="polite"
      {...props}
    >
      {label && <span>{label}</span>}
      {count.toLocaleString("tr-TR")}/{max.toLocaleString("tr-TR")}
      {over && <span aria-hidden="true">⚠</span>}
    </span>
  );
}

Props

PropTypeDescription
valuestring
maxnumber
labelstring