Overview

Simple boolean toggle input.

Import

import { Checkbox } from 'nikcli-tui';

Usage

new Checkbox({ parent: screen, label: 'Accept terms' });

Live Preview

Run Locally

npm run tsx:core-gallery

Props

Checkbox-specific Props

PropertyTypeRequiredDefaultDescription
textstringNo-Label content for the checkbox
checkedbooleanNofalseInitial checked state
labelstringNo-Label text (from component-schemas and BasePropsSchema)
indeterminatebooleanNo-Indeterminate state (from component-schemas)
onChange(checked: boolean) => voidNo-Callback fired when checkbox state changes

Inherited Base Props

The Checkbox 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.)
sizeComponentSize-Component size (xs, sm, md, lg, xl)
disabledbooleanfalseWhether component is disabled
hiddenbooleanfalseWhether component is hidden
focusablebooleantrueWhether component can receive focus
keysbooleantrueEnable keyboard input
mousebooleantrueEnable mouse input

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 (defaults to “none”)
styleTextStyleText styling (bold, underline, etc.)
animationAnimationTypeAnimation type

Zod Schema Validation

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

const CheckboxSchema = BasePropsSchema.extend({
  // Checkbox content
  text: z.string().optional(),
  
  // Checkbox state
  checked: z.boolean().optional(),
  
  // Event handlers
  onChange: z.function().args(z.boolean()).returns(z.void()).optional(),
}).strict();

Methods

Instance Methods

MethodParametersReturn TypeDescription
setTexttext: stringvoidUpdates the checkbox label text
setCheckedchecked: booleanvoidSets the checked state
toggle-voidToggles the checkbox state
isChecked-booleanReturns current checked state
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<CheckboxProps>voidUpdates component properties

Static Methods

MethodParametersReturn TypeDescription
Checkbox.createprops: CheckboxPropsCheckboxFactory method to create new checkbox instance

Events

The Checkbox component supports the following events:
  • check: Fired when checkbox is checked (triggers onChange with true)
  • uncheck: Fired when checkbox is unchecked (triggers onChange with false)

Installation

npm i nikcli-tui

Import

import { Checkbox } from 'nikcli-tui';

Quick Start

new Checkbox({ parent: screen, label: 'I agree', checked: false, onChange: v => console.log('checked:', v) });

Production Examples

let accepted = false;
const cb = new Checkbox({ parent: screen, top: 1, left: 2, label: 'Accept terms', checked: accepted, onChange: (v) => { accepted = v; } });

Testing

const c = new Checkbox({ parent: screen, label: 'X' });
c.setChecked(true);
expect(c.isChecked()).toBe(true);

Best Practices

  • Aggiungi scorciatoie da tastiera a livello di app per togglare rapidamente impostazioni comuni.