Overview

The Avatar component renders a compact identity element (initials or glyph) useful for user lists and headers.

Installation

npm i nikcli-tui

Import

import { Avatar } from 'nikcli-tui';

Quick Start

new Avatar({ parent: screen, initials: 'NE' });

Live Preview

Run Locally

  • Quick preview: npm run tsx:core-gallery
  • Built preview: npm run start:core-gallery

Production Examples

import blessed from 'blessed';
import { Avatar } from 'nikcli-tui';

const screen = blessed.screen({ smartCSR: true, title: 'Avatar Demo' });
const avatar = new Avatar({ parent: screen, top: 1, left: 2, initials: 'NE' });
screen.key(['q','C-c'], () => process.exit(0));
screen.render();

Props

Avatar-specific Props

PropertyTypeRequiredDefaultDescription
srcstringNo-Image source URL (optional)
initialsstringNo-User initials to display (1-3 characters)
shape"circle" | "square"No-Avatar shape style
size"sm" | "md" | "lg"No"md"Avatar size (from component-schemas.ts)

Inherited Base Props

The Avatar 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, etc.)
disabledbooleanfalseWhether component is disabled
hiddenbooleanfalseWhether component is hidden
focusablebooleantrueWhether component can receive focus
scrollablebooleanfalseWhether component is scrollable

Layout & Positioning Props

PropertyTypeDescription
topTerminalUnitTop position
leftTerminalUnitLeft position
rightTerminalUnitRight position
bottomTerminalUnitBottom position
widthTerminalUnitComponent width
heightTerminalUnitComponent height
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
styleTextStyleText styling (bold, underline, etc.)
animationAnimationTypeAnimation type

Zod Schema Validation

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

const AvatarSchema = BasePropsSchema.extend({
  // Avatar content
  src: z.string().optional(), // Image source
  initials: z.string().min(1).max(3).optional(), // User initials
  
  // Avatar styling
  shape: z.enum(["circle", "square"]).optional(),
}).strict();

Methods

Instance Methods

MethodParametersReturn TypeDescription
setInitialsinitials: stringvoidUpdates the avatar initials content
setAvatarSizesize: "sm" | "md" | "lg"voidChanges avatar size and re-renders
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<AvatarProps>voidUpdates component properties

Static Methods

MethodParametersReturn TypeDescription
Avatar.createprops: AvatarPropsAvatarFactory method to create new avatar instance

Keyboard & Accessibility

  • Focusable when parent container manages focus; navigation via Tab/Shift+Tab.
  • No interactive behavior by default (read-only visual element).

Theming

  • Honors global theme and BaseProps variant/tone for consistent brand styling.

Testing

// Mount and assert dimensions
const a = new Avatar({ parent: screen, initials: 'QA', size: 'sm' });
expect(a.el.width).toBe(3);
expect(a.el.height).toBe(2);

Best Practices

  • Keep initials to 2–3 chars per terminal width constraints.
  • Use size mapping (sm/md/lg) for consistent layout across views.