Typix LogoTypix
Components

CharacterLimit

Live character and word counter with a warning threshold — drop-in for blogs, comments, or any length-constrained input.

CharacterLimit reads the editor state, computes characters + words, and renders a counter that turns orange/red as the user approaches the limit. Pair it with extension-character-limit to actually prevent typing past the cap.

Install

npx typix ui add character-limit

Import

import {
  CharacterLimit,
  CharacterLimitCounter,
  useCharacterCount,
} from "@/components/typix/main/character-limit";

CharacterLimit props

PropTypeDefaultDescription
maxLengthnumberMaximum characters allowed. Required.
charset"UTF-8" | "UTF-16""UTF-16"How to count bytes. UTF-16 ≈ string.length.
warningThresholdnumber0.1Enter warning state when remaining < this fraction of maxLength.

CharacterLimitCounter props

Use the counter directly when you compute the count elsewhere:

PropTypeDefaultDescription
countnumberCurrent character count. Required.
maxLengthnumberMaximum allowed. Required.
wordsnumberWord count (only shown when showWords is true).
warningThresholdnumber0.1Warning state threshold.
showWordsbooleanfalseRender word count alongside characters.
classNamestringExtra class on the counter.

Hook

useCharacterCount returns live stats — useful for custom UIs:

const { characters, words } = useCharacterCount({ charset: "UTF-16" });

Usage

import { CharacterLimit } from "@/components/typix/main/character-limit";

<div className="flex justify-end p-2">
  <CharacterLimit maxLength={280} warningThreshold={0.15} />
</div>

On this page