InvokeAI/frontend/src/common/components/IAISelect.tsx

67 lines
1.6 KiB
TypeScript
Raw Normal View History

import { FormControl, FormLabel, Select, SelectProps } from '@chakra-ui/react';
2022-10-30 03:36:28 +00:00
import { MouseEvent } from 'react';
interface Props extends SelectProps {
label: string;
styleClass?: string;
validValues:
| Array<number | string>
| Array<{ key: string; value: string | number }>;
}
/**
* Customized Chakra FormControl + Select multi-part component.
*/
const IAISelect = (props: Props) => {
const {
label,
isDisabled,
validValues,
size = 'sm',
fontSize = 'md',
styleClass,
...rest
} = props;
return (
2022-10-30 03:36:28 +00:00
<FormControl
isDisabled={isDisabled}
className={`invokeai__select ${styleClass}`}
onClick={(e: MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
e.nativeEvent.stopPropagation();
e.nativeEvent.cancelBubble = true;
}}
>
<FormLabel
fontSize={fontSize}
marginBottom={1}
flexGrow={2}
whiteSpace="nowrap"
2022-10-27 04:24:00 +00:00
className="invokeai__select-label"
>
{label}
</FormLabel>
<Select
fontSize={fontSize}
size={size}
{...rest}
2022-10-27 04:24:00 +00:00
className="invokeai__select-picker"
>
{validValues.map((opt) => {
return typeof opt === 'string' || typeof opt === 'number' ? (
2022-10-27 04:24:00 +00:00
<option key={opt} value={opt} className="invokeai__select-option">
{opt}
</option>
) : (
<option key={opt.value} value={opt.value}>
{opt.key}
</option>
);
})}
</Select>
</FormControl>
);
};
export default IAISelect;