2021-10-12 09:35:44 +00:00
|
|
|
import { useId } from "@radix-ui/react-id";
|
2021-08-09 22:43:57 +00:00
|
|
|
import * as Label from "@radix-ui/react-label";
|
2021-09-22 19:52:38 +00:00
|
|
|
import * as PrimitiveSwitch from "@radix-ui/react-switch";
|
2022-03-17 16:48:23 +00:00
|
|
|
import React from "react";
|
2021-08-09 22:43:57 +00:00
|
|
|
|
2022-03-17 16:48:23 +00:00
|
|
|
const Switch = (
|
|
|
|
props: React.ComponentProps<typeof PrimitiveSwitch.Root> & {
|
2022-05-05 14:29:49 +00:00
|
|
|
label?: string;
|
2022-03-17 16:48:23 +00:00
|
|
|
}
|
|
|
|
) => {
|
|
|
|
const { label, ...primitiveProps } = props;
|
2021-10-12 09:35:44 +00:00
|
|
|
const id = useId();
|
2022-03-17 16:48:23 +00:00
|
|
|
|
2021-08-09 22:43:57 +00:00
|
|
|
return (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex h-[20px] items-center">
|
2022-03-17 16:48:23 +00:00
|
|
|
<PrimitiveSwitch.Root className="h-[20px] w-[36px] rounded-sm bg-gray-400 p-0.5" {...primitiveProps}>
|
2021-08-09 22:43:57 +00:00
|
|
|
<PrimitiveSwitch.Thumb
|
2021-10-12 09:35:44 +00:00
|
|
|
id={id}
|
2022-03-17 16:48:23 +00:00
|
|
|
className={"block h-[16px] w-[16px] translate-x-0 bg-white transition-transform"}
|
2021-08-09 22:43:57 +00:00
|
|
|
/>
|
|
|
|
</PrimitiveSwitch.Root>
|
|
|
|
{label && (
|
2021-10-12 09:35:44 +00:00
|
|
|
<Label.Root
|
|
|
|
htmlFor={id}
|
2022-03-11 00:26:42 +00:00
|
|
|
className="cursor-pointer align-text-top text-sm font-medium text-neutral-700 ltr:ml-3 rtl:mr-3 dark:text-white">
|
2021-08-09 22:43:57 +00:00
|
|
|
{label}
|
|
|
|
</Label.Root>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2022-03-17 16:48:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Switch;
|