headplane/app/components/Switch.tsx

35 lines
885 B
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { Switch as AriaSwitch } from 'react-aria-components';
import { cn } from '~/utils/cn';
2024-12-31 10:30:14 +05:30
type SwitchProps = Parameters<typeof AriaSwitch>[0] & {
readonly label: string;
2024-12-31 10:30:14 +05:30
};
2024-12-31 10:30:14 +05:30
export default function Switch(props: SwitchProps) {
return (
<AriaSwitch
2024-12-31 10:30:14 +05:30
{...props}
aria-label={props.label}
className="group flex gap-2 items-center"
>
<div
className={cn(
'flex h-[26px] w-[44px] p-[4px] shrink-0',
'rounded-full outline-none group-focus-visible:ring-2',
'bg-main-600/50 dark:bg-main-600/20 group-selected:bg-main-700',
2024-12-31 10:30:14 +05:30
props.isDisabled && 'opacity-50 cursor-not-allowed',
props.className,
)}
>
2024-12-31 10:30:14 +05:30
<span
className={cn(
'h-[18px] w-[18px] transform rounded-full',
'bg-white transition duration-100 ease-in-out',
'translate-x-0 group-selected:translate-x-[100%]',
)}
/>
</div>
</AriaSwitch>
2024-12-31 10:30:14 +05:30
);
}