2022-07-23 00:39:50 +00:00
|
|
|
import { useId } from "@radix-ui/react-id";
|
|
|
|
import * as Label from "@radix-ui/react-label";
|
|
|
|
import * as PrimitiveSwitch from "@radix-ui/react-switch";
|
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
|
|
|
|
const Switch = (
|
|
|
|
props: React.ComponentProps<typeof PrimitiveSwitch.Root> & {
|
|
|
|
label?: string;
|
2022-09-02 21:16:36 +00:00
|
|
|
thumbProps?: {
|
|
|
|
className?: string;
|
|
|
|
};
|
2022-07-23 00:39:50 +00:00
|
|
|
}
|
|
|
|
) => {
|
|
|
|
const { label, ...primitiveProps } = props;
|
|
|
|
const id = useId();
|
|
|
|
|
|
|
|
return (
|
2022-09-06 22:58:16 +00:00
|
|
|
<div className="flex h-auto w-auto flex-row items-center">
|
2022-07-23 00:39:50 +00:00
|
|
|
<PrimitiveSwitch.Root
|
|
|
|
className={classNames(
|
|
|
|
props.checked ? "bg-gray-900" : "bg-gray-200 hover:bg-gray-300",
|
2022-09-06 22:58:16 +00:00
|
|
|
"focus:ring-brand-800 h-6 w-10 rounded-full shadow-none",
|
2022-09-02 21:16:36 +00:00
|
|
|
props.className
|
2022-07-23 00:39:50 +00:00
|
|
|
)}
|
|
|
|
{...primitiveProps}>
|
|
|
|
<PrimitiveSwitch.Thumb
|
|
|
|
id={id}
|
2022-09-02 21:16:36 +00:00
|
|
|
// Since we dont support global dark mode - we have to style dark mode components specifically on the instance for now
|
|
|
|
// TODO: Remove once we support global dark mode
|
2022-08-31 11:13:27 +00:00
|
|
|
className={classNames(
|
2022-09-06 22:58:16 +00:00
|
|
|
"block h-[18px] w-[18px] rounded-full bg-white",
|
|
|
|
"translate-x-[4px] transition delay-100 will-change-transform",
|
|
|
|
"[&[data-state='checked']]:translate-x-[18px]",
|
2022-09-02 21:16:36 +00:00
|
|
|
props.checked && "shadow-inner",
|
|
|
|
props.thumbProps?.className
|
2022-08-31 11:13:27 +00:00
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
/>
|
|
|
|
</PrimitiveSwitch.Root>
|
|
|
|
{label && (
|
|
|
|
<Label.Root
|
|
|
|
htmlFor={id}
|
|
|
|
className="ml-2 cursor-pointer align-text-top text-sm font-medium text-neutral-700 ltr:ml-3 rtl:mr-3 dark:text-white">
|
|
|
|
{label}
|
|
|
|
</Label.Root>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Switch;
|