2021-12-14 19:14:53 +00:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2022-11-13 08:10:18 +00:00
|
|
|
import { isLimitedToBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
|
|
|
import { FeatureId } from '@/react/portainer/feature-flags/enums';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
2022-06-17 16:18:42 +00:00
|
|
|
import { BEFeatureIndicator } from '@@/BEFeatureIndicator';
|
|
|
|
|
2021-12-14 19:14:53 +00:00
|
|
|
import './Switch.css';
|
|
|
|
|
|
|
|
import styles from './Switch.module.css';
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
checked: boolean;
|
|
|
|
id: string;
|
|
|
|
name: string;
|
2023-05-25 03:59:32 +00:00
|
|
|
onChange(checked: boolean, index?: number): void;
|
2021-12-14 19:14:53 +00:00
|
|
|
|
2023-05-25 03:59:32 +00:00
|
|
|
index?: number;
|
2021-12-14 19:14:53 +00:00
|
|
|
className?: string;
|
|
|
|
dataCy?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
featureId?: FeatureId;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Switch({
|
|
|
|
name,
|
|
|
|
checked,
|
|
|
|
id,
|
|
|
|
disabled,
|
|
|
|
dataCy,
|
|
|
|
onChange,
|
2023-05-25 03:59:32 +00:00
|
|
|
index,
|
2021-12-14 19:14:53 +00:00
|
|
|
featureId,
|
|
|
|
className,
|
|
|
|
}: Props) {
|
|
|
|
const limitedToBE = isLimitedToBE(featureId);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<label
|
|
|
|
className={clsx('switch', className, styles.root, {
|
|
|
|
business: limitedToBE,
|
|
|
|
limited: limitedToBE,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name={name}
|
|
|
|
id={id}
|
|
|
|
checked={checked}
|
|
|
|
disabled={disabled || limitedToBE}
|
2023-05-25 03:59:32 +00:00
|
|
|
onChange={({ target: { checked } }) => onChange(checked, index)}
|
2021-12-14 19:14:53 +00:00
|
|
|
/>
|
2022-08-23 00:11:11 +00:00
|
|
|
<span className="slider round before:content-['']" data-cy={dataCy} />
|
2021-12-14 19:14:53 +00:00
|
|
|
</label>
|
|
|
|
{limitedToBE && <BEFeatureIndicator featureId={featureId} />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|