class Checkbox
extends GenericList<TValue, Array<TValue>, Array<TValue>, CheckboxOptionSettings<TValue>, CheckboxOptionGroupSettings<TValue>>
import { Checkbox } from "https://deno.land/x/cliffy@v1.0.0-rc.1/prompt/checkbox.ts";
Checkbox prompt representation.
Simple prompt:
import { Checkbox } from "./mod.ts";
const colors: Array<string> = await Checkbox.prompt({
message: "Pick some colors",
options: ["red", "green", "blue"],
});
Mixed option types:
import { Checkbox } from "./mod.ts";
const values: Array<string | number> = await Checkbox.prompt<string | number>({
message: "Pick some colors",
options: [1, 2, "3", "4"],
});
None primitive option types:
import { Checkbox } from "./mod.ts";
const dates: Array<Date> = await Checkbox.prompt({
message: "Pick some dates",
options: [
{
name: "Date 1",
value: new Date(100000),
},
{
name: "Date 2",
value: new Date(200000),
},
{
name: "Date 3",
value: new Date(300000),
},
],
});
Grouped options:
import { Checkbox } from "./mod.ts";
const values = await Checkbox.prompt({
message: "Select some values",
options: [{
name: "Group 1",
options: ["foo", "bar", "baz"],
}, {
name: "Group 2",
options: ["beep", "boop"],
}],
});
Constructors
new
Checkbox(options: CheckboxOptions<TValue>)Properties
protected
options: Array<CheckboxOptionSettings<TValue> | CheckboxOptionGroupSettings<TValue>>protected
readonly
settings: CheckboxSettings<TValue>Methods
private
checkOption(option: CheckboxOptionSettings<TValue> | CheckboxOptionGroupSettings<TValue>, checked: boolean)private
getCheckboxIcon(option: CheckboxOptionSettings<TValue> | CheckboxOptionGroupSettings<TValue>): stringprotected
checkValue(): voidCheck selected option.
protected
getListItemIcon(option: CheckboxOptionSettings<TValue> | CheckboxOptionGroupSettings<TValue>): stringprotected
handleEvent(event: KeyCode): Promise<void>Handle user input event.
protected
hint(): string | undefinedprotected
mapOption(options: CheckboxOptions<TValue>, option: CheckboxOption<TValue> | GenericListSeparatorOption): CheckboxOptionSettings<TValue>protected
mapOptionGroup(promptOptions: CheckboxOptions<TValue>, option: CheckboxOptionGroup<TValue>): CheckboxOptionGroupSettings<TValue>protected
mapOptions(promptOptions: CheckboxOptions<TValue>, options: Array<>): Array<CheckboxOptionSettings<TValue> | CheckboxOptionGroupSettings<TValue>>
Map string option values to options and set option defaults.
protected
match(): voidprotected
submit(hasConfirmed?: boolean): Promise<void>getDefaultSettings(options: CheckboxOptions<TValue>): CheckboxSettings<TValue>
Static Methods
Inject prompt value. If called, the prompt doesn't prompt for an input and returns immediately the injected value. Can be used for unit tests or pre selections.
prompt<TValue>(options: CheckboxOptions<TValue>): Promise<Array<WidenType<TValue>>>
Execute the prompt with provided options.