mithril-materialized
Version:
A materialize library for mithril.
56 lines (55 loc) • 2.4 kB
TypeScript
import { Attributes, Component } from 'mithril';
import { InputOption } from './option';
export type SortSelected<T extends string | number> = 'asc' | 'desc' | 'none' | ((a: InputOption<T>, b: InputOption<T>) => number);
export interface SelectAttrs<T extends string | number> extends Attributes {
/** Options to select from */
options: InputOption<T>[];
/** Called when the selection changes, contains all selected (checked) ids as an array */
onchange?: (checkedIds: T[]) => void;
/**
* Currently selected id or ids. For controlled mode, pass the current selection and provide onchange.
* For single select, pass a single value or array with one item.
* For multiple select, pass an array of selected ids.
*/
checkedId?: T | T[];
/**
* Default selected id or ids for uncontrolled mode. Only used when checkedId and onchange are not provided.
* The component will manage its own internal state in uncontrolled mode.
*/
defaultCheckedId?: T | T[];
/** Select a single option or multiple options */
multiple?: boolean;
/** Optional label. */
label?: string;
/** Optional ID. */
id?: string;
/** Unique key for use of the element in an array. */
key?: string | number;
/** Add a a placeholder to the input field. */
placeholder?: string;
/** Add a description underneath the input field. */
helperText?: string;
/** Uses Materialize icons as a prefix or postfix. */
iconName?: string;
/** Sets the input field to disabled. */
disabled?: boolean;
/** Optional style information. */
style?: string;
/** If true, break to a new row */
newRow?: boolean;
/**
* If true, add a mandatory * after the label (if any),
* and add the required and aria-required attributes to the input element.
*/
isMandatory?: boolean;
/** Add the required and aria-required attributes to the input element */
required?: boolean;
/** Enable the clear icon */
showClearButton?: boolean;
/** Max height of the dropdown menu, default '400px' */
maxHeight?: string;
/** Sort selected items: 'asc' (alphabetically A-Z), 'desc' (Z-A), 'none' (insertion order), or custom sort function */
sortSelected?: SortSelected<T>;
}
/** Select component */
export declare const Select: <T extends string | number>() => Component<SelectAttrs<T>>;