PromucFlow_constructor/app/client/src/components/editorComponents/SelectComponent.tsx
Satish Gandham 7f7f6f666b
Development: Add eslint rules for code consistency (#4083)
Co-authored-by: Satish Gandham <satish@appsmith.com>
Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2021-04-28 15:58:39 +05:30

48 lines
1.3 KiB
TypeScript

import React, { ReactNode } from "react";
import CustomizedDropdown, {
CustomizedDropdownProps,
} from "pages/common/CustomizedDropdown/index";
type SelectComponentProps = {
input: {
value?: string;
onChange?: (value: string) => void;
};
options?: Array<{ id: string; name: string; content?: ReactNode }>;
placeholder?: string;
size?: "large" | "small";
outline?: boolean;
};
export function SelectComponent(props: SelectComponentProps) {
const dropdownProps: CustomizedDropdownProps = {
sections: [
{
isSticky: false,
options:
props.options &&
props.options.map((option) => ({
content: option.content ? option.content : option.name,
onSelect: () => {
props.input.onChange && props.input.onChange(option.id);
},
shouldCloseDropdown: true,
})),
},
],
trigger: {
text: props.input.value
? props.options &&
props.options.filter((option) => props.input.value === option.id)[0]
.name
: props.placeholder,
outline: props?.outline ?? true,
size: props.size,
},
openDirection: "down",
};
return <CustomizedDropdown {...dropdownProps} />;
}
export default SelectComponent;