From b660c2f3bb3772657f8c22cebaf7369454325e4e Mon Sep 17 00:00:00 2001 From: AndersonFriaca Date: Tue, 13 Feb 2018 01:25:40 -0300 Subject: [PATCH] Types for bootstrap-3-typeahead --- .../bootstrap-3-typeahead-tests.ts | 19 ++++ types/bootstrap-3-typeahead/index.d.ts | 107 ++++++++++++++++++ types/bootstrap-3-typeahead/tsconfig.json | 25 ++++ types/bootstrap-3-typeahead/tslint.json | 1 + 4 files changed, 152 insertions(+) create mode 100644 types/bootstrap-3-typeahead/bootstrap-3-typeahead-tests.ts create mode 100644 types/bootstrap-3-typeahead/index.d.ts create mode 100644 types/bootstrap-3-typeahead/tsconfig.json create mode 100644 types/bootstrap-3-typeahead/tslint.json diff --git a/types/bootstrap-3-typeahead/bootstrap-3-typeahead-tests.ts b/types/bootstrap-3-typeahead/bootstrap-3-typeahead-tests.ts new file mode 100644 index 0000000000..0106ee2db3 --- /dev/null +++ b/types/bootstrap-3-typeahead/bootstrap-3-typeahead-tests.ts @@ -0,0 +1,19 @@ +$(document).ready(() => { + // basic usage + $('#typeahead').typeahead(); + $('#typeahead').typeahead('lookup'); + $('#typeahead').typeahead('lookup', 'Display name 1'); + $('#typeahead').typeahead('getActive'); + $('#typeahead').typeahead('destroy'); + + // with options example + const options: Bootstrap3Typeahead.Options = { + source: [ + {id: 'someId1', name: 'Display name 1'}, + {id: 'someId2', name: 'Display name 2'} + ], + autoSelect: true + }; + + $('#typeahead').typeahead(options); +}); diff --git a/types/bootstrap-3-typeahead/index.d.ts b/types/bootstrap-3-typeahead/index.d.ts new file mode 100644 index 0000000000..98d7eee664 --- /dev/null +++ b/types/bootstrap-3-typeahead/index.d.ts @@ -0,0 +1,107 @@ +// Type definitions for Bootstrap 3 Typeahead 4.0 +// Project: https://github.com/bassjobsen/Bootstrap-3-Typeahead +// Definitions by: Anderson Friaça +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +declare namespace Bootstrap3Typeahead { + interface Options { + /** + * The data source to query against + */ + source?: string[] | object[] | ((query?: string, process?: ((callback: any) => string|string[]|object[])) => void); + + /** + * The max number of items to display in the dropdown + */ + items?: number; + + /** + * The minimum character length needed before triggering autocomplete suggestions + */ + minLength?: number; + + /** + * If hints should be shown as soon as the input gets focus + */ + showHintOnFocus?: boolean | 'all'; + + /** + * Number of pixels the scrollable parent container scrolled down + */ + scrollHeight?: number | (() => number); + + /** + * The method used to determine if a query matches an item + */ + matcher?: (item: string) => boolean; + + /** + * Method used to sort autocomplete results + */ + sorter?: (items: string[]) => string[]; + + /** + * The method used to return selected item + */ + updater?: (item: string) => string; + + /** + * Method used to highlight autocomplete results + */ + highlighter?: (item: string) => string; + + /** + * Method used to get textual representation of an item of the sources + */ + displayText?: (item: string|{name: string}) => string; + + /** + * Allows you to dictate whether or not the first suggestion is selected automatically + */ + autoSelect?: boolean; + + /** + * Call back function to execute after selected an item + */ + afterSelect?: (item: string) => void; + + /** + * Adds a delay between lookups + */ + delay?: number; + + /** + * Use this option to add the menu to another div + */ + appendTo?: JQuery; + + /** + * Set to true if you want the menu to be the same size than the input it is attached to + */ + fitToElement?: boolean; + + /** + * Adds an item to the end of the list + */ + addItem?: object; + } +} +interface JQuery { + /** + * Initialize or destroy Typeahead + */ + typeahead(methodOrOptions?: 'destroy' | Bootstrap3Typeahead.Options): JQuery; + + /** + * To get the currently active item + */ + typeahead(method: 'getActive'): undefined|string|object; + + /** + * To trigger the lookup function externally + */ + typeahead(method: 'lookup', defaultValue?: string): JQuery; +} diff --git a/types/bootstrap-3-typeahead/tsconfig.json b/types/bootstrap-3-typeahead/tsconfig.json new file mode 100644 index 0000000000..d8226518b8 --- /dev/null +++ b/types/bootstrap-3-typeahead/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "bootstrap-3-typeahead-tests.ts" + ] +} \ No newline at end of file diff --git a/types/bootstrap-3-typeahead/tslint.json b/types/bootstrap-3-typeahead/tslint.json new file mode 100644 index 0000000000..4e88071852 --- /dev/null +++ b/types/bootstrap-3-typeahead/tslint.json @@ -0,0 +1 @@ +{"extends": "dtslint/dt.json"}