Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ink-checkbox-list

MaxMEllon11MIT1.3.1

Checkbox list component for ink.

ink, text, input, component, jsx, react, stdin

readme

ink-checkbox-list Build Status XO code style

Checkbox list component for Ink

Demo

Demo Image

Install

$ npm install ink-checkbox-list

Usage

const {h, render} = require('ink');
const {List, ListItem} = require('ink-checkbox-list');

render(
    <List
        onSubmit={(list) => {
            console.log(list)
            process.exit(0);
        }}
    >
        <ListItem value="1">option1</ListItem>
        <ListItem value="2">option2</ListItem>
        <ListItem value="3">option3</ListItem>
        <ListItem value="4">option4</ListItem>
    </List>
);

Note:

Use this snippet to enable keypress events:

const readline = require('readline');

readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);

Props

List

checkedChar

Type: string Default:

This character is used checked component.

uncheckedChar

Type: string Default:

This character is used unchecked component.

cursorChar

Type: string Default:

This character is used current cursor line.

onChange

Type: Function

Function to call when you pressed <kbd>Space</kbd> key.

onSubmit

Type: Function

Function to call when you pressed <kbd>Enter</kbd> key.

ListItem

value

Type: string Required

onChange()/onSubmit() is used this props. Callback function return value list.

Key bindings

key action
<kbd>Space</kbd> toggle check/uncheck
<kbd>Enter</kbd> submit item list
<kbd>↑</kbd> move to up a cursor
<kbd>↓</kbd> move to down a cursor

LICENSE

MIT © 2017 MaxMellon