Specifying types a bit more

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev committed 2021-03-26 13:40:02 +03:00
1 parent 06c42ab9ae
commit 71ed501f07
1 file changed
+7 -10
+7 -10
View File
@@ -12,18 +12,21 @@ import { themeStore } from "../../theme.store";
const { Menu } = components;
type OptionType = { label: string; value: string };
type GroupType = GroupTypeBase<OptionType>;
export interface GroupSelectOption<T extends SelectOption = SelectOption> {
label: ReactNode;
options: T[];
}
export interface SelectOption<T = any> {
value: T;
value?: T;
label?: React.ReactNode;
}
export interface SelectProps<T = any> extends ReactSelectProps<OptionTypeBase, boolean, GroupTypeBase<OptionTypeBase>> {
options?: readonly any[];
export interface SelectProps<T = any> extends ReactSelectProps<OptionTypeBase, boolean> {
options?: ReadonlyArray<OptionType | GroupType | unknown>;
value?: T;
themeName?: "dark" | "light" | "outlined";
menuClass?: string;
@@ -70,17 +73,11 @@ export class Select extends React.Component<SelectProps> {
}
@computed get options(): readonly SelectOption[] {
const { autoConvertOptions, options } = this.props;
if (autoConvertOptions && Array.isArray(options)) {
return options.map(opt => {
return this.props.options.map(opt => {
return this.isValidOption(opt) ? opt : { value: opt, label: String(opt) };
});
}
return options;
}
@autobind()
onChange(value: SelectOption, meta: ActionMeta<any>) {
if (this.props.onChange) {