diff --git a/types/ink-text-input/index.d.ts b/types/ink-text-input/index.d.ts new file mode 100644 index 0000000000..9aaadd330e --- /dev/null +++ b/types/ink-text-input/index.d.ts @@ -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 +// 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 { } + +export = TextInput; diff --git a/types/ink-text-input/ink-text-input-tests.tsx b/types/ink-text-input/ink-text-input-tests.tsx new file mode 100644 index 0000000000..82b63854a2 --- /dev/null +++ b/types/ink-text-input/ink-text-input-tests.tsx @@ -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 ( +
+ Enter your query: + + +
+ ); + } + + private handleChange(value: string) { + this.setState({ + query: value, + }); + } + + private handleSubmit(value: string) { + console.log(value); + } +} diff --git a/types/ink-text-input/tsconfig.json b/types/ink-text-input/tsconfig.json new file mode 100644 index 0000000000..2582b4325e --- /dev/null +++ b/types/ink-text-input/tsconfig.json @@ -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" + ] +} diff --git a/types/ink-text-input/tslint.json b/types/ink-text-input/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/ink-text-input/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }