UNPKG

mithril-materialized

Version:
51 lines (50 loc) 1.98 kB
import { Component, Attributes } from 'mithril'; export interface DropdownItem<T extends string | number> { /** ID property of the selected item */ id?: T; /** Label to show in the dropdown */ label: string; /** Can we select the item */ disabled?: boolean; /** Display a Materials Icon in front of the label */ iconName?: string; /** Add a divider */ divider?: boolean; } export interface DropdownAttrs<T extends string | number> extends Attributes { /** * Optional id of the dropdown element * @default 'dropdown' */ id?: T; /** * Optional label when no item is selected * @default 'Select' */ label?: string; key?: string | number; /** If true, disable the selection */ disabled?: boolean; /** Item array to show in the dropdown. If the value is not supplied, uses he name. */ items: DropdownItem<T>[]; /** * Currently selected item id for controlled mode. If provided along with `onchange`, the component operates in controlled mode * where the parent manages the state. The parent must update this value in response to `onchange` callbacks. */ checkedId?: T; /** * Default selected item id 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; /** When a value or name is selected. Optional for uncontrolled mode. */ onchange?: (value: T) => void; /** Uses Materialize icons as a prefix or postfix. */ iconName?: string; /** Add a description underneath the input field. */ helperText?: string; /** Max height of the dropdown menu, default '400px', use 'none' to disable it */ maxHeight?: string; } /** Pure TypeScript Dropdown component - no Materialize dependencies */ export declare const Dropdown: <T extends string | number>() => Component<DropdownAttrs<T>>;