@trellixio/roaster-coffee
Version:
Beans' product component library
55 lines • 2.67 kB
TypeScript
import * as React from 'react';
/**
* The `SelectItem` type extends the built-in `Record` type, which allows for arbitrary key-value pairs.
*/
export interface SelectItem extends Record<string, any> {
}
/**
* A function that takes a `SelectItem` object as input and returns an object containing a `value` and a `label` property.
* - `value`: the value to be passed as the `value` prop to the select component
* - `label`: the label to be displayed for the option in the select component
* - `disabled`: whether the option should be disabled (optional)
*/
declare type OptionResolver = (option: SelectItem) => {
value: string;
label: string;
disabled?: boolean;
};
export interface SelectProps {
/** The HTML ID attribute to be applied to the select element (optional). */
id?: string;
/** The label to be displayed above the select field (optional). */
label?: React.ReactNode;
/** The error message to be displayed below the select field (optional). */
error?: string;
/** The help text to be displayed below the select field (optional). */
helpText?: React.ReactNode;
/** An array of strings or `SelectItem` objects that represent the options in the select field (required). */
data: (string | SelectItem)[];
/** Whether the select field should be disabled (optional). */
disabled?: boolean;
/** The default value of the select field (optional). */
defaultValue?: string;
/** The element to be displayed to the left of the select field (optional). */
prefix?: React.ReactNode;
/** The width of the prefix element (optional). */
prefixWidth?: number;
/**
* A function that is called when the value of the select field changes (optional).
* This function accepts the new value of the select field as input.
*/
onChange?(value: string): void;
/**
* A function that takes a `SelectItem` object as input and returns an object containing a `value` and a `label` property (optional).
* This function is used to map the `SelectItem` objects in the `data` array to option objects that are used to render the select field.
* If this prop is not provided, the `value` and `label` properties of the `SelectItem` objects will be used.
*/
optionResolver?: OptionResolver;
/** CSS class names to be applied to the select element (optional). */
selectClassName?: string;
/** CSS class names to be applied to the label element (optional). */
labelClassName?: string;
}
export declare const Select: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<HTMLSelectElement>>;
export {};
//# sourceMappingURL=Select.d.ts.map