diff --git a/types/vue-select/index.d.ts b/types/vue-select/index.d.ts new file mode 100644 index 0000000000..ff8767e189 --- /dev/null +++ b/types/vue-select/index.d.ts @@ -0,0 +1,98 @@ +// Type definitions for vue-select 2.4 +// Project: https://github.com/sagalbot/vue-select#readme +// Definitions by: Ilia Beliaev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { VueConstructor } from 'vue'; + +export default VueSelect; +export const VueSelect: VueSelectConstructor; +export type OptionConsumer = (option: any) => void; + +export interface VueSelectProps { + value: any; + options: any[]; + disabled: boolean; + maxHeight: string; + searchable: boolean; + multiple: boolean; + placeholder: string; + transition: string; + clearSearchOnSelect: boolean; + closeOnSelect: boolean; + label: string; + getOptionLabel: (option: any) => string; + onChange: OptionConsumer; + taggable: boolean; + tabindex: number | null; + pushTags: boolean; + filterable: boolean; + createOption: (option: any) => any; + resetOnOptionsChange: boolean; + noDrop: boolean; + inputId: string | null; + dir: string; +} + +export interface VueSelectData { + search: string; + open: boolean; + mutableValue: any; + mutableOptions: any[]; +} + +export interface VueSelectWatch { + value: (val: any) => void; + mutableValue: (val: any, old: any) => void; + options: (val: any) => void; + mutableOptions: () => void; + multiple: (reset: boolean) => void; + created: () => void; +} + +export interface VueSelectMethods { + select: OptionConsumer; + deselect: OptionConsumer; + clearSelection: () => void; + onAfterSelect: OptionConsumer; + toggleDropdown: (e: Event) => void; + isOptionSelected: (option: any) => boolean; + onEscape: () => void; + onSearchBlur: () => void; + onSearchFocus: () => void; + maybeDeleteValue: () => void; + optionExists: (option: any) => boolean; + maybePushTag: OptionConsumer; +} + +export interface VueSelectComputed { + dropdownClasses: () => DropdownClasses; + clearSearchOnBlur: () => boolean; + searching: () => boolean; + dropdownOpen: () => boolean; + searchPlaceholder: () => boolean; + filteredOptions: () => any[]; + isValueEmpty: () => boolean; + valueAsArray: () => any[]; + showClearButton: () => boolean; +} + +export interface DropdownClasses { + open: boolean; + single: boolean; + searching: boolean; + searchable: boolean; + unsearchable: boolean; + loading: boolean; + rtl: boolean; + disabled: boolean; +} + +export interface VueSelectConstructor extends VueConstructor { + props: VueSelectProps; + data: () => VueSelectData; + watch: VueSelectWatch; + methods: VueSelectMethods; + computed: VueSelectComputed; +} diff --git a/types/vue-select/package.json b/types/vue-select/package.json new file mode 100644 index 0000000000..faefc1b2f7 --- /dev/null +++ b/types/vue-select/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "vue": ">=2.0.0" + } +} diff --git a/types/vue-select/tsconfig.json b/types/vue-select/tsconfig.json new file mode 100644 index 0000000000..656897ba29 --- /dev/null +++ b/types/vue-select/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "vue-select-tests.ts" + ] +} diff --git a/types/vue-select/tslint.json b/types/vue-select/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/vue-select/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/vue-select/vue-select-tests.ts b/types/vue-select/vue-select-tests.ts new file mode 100644 index 0000000000..8fea33b2dc --- /dev/null +++ b/types/vue-select/vue-select-tests.ts @@ -0,0 +1,65 @@ +import Vue from 'vue'; +import VueSelect from 'vue-select'; + +const options = [ + { + name: 'SomeName' + }, + { + name: 'SomeName2' + } +]; + +new Vue({ + el: '#app', + data: { + options, + value: null, + }, + components: { + 'vue-select': VueSelect + }, + methods: { + getOptionLabel(option: any) { + if (option && option.name) { + return option.name; + } + return ''; + }, + optionConsumer(option: any) { + }, + optionToOption(option: any) { + return option; + }, + onSearch(search: string, loading: (b: boolean) => void) { + loading(true); + } + }, + template: ` + + +` +});