Merge pull request #33059 from lukostry/ink-text-input

[ink-text-input] Add definitions for ink-text-input
This commit is contained in:
Mine Starks
2019-02-15 08:39:29 -08:00
committed by GitHub
4 changed files with 92 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
// 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';
interface TextInputProps {
focus?: boolean;
onChange?: (value: string) => void;
onSubmit?: (value: string) => void;
placeholder?: string;
value?: string;
}
declare class TextInput extends Component<TextInputProps> { }
export = TextInput;
@@ -0,0 +1,47 @@
/** @jsx h */
import { h, Component } from 'ink';
import TextInput from 'ink-text-input';
// NOTE: `import TextInput = require('ink-text-input');` will work as well
// For importing using ES6 default import as above,
// `allowSyntheticDefaultImports` flag in compiler options needs to be set to `true`
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);
}
}
+25
View File
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }