Ink select input update for latest version and ink2 support (#34192)

* Update ink-select-input to support latest version and ink2

* Major version up

* Fix travis errors

* Fix travis errors

* Fixed travis errors 3
This commit is contained in:
Kubo Satnik
2019-03-27 16:15:22 -07:00
committed by Ron Buckton
parent e2476bf0eb
commit b36aeafe88
2 changed files with 36 additions and 34 deletions
+10 -7
View File
@@ -1,25 +1,28 @@
// Type definitions for ink-select-input 2.0
// Type definitions for ink-select-input 3.0
// Project: https://github.com/vadimdemedes/ink-select-input#readme
// Definitions by: Łukasz Ostrowski <https://github.com/lukostry>
// Jakub Satnik <https://github.com/shatodj>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Component, InkComponent } from 'ink';
import { Component } from 'react';
interface ItemOfSelectInput {
export interface ItemOfSelectInput {
label: string;
value: any;
key?: string | number;
}
interface SelectInputProps<T extends ItemOfSelectInput = ItemOfSelectInput> {
export interface SelectInputProps<T extends ItemOfSelectInput = ItemOfSelectInput> {
focus?: boolean;
indicatorComponent?: InkComponent;
itemComponent?: InkComponent;
indicatorComponent?: Component;
itemComponent?: Component;
items?: ReadonlyArray<T>;
limit?: number;
initialIndex?: number;
onSelect?: (item: T) => void;
}
declare class SelectInput extends Component<SelectInputProps> { }
export = SelectInput;
export default SelectInput;
@@ -1,32 +1,31 @@
/** @jsx h */
import { h, InkComponent } from 'ink';
import SelectInput from 'ink-select-input';
import * as React from 'react';
// tslint:disable-next-line:import-name
import SelectInput, { ItemOfSelectInput } from 'ink-select-input';
// NOTE: `import SelectInput = require('ink-select-input');` will work as well.
// If importing using ES6 default import as above,
// `allowSyntheticDefaultImports` flag in compiler options needs to be set to `true`
interface DemoItem {
label: string;
value: string;
const items: ReadonlyArray<ItemOfSelectInput> = [
{
label: 'First',
value: 'first',
key: 0,
},
{
label: 'Second',
value: 'second',
},
{
label: 'Third',
value: 'third',
},
];
class Demo extends React.PureComponent {
handleSelect = (item: ItemOfSelectInput) => {};
render() {
return <SelectInput items={items} onSelect={this.handleSelect} />;
}
}
const items: ReadonlyArray<DemoItem> = [{
label: 'First',
value: 'first'
},
{
label: 'Second',
value: 'second'
},
{
label: 'Third',
value: 'third'
}];
const Demo: InkComponent = () => {
const handleSelect = (item: DemoItem) => {
console.log(item);
};
return <SelectInput items={items} onSelect={handleSelect} />;
};