Files
cal.diy/packages/ui/components/form/switch/SettingsToggle.tsx
T
9cb9ce2e42 Chor/bulk UI migration (#6367)
* Big bulk commit

* Switch and settings toggle

* Popover Kbar Timezones

* Image Uploader

* Fix core export

* Meta

* Swatch

* Remove shell

* Fix shell imports

* Moved ShellSubHeading component to UI, to prevent recursive imports from shell component

* Removed shell from ui ts config since shell doesnt have a dependency on shell anymore.

Co-authored-by: Jeroen Reumkens <[email protected]>
Co-authored-by: Omar López <[email protected]>
2023-01-10 15:39:29 +00:00

58 lines
1.5 KiB
TypeScript

import { useAutoAnimate } from "@formkit/auto-animate/react";
import { ReactNode } from "react";
import { Label } from "..";
import Switch from "./Switch";
type Props = {
children?: ReactNode;
title: string;
description?: string;
checked: boolean;
disabled?: boolean;
onCheckedChange?: (checked: boolean) => void;
"data-testid"?: string;
};
function SettingsToggle({
checked,
onCheckedChange,
description,
title,
children,
disabled,
...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}
/>
<div className="">
<Label className="text-sm font-semibold leading-none text-black">{title}</Label>
{description && <p className="-mt-2 text-sm leading-normal text-gray-600">{description}</p>}
</div>
</div>
{children && (
<div className="lg:ml-14" ref={animateRef}>
{checked && <div className="mt-4">{children}</div>}
</div>
)}
</fieldset>
</div>
</>
);
}
export default SettingsToggle;