Update types for 3.0.0

This commit is contained in:
Zack Schuster 2017-08-04 14:49:29 -07:00
parent 791eb9a95b
commit 4d2caa129c

393
index.d.ts vendored
View file

@ -3,208 +3,208 @@ declare module "choices.js" {
passedElement: Element; passedElement: Element;
constructor(element?: string | HTMLElement | HTMLCollectionOf<HTMLElement> | NodeList, userConfig?: Choices.Options); constructor(element?: string | HTMLElement | HTMLCollectionOf<HTMLElement> | NodeList, userConfig?: Choices.Options);
new(element?: string | HTMLElement | HTMLCollectionOf<HTMLElement> | NodeList, userConfig?: Choices.Options): this;; new(element?: string | HTMLElement | HTMLCollectionOf<HTMLElement> | NodeList, userConfig?: Choices.Options): this;
/** /**
* Initialise Choices * Initialise Choices
* @return * @return
* @public * @public
*/ */
init(): void; init(): void;
/** /**
* Destroy Choices and nullify values * Destroy Choices and nullify values
* @return * @return
* @public * @public
*/ */
destroy(): void; destroy(): void;
/** /**
* Render group choices into a DOM fragment and append to choice list * Render group choices into a DOM fragment and append to choice list
* @param {Array} groups Groups to add to list * @param {Array} groups Groups to add to list
* @param {Array} choices Choices to add to groups * @param {Array} choices Choices to add to groups
* @param {DocumentFragment} fragment Fragment to add groups and options to (optional) * @param {DocumentFragment} fragment Fragment to add groups and options to (optional)
* @return {DocumentFragment} Populated options fragment * @return {DocumentFragment} Populated options fragment
* @private * @private
*/ */
renderGroups(groups: any[], choices: any[], fragment?: DocumentFragment): DocumentFragment; renderGroups(groups: any[], choices: any[], 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
* @param {Array} choices Choices to add to list * @param {Array} choices Choices to add to list
* @param {DocumentFragment} fragment Fragment to add choices to (optional) * @param {DocumentFragment} fragment Fragment to add choices to (optional)
* @return {DocumentFragment} Populated choices fragment * @return {DocumentFragment} Populated choices fragment
* @private * @private
*/ */
renderChoices(choices: any[], fragment?: DocumentFragment): DocumentFragment; renderChoices(choices: any[], fragment?: DocumentFragment): DocumentFragment;
/** /**
* Render items into a DOM fragment and append to items list * Render items into a DOM fragment and append to items list
* @param {Array} items Items to add to list * @param {Array} items Items to add to list
* @param {DocumentFragment} fragment Fragrment to add items to (optional) * @param {DocumentFragment} fragment Fragrment to add items to (optional)
* @return * @return
* @private * @private
*/ */
renderItems(items: any[], fragment?: DocumentFragment): void; renderItems(items: any[], fragment?: DocumentFragment): void;
/** /**
* Render DOM with values * Render DOM with values
* @return * @return
* @private * @private
*/ */
render(): void; render(): void;
/** /**
* Select item (a selected item can be deleted) * Select item (a selected item can be deleted)
* @param {Element} item Element to select * @param {Element} item Element to select
* @param {boolean} runEvent Whether to highlight immediately or not. Defaults to true. * @param {boolean} runEvent Whether to highlight immediately or not. Defaults to true.
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
highlightItem(item: Element, runEvent?: boolean): this; highlightItem(item: Element, runEvent?: boolean): this;
/** /**
* Deselect item * Deselect item
* @param {Element} item Element to de-select * @param {Element} item Element to de-select
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
unhighlightItem(item: Element): this; unhighlightItem(item: Element): this;
/** /**
* Highlight items within store * Highlight items within store
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
highlightAll(): this; highlightAll(): this;
/** /**
* Deselect items within store * Deselect items within store
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
unhighlightAll(): this; unhighlightAll(): this;
/** /**
* Remove an item from the store by its value * Remove an item from the store by its value
* @param {String} value Value to search for * @param {String} value Value to search for
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
removeItemsByValue(value: string): this; removeItemsByValue(value: string): this;
/** /**
* Remove all items from store array * Remove all items from store array
* @note Removed items are soft deleted * @note Removed items are soft deleted
* @param {Number} excludedId Optionally exclude item by ID * @param {Number} excludedId Optionally exclude item by ID
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
removeActiveItems(excludedId?: number): this; removeActiveItems(excludedId?: number): this;
/** /**
* Remove all selected items from store * Remove all selected items from store
* @note Removed items are soft deleted * @note Removed items are soft deleted
* @param {boolean} runEvent Whether to remove highlighted items immediately or not. Defaults to false. * @param {boolean} runEvent Whether to remove highlighted items immediately or not. Defaults to false.
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
removeHighlightedItems(runEvent?: boolean): this; removeHighlightedItems(runEvent?: boolean): this;
/** /**
* Show dropdown to user by adding active state class * Show dropdown to user by adding active state class
* @param {boolean} focusInput Whether to focus the input or not. Defaults to false. * @param {boolean} focusInput Whether to focus the input or not. Defaults to false.
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
showDropdown(focusInput?: boolean): this; showDropdown(focusInput?: boolean): this;
/** /**
* Hide dropdown from user * Hide dropdown from user
* @param {boolean} focusInput Whether to blur input focus or not. Defaults to false. * @param {boolean} focusInput Whether to blur input focus or not. Defaults to false.
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
hideDropdown(blurInput?: boolean): this; hideDropdown(blurInput?: boolean): this;
/** /**
* Determine whether to hide or show dropdown based on its current state * Determine whether to hide or show dropdown based on its current state
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
toggleDropdown(): this; toggleDropdown(): this;
/** /**
* Get value(s) of input (i.e. inputted items (text) or selected choices (select)) * Get value(s) of input (i.e. inputted items (text) or selected choices (select))
* @param {Boolean} valueOnly Get only values of selected items, otherwise return selected items * @param {Boolean} valueOnly Get only values of selected items, otherwise return selected items
* @return {Array/String} selected value (select-one) or array of selected items (inputs & select-multiple) * @return {Array/String} selected value (select-one) or array of selected items (inputs & select-multiple)
* @public * @public
*/ */
getValue(valueOnly?: boolean): string | string[]; getValue(valueOnly?: boolean): string | string[];
/** /**
* Set value of input. If the input is a select box, a choice will be created and selected otherwise * Set value of input. If the input is a select box, a choice will be created and selected otherwise
* an item will created directly. * an item will created directly.
* @param {Array} args Array of value objects or value strings * @param {Array} args Array of value objects or value strings
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
setValue(args: any[]): this; setValue(args: any[]): this;
/** /**
* Select value of select box via the value of an existing choice * Select value of select box via the value of an existing choice
* @param {Array/String} value An array of strings of a single string * @param {Array/String} value An array of strings of a single string
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
setValueByChoice(value: string | string[]): this; setValueByChoice(value: string | string[]): this;
/** /**
* Direct populate choices * Direct populate choices
* @param {Array} choices - Choices to insert * @param {Array} choices - Choices to insert
* @param {String} value - Name of 'value' property * @param {String} value - Name of 'value' property
* @param {String} label - Name of 'label' property * @param {String} label - Name of 'label' property
* @param {Boolean} replaceChoices Whether existing choices should be removed * @param {Boolean} replaceChoices Whether existing choices should be removed
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
setChoices(choices: any[], value: string, label: string, replaceChoices?: boolean): this; setChoices(choices: any[], value: string, label: string, replaceChoices?: boolean): this;
/** /**
* Clear items,choices and groups * Clear items,choices and groups
* @note Hard delete * @note Hard delete
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
clearStore(): this; clearStore(): this;
/** /**
* Set value of input to blank * Set value of input to blank
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
clearInput(): this; clearInput(): this;
/** /**
* Enable interaction with Choices * Enable interaction with Choices
* @return {Object} Class instance * @return {Object} Class instance
*/ */
enable(): this; enable(): this;
/** /**
* Disable interaction with Choices * Disable interaction with Choices
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
disable(): this; disable(): this;
/** /**
* Populate options via ajax callback * Populate options via ajax callback
* @param {Function} fn Passed * @param {Function} fn Passed
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
ajax(fn: (values: any) => any): this; ajax(fn: (values: any) => any): this;
} }
namespace Choices { namespace Choices {
@ -272,6 +272,14 @@ declare module "choices.js" {
*/ */
choices?: any[]; choices?: any[];
/**
* The amount of choices to be rendered within the dropdown list ("-1" indicates no limit). This is useful if you have a lot of choices where it is easier for a user to use the search area to find a choice.
*
* Input types affected: select-one, select-multiple
* @default -1
*/
renderChoiceLimit?: number;
/** /**
* The amount of items a user can input/select ("-1" indicates no limit). * The amount of items a user can input/select ("-1" indicates no limit).
* *
@ -436,7 +444,15 @@ declare module "choices.js" {
/** /**
* Whether the input should show a placeholder. Used in conjunction with placeholderValue. If placeholder is set to true and no value is passed to placeholderValue, the passed input's placeholder attribute will be used as the placeholder value. * Whether the input should show a placeholder. Used in conjunction with placeholderValue. If placeholder is set to true and no value is passed to placeholderValue, the passed input's placeholder attribute will be used as the placeholder value.
* *
* Input types affected: text, select-one, select-multiple * Note: For single select boxes, the recommended way of adding a placeholder is as follows:
* <select>
* <option placeholder>This is a placeholder</option>
* <option>...</option>
* <option>...</option>
* <option>...</option>
* </select>
*
* Input types affected: text, select-multiple
* @default true * @default true
*/ */
placeholder?: boolean; placeholder?: boolean;
@ -444,11 +460,19 @@ declare module "choices.js" {
/** /**
* The value of the inputs placeholder. * The value of the inputs placeholder.
* *
* Input types affected: text, select-one, select-multiple * Input types affected: text, select-multiple
* @default null * @default null
*/ */
placeholderValue?: string; placeholderValue?: string;
/**
* The value of the search inputs placeholder.
*
* Input types affected: select-one
* @default null
*/
searchPlaceholderValue?: string;
/** /**
* Prepend a value to each item added/selected. * Prepend a value to each item added/selected.
* *
@ -603,6 +627,11 @@ declare module "choices.js" {
*/ */
groupHeading?: string; groupHeading?: string;
/**
* @default 'choices__placeholder'
*/
placeholder?: string;
/** /**
* @default 'choices__button' * @default 'choices__button'
*/ */
@ -647,6 +676,16 @@ declare module "choices.js" {
* @default 'is-loading' * @default 'is-loading'
*/ */
loadingState?: string; loadingState?: string;
/**
* @default 'has-no-results'
*/
noResults?: string;
/**
* @default 'has-no-choices'
*/
noChoices?: string;
}; };
/** /**