2022-10-03 16:15:26 +00:00
|
|
|
import { FormControl, FormLabel, Select, SelectProps } from '@chakra-ui/react';
|
2022-10-30 03:36:28 +00:00
|
|
|
import { MouseEvent } from 'react';
|
2022-10-03 16:15:26 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}}
|
|
|
|
>
|
2022-10-03 16:15:26 +00:00
|
|
|
<FormLabel
|
|
|
|
fontSize={fontSize}
|
|
|
|
marginBottom={1}
|
|
|
|
flexGrow={2}
|
|
|
|
whiteSpace="nowrap"
|
2022-10-27 04:24:00 +00:00
|
|
|
className="invokeai__select-label"
|
2022-10-03 16:15:26 +00:00
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</FormLabel>
|
|
|
|
<Select
|
|
|
|
fontSize={fontSize}
|
|
|
|
size={size}
|
|
|
|
{...rest}
|
2022-10-27 04:24:00 +00:00
|
|
|
className="invokeai__select-picker"
|
2022-10-03 16:15:26 +00:00
|
|
|
>
|
|
|
|
{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">
|
2022-10-03 16:15:26 +00:00
|
|
|
{opt}
|
|
|
|
</option>
|
|
|
|
) : (
|
|
|
|
<option key={opt.value} value={opt.value}>
|
|
|
|
{opt.key}
|
|
|
|
</option>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Select>
|
|
|
|
</FormControl>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default IAISelect;
|