mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Specifying types a bit more
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
06c42ab9ae
commit
71ed501f07
@ -12,18 +12,21 @@ import { themeStore } from "../../theme.store";
|
|||||||
|
|
||||||
const { Menu } = components;
|
const { Menu } = components;
|
||||||
|
|
||||||
|
type OptionType = { label: string; value: string };
|
||||||
|
type GroupType = GroupTypeBase<OptionType>;
|
||||||
|
|
||||||
export interface GroupSelectOption<T extends SelectOption = SelectOption> {
|
export interface GroupSelectOption<T extends SelectOption = SelectOption> {
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
options: T[];
|
options: T[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectOption<T = any> {
|
export interface SelectOption<T = any> {
|
||||||
value: T;
|
value?: T;
|
||||||
label?: React.ReactNode;
|
label?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectProps<T = any> extends ReactSelectProps<OptionTypeBase, boolean, GroupTypeBase<OptionTypeBase>> {
|
export interface SelectProps<T = any> extends ReactSelectProps<OptionTypeBase, boolean> {
|
||||||
options?: readonly any[];
|
options?: ReadonlyArray<OptionType | GroupType | unknown>;
|
||||||
value?: T;
|
value?: T;
|
||||||
themeName?: "dark" | "light" | "outlined";
|
themeName?: "dark" | "light" | "outlined";
|
||||||
menuClass?: string;
|
menuClass?: string;
|
||||||
@ -70,17 +73,11 @@ export class Select extends React.Component<SelectProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@computed get options(): readonly SelectOption[] {
|
@computed get options(): readonly SelectOption[] {
|
||||||
const { autoConvertOptions, options } = this.props;
|
return this.props.options.map(opt => {
|
||||||
|
|
||||||
if (autoConvertOptions && Array.isArray(options)) {
|
|
||||||
return options.map(opt => {
|
|
||||||
return this.isValidOption(opt) ? opt : { value: opt, label: String(opt) };
|
return this.isValidOption(opt) ? opt : { value: opt, label: String(opt) };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
onChange(value: SelectOption, meta: ActionMeta<any>) {
|
onChange(value: SelectOption, meta: ActionMeta<any>) {
|
||||||
if (this.props.onChange) {
|
if (this.props.onChange) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user