2021-12-14 19:14:53 +00:00
|
|
|
import clsx from 'clsx';
|
2023-02-22 20:13:33 +00:00
|
|
|
import { ComponentProps } from 'react';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
2022-11-13 08:10:18 +00:00
|
|
|
import { FeatureId } from '@/react/portainer/feature-flags/enums';
|
2022-06-17 16:18:42 +00:00
|
|
|
|
|
|
|
import { Tooltip } from '@@/Tip/Tooltip';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
|
|
|
import styles from './SwitchField.module.css';
|
|
|
|
import { Switch } from './Switch';
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
label: string;
|
|
|
|
checked: boolean;
|
|
|
|
onChange(value: boolean): void;
|
|
|
|
|
|
|
|
name?: string;
|
2023-02-22 20:13:33 +00:00
|
|
|
tooltip?: ComponentProps<typeof Tooltip>['message'];
|
|
|
|
setTooltipHtmlMessage?: ComponentProps<typeof Tooltip>['setHtmlMessage'];
|
2021-12-14 19:14:53 +00:00
|
|
|
labelClass?: string;
|
2022-07-22 02:16:50 +00:00
|
|
|
switchClass?: string;
|
2022-07-27 01:05:25 +00:00
|
|
|
fieldClass?: string;
|
2021-12-14 19:14:53 +00:00
|
|
|
dataCy?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
featureId?: FeatureId;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function SwitchField({
|
|
|
|
tooltip,
|
|
|
|
checked,
|
|
|
|
label,
|
|
|
|
name,
|
|
|
|
labelClass,
|
2022-07-27 01:05:25 +00:00
|
|
|
fieldClass,
|
2021-12-14 19:14:53 +00:00
|
|
|
dataCy,
|
|
|
|
disabled,
|
|
|
|
onChange,
|
|
|
|
featureId,
|
2022-07-22 02:16:50 +00:00
|
|
|
switchClass,
|
2022-12-08 21:41:11 +00:00
|
|
|
setTooltipHtmlMessage,
|
2021-12-14 19:14:53 +00:00
|
|
|
}: Props) {
|
|
|
|
const toggleName = name ? `toggle_${name}` : '';
|
|
|
|
|
|
|
|
return (
|
2022-07-27 01:05:25 +00:00
|
|
|
<label className={clsx(styles.root, fieldClass)}>
|
2021-12-14 19:14:53 +00:00
|
|
|
<span
|
2023-02-12 21:04:24 +00:00
|
|
|
className={clsx('space-right control-label !p-0 text-left', labelClass)}
|
2021-12-14 19:14:53 +00:00
|
|
|
>
|
|
|
|
{label}
|
2022-12-08 21:41:11 +00:00
|
|
|
{tooltip && (
|
|
|
|
<Tooltip message={tooltip} setHtmlMessage={setTooltipHtmlMessage} />
|
|
|
|
)}
|
2021-12-14 19:14:53 +00:00
|
|
|
</span>
|
|
|
|
<Switch
|
2022-07-22 02:16:50 +00:00
|
|
|
className={clsx('space-right', switchClass)}
|
2021-12-14 19:14:53 +00:00
|
|
|
name={toggleName}
|
|
|
|
id={toggleName}
|
|
|
|
checked={checked}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={onChange}
|
|
|
|
featureId={featureId}
|
|
|
|
dataCy={dataCy}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
}
|