You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/components/form-components/SwitchField/SwitchField.tsx

65 lines
1.3 KiB

import clsx from 'clsx';
import { FeatureId } from '@/react/portainer/feature-flags/enums';
import { Tooltip } from '@@/Tip/Tooltip';
import styles from './SwitchField.module.css';
import { Switch } from './Switch';
export interface Props {
label: string;
checked: boolean;
onChange(value: boolean): void;
name?: string;
tooltip?: string;
labelClass?: string;
switchClass?: string;
fieldClass?: string;
dataCy?: string;
disabled?: boolean;
featureId?: FeatureId;
setTooltipHtmlMessage?: boolean;
}
export function SwitchField({
tooltip,
checked,
label,
name,
labelClass,
fieldClass,
dataCy,
disabled,
onChange,
featureId,
switchClass,
setTooltipHtmlMessage,
}: Props) {
const toggleName = name ? `toggle_${name}` : '';
return (
<label className={clsx(styles.root, fieldClass)}>
<span
className={clsx('text-left space-right control-label !p-0', labelClass)}
>
{label}
{tooltip && (
<Tooltip message={tooltip} setHtmlMessage={setTooltipHtmlMessage} />
)}
</span>
<Switch
className={clsx('space-right', switchClass)}
name={toggleName}
id={toggleName}
checked={checked}
disabled={disabled}
onChange={onChange}
featureId={featureId}
dataCy={dataCy}
/>
</label>
);
}