/** * Official Type definitions for LemonadeJS plugins * https://lemonadejs.net * Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped */ declare function Dropdown(el: HTMLElement, options?: Dropdown.Options): Dropdown.Instance; declare namespace Dropdown { interface Item { /** Value of the selected item. */ value?: string | number; /** Description of the item */ text?: string; /** Icon of the item */ image?: string; /** Name of the group where the item belongs to */ group?: string; /** Keywords to help finding one item */ synonym?: string | string[]; /** Item is disabled */ disabled?: boolean; /** Color for the item */ color?: string; // Keywords keywords?: string | string[]; } interface Options { /** Preloaded data items for the dropdown */ data?: Item[]; /** Format type of the data, typically { id: name } or { value: text } */ format?: number; /** Indicates if multiple item selection is allowed */ multiple?: boolean; /** Enables the autocomplete feature for user input */ autocomplete?: boolean; /** Rendering style of the dropdown: 'default', 'picker', 'searchbar' or inline. auto will render picker or searchbar based on screensize */ type?: 'default' | 'auto' | 'picker' | 'searchbar' | 'inline', /** Defines the dropdown width */ width?: number; /** The initial value of the dropdown */ value?: string | string[] | number | number[]; /** Placeholder text for the dropdown */ placeholder?: string; /** Allow insert new items */ insert?: boolean; /** Specifies the URL for fetching the data */ url?: string; /** Item is disabled */ disabled?: boolean; /** Enables another ways to option insert */ prompt?: boolean | string | (() => string); /** Remote search */ remote?: boolean; /** Allow empty in single dropdown options. Default: true */ allowEmpty?: boolean; /** Event handler for value changes */ onchange?: (self: object, newValue: string|number) => void; /** Event handler for when the dropdown is ready */ onload?: (self: object) => void; /** Event handler for when the dropdown opens */ onopen?: (self: object) => void; /** Event handler for when the dropdown closes */ onclose?: (self: object) => void; /** * Event handler for just before a new option is added to the dropdown. This is an async function to handle ajax requests. * Example: * self.beforeInsert = async function(s, element) { * let newId = await getTheNewItemIdFromDatabase(element.text); * return { * text: element.text, * value: newId, * }; * } * * */ onbeforeinsert?: (self: object, item: Item) => boolean | void; /** Event handler for when a new option is added to the dropdown */ oninsert?: (self: object, item: Item) => void; /** Before the search happens */ onbeforesearch?: (self: object, query: string, result: object[]) => boolean | null; /** Event handler for processing search results */ onsearch?: (self: object, query: string, result: object[]) => void; } interface Instance { /** Internal type */ type: 'default' | 'auto' | 'picker' | 'searchbar' | 'inline'; /** The initial value of the dropdown */ value?: string | string[] | number | number[]; /** Existing data */ data: Item[]; /** Add a new item */ add: (item: Item) => void; /** Open dropdown */ open: () => void; /** Close Dropdown */ close: () => void; /** Dropdown state */ isClosed: () => boolean; /** Get current value */ getValue: () => number | string | number[] | string[]; /** Get current text (label). Returns string if single, string[] if multiple */ getText: () => string | string[]; /** Set current value */ setValue: (value: number | string | number[] | string[]) => void; /** Get current data */ getData: () => Item[]; /** Set current data */ setData: (data: Item[]) => void; } } export default Dropdown;