2023-04-19 10:10:31 +00:00
|
|
|
import { Switch } from "@headlessui/react";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
value: boolean;
|
|
|
|
onChange: (value: boolean) => void;
|
|
|
|
label?: string;
|
2023-04-24 13:23:07 +00:00
|
|
|
size?: "sm" | "md" | "lg";
|
2023-04-19 10:10:31 +00:00
|
|
|
disabled?: boolean;
|
|
|
|
className?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ToggleSwitch: React.FC<Props> = (props) => {
|
2023-04-24 13:23:07 +00:00
|
|
|
const { value, onChange, label, size = "sm", disabled, className } = props;
|
2023-04-19 10:10:31 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Switch
|
|
|
|
checked={value}
|
|
|
|
disabled={disabled}
|
|
|
|
onChange={onChange}
|
2023-04-24 13:23:07 +00:00
|
|
|
className={`relative inline-flex ${
|
|
|
|
size === "sm" ? "h-3.5 w-6" : size === "md" ? "h-4 w-7" : "h-6 w-11"
|
|
|
|
} flex-shrink-0 cursor-pointer rounded-full border-2 border-brand-base transition-colors duration-200 ease-in-out focus:outline-none ${
|
|
|
|
value ? "bg-green-500" : "bg-brand-surface-2"
|
|
|
|
} ${className || ""}`}
|
2023-04-19 10:10:31 +00:00
|
|
|
>
|
|
|
|
<span className="sr-only">{label}</span>
|
|
|
|
<span
|
|
|
|
aria-hidden="true"
|
2023-04-24 13:23:07 +00:00
|
|
|
className={`inline-block ${
|
|
|
|
size === "sm" ? "h-2.5 w-2.5" : size === "md" ? "h-3 w-3" : "h-5 w-5"
|
|
|
|
} transform rounded-full shadow ring-0 transition duration-200 ease-in-out ${
|
|
|
|
value
|
|
|
|
? (size === "sm"
|
|
|
|
? "translate-x-2.5"
|
|
|
|
: size === "md"
|
|
|
|
? "translate-x-3"
|
|
|
|
: "translate-x-5") + " bg-white"
|
|
|
|
: "translate-x-0 bg-brand-surface-1"
|
2023-04-19 10:10:31 +00:00
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
</Switch>
|
|
|
|
);
|
|
|
|
};
|