Skip to content
Confirmation input component for Ink
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig
.gitattributes
.gitignore
.npmrc
.travis.yml
index.js
license
package.json
readme.md
test.js

readme.md

ink-confirm-input Build Status

Confirmation input component for Ink

Install

$ npm install ink-confirm-input

Usage

const {h, render, Component} = require('ink');
const ConfirmInput = require('ink-confirm-input');

class UnicornQuestion extends Component {
	constructor() {
		super();
		this.handleChange = this.handleChange.bind(this);
		this.handleSubmit = this.handleSubmit.bind(this);
		this.state = {
			answer: null,
			input: ''
		};
	}

	handleChange(val) {
		this.setState({input: val});
	}

	handleSubmit(val) {
		if (!val) {
			this.setState({answer: 'You are heartless…'});
			return;
		}

		this.setState({answer: 'You love unicorns!'});
	}

	render() {
		const {answer, input} = this.state;

		return (
			<div>
				Do you like unicorns? (Y/n)

				<ConfirmInput
					checked
					value={input}
					onChange={this.handleChange}
					onSubmit={this.handleSubmit}
				/>

				{answer && answer}
			</div>
		);
	}
}

render(<UnicornQuestion/>);

API

<ConfirmInput/>

checked

Type: boolean

Whether to return true or false by default.

value

Type: string

Value to display in a text input.

placeholder

Type: string

Text to display when value is empty.

onChange

Type: Function

Function to call when value updates. Returns a string with the input.

onSubmit

Type: Function

Function to call when user press Enter. Returns a boolean for the answer.

License

MIT © Kevin Mårtensson

You can’t perform that action at this time.