Files

43 lines
1.5 KiB
TypeScript

import type { ButtonHTMLAttributes } from "react";
import { cn } from "~/lib/utils";
export type ChatSwitchProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "role"> &
Readonly<{
checked: boolean;
onCheckedChange: (checked: boolean) => void;
}>;
/** Chat-local accessible switch; avoids changing the generated Subframe primitive. */
export function ChatSwitch({ checked, onCheckedChange, className, disabled, ...props }: ChatSwitchProps): React.JSX.Element {
return (
<button
{...props}
type="button"
role="switch"
aria-checked={checked}
disabled={disabled}
onClick={() => onCheckedChange(!checked)}
className={cn(
"focus-visible:shadow-focus inline-flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent outline-none disabled:cursor-default disabled:opacity-50",
className
)}
>
<span
aria-hidden="true"
className={cn(
"rounded-round flex h-6 w-10 items-center border border-solid px-0.5 transition-colors",
checked ? "border-brand-brand-border-solid-default bg-brand-brand-surface-solid-default" : "border-border-strong bg-surface-neutral-primary"
)}
>
<span
className={cn(
"rounded-round h-4 w-4 transition-transform",
checked ? "bg-icon-neutral-on-solid translate-x-4" : "bg-icon-neutral-tertiary translate-x-0"
)}
/>
</span>
</button>
);
}