Overview

Compact label for statuses, categories, and annotations.

Installation

npm i nikcli-tui

Import

import { Badge } from "nikcli-tui";

Quick Start

new Badge({ parent: screen, text: "New", variant: "success" });

Live Preview

Run Locally

npm run tsx:core-gallery

Production Examples

new Badge({ parent: screen, top: 1, left: 2, text: "Info", variant: "info" });
new Badge({
  parent: screen,
  top: 1,
  left: 12,
  text: "Warn",
  variant: "warning",
});
new Badge({ parent: screen, top: 1, left: 22, text: "OK", variant: "success" });
new Badge({ parent: screen, top: 1, left: 30, text: "Err", variant: "error" });

Props

Badge-specific Props

PropertyTypeRequiredDefaultDescription
childrenstring | anyNo-Badge content text or child components
dotbooleanNofalseDisplay as a dot indicator (● symbol)
roundedbooleanNofalseApply rounded styling
countnumberNo-Show numeric count instead of text (must be >= 0)
textstringNo-Badge text (from component-schemas.ts)
colorstringNo-Badge color override

Inherited Base Props

The Badge component extends BasePropsSchema and includes all standard TUI component properties:
PropertyTypeDefaultDescription
parentblessed.Widgets.Node-Parent blessed element
classNamestring-CSS-like class name for styling
idstring-Unique identifier
variantComponentVariant"default"Component variant (primary, secondary, destructive, success, warning, error, info, etc.)
sizeComponentSize-Component size (xs, sm, md, lg, xl)
disabledbooleanfalseWhether component is disabled
hiddenbooleanfalseWhether component is hidden
focusablebooleantrueWhether component can receive focus

Layout & Positioning Props

PropertyTypeDescription
topTerminalUnitTop position
leftTerminalUnitLeft position
rightTerminalUnitRight position
bottomTerminalUnitBottom position
widthTerminalUnitComponent width (defaults to “shrink”)
heightTerminalUnitComponent height (defaults to 1)
paddingPaddingConfigInternal spacing
marginPaddingConfigExternal spacing

Style Props

PropertyTypeDescription
bgColorValueBackground color
fgColorValueForeground color
borderBorderStyleBorder configuration
borderColorColorValueBorder color
borderStyle"line" | "double" | "round" | "bold" | "classic" | "none"Border style helper (defaults to “none”)
styleTextStyleText styling (bold, underline, etc.)
animationAnimationTypeAnimation type

Zod Schema Validation

The Badge component uses Zod for runtime type validation:
import { BadgeSchema } from 'nikcli-tui';

const BadgeSchema = BasePropsSchema.extend({
  // Content
  children: z.union([z.string(), z.any()]).optional(),
  
  // Badge-specific styling
  dot: z.boolean().optional(),
  rounded: z.boolean().optional(),
  count: z.number().min(0).optional(), // Show count instead of text
}).strict();

Methods

Instance Methods

MethodParametersReturn TypeDescription
setContentcontent: stringvoidUpdates the badge text content
setCountcount: numbervoidSets numeric count display (≥ 0)
setDotdot: booleanvoidToggle dot indicator mode
destroy-voidCleanup method from base component

Inherited Methods (from BaseComponent)

MethodParametersReturn TypeDescription
setVariantvariant: ComponentVariantvoidUpdates component variant
setSizesize: ComponentSizevoidUpdates component size
setStatestate: ComponentStatevoidUpdates component state
getConfig-ComponentConfigReturns current configuration
updateprops: Partial<BadgeProps>voidUpdates component properties

Static Methods

MethodParametersReturn TypeDescription
Badge.createprops: BadgePropsBadgeFactory method to create new badge instance

Best Practices

  • Keep text short (≤ 10 chars) to prevent wrapping in narrow terminals.
  • Use tone/variant consistently across the app for predictable semantics.