@pheonixcoder/ink-confirm-input

1.0.3 • Public • Published

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,
		};
	}

	handleChange(val) {
		console.log(`Change: ${val}`)
	}

	handleSubmit(val) {
        this.setState({ answer: val ? 'You love unicorns!' : 'You are heartless…' });
        
        setTimeout(() => {
            // eslint-disable-line unicorn/no-process-exit
            process.exit(0);
        }, 200);
	}

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

		return (
			<div>
				<ConfirmInput
                    defaultValue="No"
                    externalSeparators="Parenthesis"
                    question="Do you like unicorns?"
					onChange={this.handleChange}
					onSubmit={this.handleSubmit}
				/>
				{answer && answer}
			</div>
		);
	}
}

render(<UnicornQuestion/>);

API

<ConfirmInput/>

question

Type: string

The message you want to show before asking the input.

defaultValue

Type: enum(Yes, No)

Default: Yes

The default value of the input. The default value is shown in UpperCase.

externalSeparators

Type: enum(Nothing, Parenthesis, Brackets)

Default: Brackets

The external separator that is shown around the Yes No options.

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

Dependents (0)

Package Sidebar

Install

npm i @pheonixcoder/ink-confirm-input

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

8.22 kB

Total Files

4

Last publish

Collaborators

  • balwant