InvokeAI/invokeai/frontend/web/src/common/components/IAISwitch.tsx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.3 KiB
TypeScript
Raw Normal View History

import {
FormControl,
FormControlProps,
FormLabel,
FormLabelProps,
Switch,
SwitchProps,
2023-06-03 12:47:51 +00:00
Tooltip,
} from '@chakra-ui/react';
import { memo } from 'react';
interface Props extends SwitchProps {
label?: string;
width?: string | number;
formControlProps?: FormControlProps;
formLabelProps?: FormLabelProps;
2023-06-03 12:47:51 +00:00
tooltip?: string;
}
/**
* Customized Chakra FormControl + Switch multi-part component.
*/
const IAISwitch = (props: Props) => {
const {
label,
isDisabled = false,
width = 'auto',
formControlProps,
formLabelProps,
2023-06-03 12:47:51 +00:00
tooltip,
...rest
} = props;
return (
2023-06-03 12:47:51 +00:00
<Tooltip label={tooltip} hasArrow placement="top" isDisabled={!tooltip}>
<FormControl
isDisabled={isDisabled}
width={width}
display="flex"
gap={4}
alignItems="center"
{...formControlProps}
>
{label && (
<FormLabel
my={1}
flexGrow={1}
sx={{
cursor: isDisabled ? 'not-allowed' : 'pointer',
...formLabelProps?.sx,
}}
{...formLabelProps}
>
2023-06-03 12:47:51 +00:00
{label}
</FormLabel>
)}
<Switch {...rest} />
</FormControl>
</Tooltip>
);
};
export default memo(IAISwitch);