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-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;
|
|
|
|
onCheckedChange?: (checked: boolean) => void;
|
|
|
|
"data-testid"?: string;
|
2023-03-07 17:05:01 +00:00
|
|
|
tooltip?: string;
|
2022-10-24 23:11:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function SettingsToggle({
|
|
|
|
checked,
|
|
|
|
onCheckedChange,
|
|
|
|
description,
|
|
|
|
title,
|
|
|
|
children,
|
|
|
|
disabled,
|
2023-03-07 17:05:01 +00:00
|
|
|
tooltip,
|
2022-10-24 23:11:07 +00:00
|
|
|
...rest
|
|
|
|
}: Props) {
|
|
|
|
const [animateRef] = useAutoAnimate<HTMLDivElement>();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="flex w-full flex-col space-y-4 lg:flex-row lg:space-y-0 lg:space-x-4">
|
|
|
|
<fieldset className="block w-full flex-col sm:flex">
|
|
|
|
<div className="flex space-x-3">
|
|
|
|
<Switch
|
|
|
|
data-testid={rest["data-testid"]}
|
|
|
|
fitToHeight={true}
|
|
|
|
checked={checked}
|
|
|
|
onCheckedChange={onCheckedChange}
|
|
|
|
disabled={disabled}
|
2023-03-07 17:05:01 +00:00
|
|
|
tooltip={tooltip}
|
2022-10-24 23:11:07 +00:00
|
|
|
/>
|
|
|
|
|
2023-03-07 17:05:01 +00:00
|
|
|
<div>
|
2022-10-24 23:11:07 +00:00
|
|
|
<Label className="text-sm font-semibold leading-none text-black">{title}</Label>
|
2023-01-16 12:18:18 +00:00
|
|
|
{description && <p className="-mt-1.5 text-sm leading-normal text-gray-600">{description}</p>}
|
2022-10-24 23:11:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{children && (
|
2022-11-03 14:24:07 +00:00
|
|
|
<div className="lg:ml-14" ref={animateRef}>
|
|
|
|
{checked && <div className="mt-4">{children}</div>}
|
2022-10-24 23:11:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</fieldset>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingsToggle;
|