Add type info for choice, group, and item (#609)

Refs: 551
This commit is contained in:
Dieter Luypaert 2019-07-03 11:43:57 +02:00 committed by Josh Johnson
parent 62ccd923ff
commit 061219cb00
2 changed files with 40 additions and 8 deletions

View file

@ -1 +1,2 @@
node_modules/ node_modules/
types/

47
types/index.d.ts vendored
View file

@ -1,8 +1,8 @@
// Type definitions for Choices.js 3.0.2 // Type definitions for Choices.js 7.0.0
// Project: https://github.com/jshjohnson/Choices // Project: https://github.com/jshjohnson/Choices
// Definitions by: Arthur vasconcelos <https://github.com/arthurvasconcelos>, Josh Johnson <https://github.com/jshjohnson>, Zack Schuster <https://github.com/zackschuster> // Definitions by: Arthur vasconcelos <https://github.com/arthurvasconcelos>, Josh Johnson <https://github.com/jshjohnson>, Zack Schuster <https://github.com/zackschuster>
// Definitions: https://github.com/jshjohnson/Choices // Definitions: https://github.com/jshjohnson/Choices
// TypeScript Version: 2.6.2 // TypeScript Version: 2.9.2
// Choices Namespace // Choices Namespace
declare namespace Choices { declare namespace Choices {
@ -16,6 +16,19 @@ declare namespace Choices {
type callbackOnCreateTemplates = (template: strToEl) => Choices.Templates; type callbackOnCreateTemplates = (template: strToEl) => Choices.Templates;
} }
interface Choice {
customProperties?: { [prop: string]: any };
disabled?: boolean;
elementId?: string;
groupId?: string;
id?: string;
keyCode?: number;
label: string;
placeholder?: any;
selected?: boolean;
value: any;
}
/** /**
* Events fired by Choices behave the same as standard events. Each event is triggered on the element passed to Choices (accessible via `this.passedElement`. Arguments are accessible within the `event.detail` object. * Events fired by Choices behave the same as standard events. Each event is triggered on the element passed to Choices (accessible via `this.passedElement`. Arguments are accessible within the `event.detail` object.
*/ */
@ -111,6 +124,24 @@ declare namespace Choices {
"hideDropdown": CustomEvent; "hideDropdown": CustomEvent;
} }
interface Group {
active?: boolean;
disabled?: boolean;
id?: string;
value: any;
}
interface Item {
choiceId?: string;
customProperties?: { [prop: string]: any };
groupId?: string;
id?: string;
keyCode?: number;
label: string;
placeholder?: string;
value: any;
}
interface Templates { interface Templates {
containerOuter?: (direction: string) => HTMLElement; containerOuter?: (direction: string) => HTMLElement;
containerInner?: () => HTMLElement; containerInner?: () => HTMLElement;
@ -682,8 +713,8 @@ export default class Choices {
canSearch: boolean; canSearch: boolean;
placeholder: boolean; placeholder: boolean;
presetChoices: any[]; presetChoices: Choices.Choice[];
presetItems: any[]; presetItems: Choices.Item[];
readonly baseId: string; readonly baseId: string;
@ -849,7 +880,7 @@ export default class Choices {
setChoiceByValue(value: string | string[]): this; setChoiceByValue(value: string | string[]): this;
/** Direct populate choices */ /** Direct populate choices */
setChoices(choices: any[], value: string, label: string, replaceChoices?: boolean): this; setChoices(choices: Choices.Choice[], value: string, label: string, replaceChoices?: boolean): this;
/** /**
* Removes all items, choices and groups. Use with caution. * Removes all items, choices and groups. Use with caution.
@ -904,13 +935,13 @@ export default class Choices {
ajax(fn: (values: any) => any): this; ajax(fn: (values: any) => any): this;
/** Render group choices into a DOM fragment and append to choice list */ /** Render group choices into a DOM fragment and append to choice list */
private createGroupsFragment(groups: any[], choices: any[], fragment: DocumentFragment): DocumentFragment; private createGroupsFragment(groups: Choices.Group[], choices: Choices.Choice[], fragment: DocumentFragment): DocumentFragment;
/** Render choices into a DOM fragment and append to choice list */ /** Render choices into a DOM fragment and append to choice list */
private createChoicesFragment(choices: any[], fragment: DocumentFragment, withinGroup?: boolean): DocumentFragment; private createChoicesFragment(choices: Choices.Choice[], fragment: DocumentFragment, withinGroup?: boolean): DocumentFragment;
/** Render items into a DOM fragment and append to items list */ /** Render items into a DOM fragment and append to items list */
private _createItemsFragment(items: any[], fragment?: DocumentFragment): void; private _createItemsFragment(items: Choices.Item[], fragment?: DocumentFragment): void;
/** Render DOM with values */ /** Render DOM with values */
private render(): void; private render(): void;