Add definitions for ink-text-input

This commit is contained in:
lukostry
2019-02-14 11:58:29 +01:00
parent d77c47c753
commit f5f34f814e
4 changed files with 86 additions and 0 deletions

17
types/ink-text-input/index.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
// Type definitions for ink-text-input 2.0
// Project: https://github.com/vadimdemedes/ink-text-input#readme
// Definitions by: Łukasz Ostrowski <https://github.com/lukostry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Component } from 'ink';
export interface TextInputProps {
focus?: boolean;
onChange?: (value: string) => void;
onSubmit?: (value: string) => void;
placeholder?: string;
value?: string;
}
export default class TextInput extends Component<TextInputProps> { }

View File

@@ -0,0 +1,44 @@
/** @jsx h */
import { h, Component } from 'ink';
import TextInput from 'ink-text-input';
interface QueryState {
query: string;
}
class SearchQuery extends Component {
constructor() {
super();
this.state = {
query: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
render(props: {}, state: QueryState) {
return (
<div>
Enter your query:
<TextInput
value={state.query}
onChange={this.handleChange}
onSubmit={this.handleSubmit}
/>
</div>
);
}
private handleChange(value: string) {
this.setState({
query: value,
});
}
private handleSubmit(value: string) {
console.log(value);
}
}

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"jsx": "react",
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ink-text-input-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }