2022-10-24 23:11:07 +00:00
|
|
|
import { useAutoAnimate } from "@formkit/auto-animate/react";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { ReactNode } from "react";
|
2022-10-24 23:11:07 +00:00
|
|
|
|
2023-09-28 11:59:06 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
|
|
|
|
2023-01-10 15:39:29 +00:00
|
|
|
import { Label } from "..";
|
2022-10-24 23:11:07 +00:00
|
|
|
import Switch from "./Switch";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
children?: ReactNode;
|
|
|
|
title: string;
|
|
|
|
description?: string;
|
|
|
|
checked: boolean;
|
|
|
|
disabled?: boolean;
|
2023-04-13 02:10:23 +00:00
|
|
|
LockedIcon?: React.ReactNode;
|
2023-09-28 11:59:06 +00:00
|
|
|
Badge?: React.ReactNode;
|
2022-10-24 23:11:07 +00:00
|
|
|
onCheckedChange?: (checked: boolean) => void;
|
|
|
|
"data-testid"?: string;
|
2023-03-07 17:05:01 +00:00
|
|
|
tooltip?: string;
|
2023-09-28 11:59:06 +00:00
|
|
|
toggleSwitchAtTheEnd?: boolean;
|
|
|
|
childrenClassName?: string;
|
|
|
|
switchContainerClassName?: string;
|
2022-10-24 23:11:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function SettingsToggle({
|
|
|
|
checked,
|
|
|
|
onCheckedChange,
|
|
|
|
description,
|
2023-04-13 02:10:23 +00:00
|
|
|
LockedIcon,
|
2023-09-28 11:59:06 +00:00
|
|
|
Badge,
|
2022-10-24 23:11:07 +00:00
|
|
|
title,
|
|
|
|
children,
|
|
|
|
disabled,
|
2023-03-07 17:05:01 +00:00
|
|
|
tooltip,
|
2023-09-28 11:59:06 +00:00
|
|
|
toggleSwitchAtTheEnd = false,
|
|
|
|
childrenClassName,
|
|
|
|
switchContainerClassName,
|
2022-10-24 23:11:07 +00:00
|
|
|
...rest
|
|
|
|
}: Props) {
|
|
|
|
const [animateRef] = useAutoAnimate<HTMLDivElement>();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-06-22 22:25:37 +00:00
|
|
|
<div className="flex w-full flex-col space-y-4 lg:flex-row lg:space-x-4 lg:space-y-0">
|
2022-10-24 23:11:07 +00:00
|
|
|
<fieldset className="block w-full flex-col sm:flex">
|
2023-09-28 11:59:06 +00:00
|
|
|
{toggleSwitchAtTheEnd ? (
|
|
|
|
<div className={classNames("flex justify-between space-x-3", switchContainerClassName)}>
|
|
|
|
<div>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<Label className="text-emphasis text-base font-semibold leading-none">
|
|
|
|
{title}
|
|
|
|
{LockedIcon}
|
|
|
|
</Label>
|
2023-09-29 12:37:06 +00:00
|
|
|
{Badge}
|
2023-09-28 11:59:06 +00:00
|
|
|
</div>
|
|
|
|
{description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>}
|
|
|
|
</div>
|
|
|
|
<div className="my-auto h-full">
|
|
|
|
<Switch
|
|
|
|
data-testid={rest["data-testid"]}
|
|
|
|
fitToHeight={true}
|
|
|
|
checked={checked}
|
|
|
|
onCheckedChange={onCheckedChange}
|
|
|
|
disabled={disabled}
|
|
|
|
tooltip={tooltip}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="flex space-x-3">
|
|
|
|
<Switch
|
|
|
|
data-testid={rest["data-testid"]}
|
|
|
|
fitToHeight={true}
|
|
|
|
checked={checked}
|
|
|
|
onCheckedChange={onCheckedChange}
|
|
|
|
disabled={disabled}
|
|
|
|
tooltip={tooltip}
|
|
|
|
/>
|
2022-10-24 23:11:07 +00:00
|
|
|
|
2023-09-28 11:59:06 +00:00
|
|
|
<div>
|
|
|
|
<Label className="text-emphasis text-sm font-semibold leading-none">
|
|
|
|
{title}
|
|
|
|
{LockedIcon}
|
|
|
|
</Label>
|
|
|
|
{description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>}
|
|
|
|
</div>
|
2022-10-24 23:11:07 +00:00
|
|
|
</div>
|
2023-09-28 11:59:06 +00:00
|
|
|
)}
|
2022-10-24 23:11:07 +00:00
|
|
|
{children && (
|
2023-09-28 11:59:06 +00:00
|
|
|
<div className={classNames("lg:ml-14", childrenClassName)} ref={animateRef}>
|
|
|
|
{checked && <div className={classNames(!toggleSwitchAtTheEnd && "mt-4")}>{children}</div>}
|
2022-10-24 23:11:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</fieldset>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingsToggle;
|