diff --git a/src/components/ui/Switch.tsx b/src/components/ui/Switch.tsx index 30aba22..8c19f25 100644 --- a/src/components/ui/Switch.tsx +++ b/src/components/ui/Switch.tsx @@ -1,5 +1,11 @@ "use client"; -import React from 'react'; + +import React from "react"; +import { + Switch as HeroSwitch, + Label, + Description, +} from "@heroui/react"; export interface SwitchProps { label?: React.ReactNode; @@ -7,7 +13,7 @@ export interface SwitchProps { checked?: boolean; onChange?: (checked: boolean) => void; disabled?: boolean; - size?: 'sm' | 'md' | 'lg'; + size?: "sm" | "md" | "lg"; checkedIcon?: React.ReactNode; uncheckedIcon?: React.ReactNode; id?: string; @@ -16,21 +22,21 @@ export interface SwitchProps { } const trackSizes = { - sm: 'w-8 h-4.5', - md: 'w-11 h-6', - lg: 'w-14 h-7.5', + sm: "w-8 h-[18px]", + md: "w-11 h-6", + lg: "w-14 h-[30px]", }; const thumbSizes = { - sm: 'w-3.5 h-3.5', - md: 'w-5 h-5', - lg: 'w-6.5 h-6.5', + sm: "size-3.5", + md: "size-5", + lg: "size-[26px]", }; const translateSizes = { - sm: 'translate-x-3.5', - md: 'translate-x-5', - lg: 'translate-x-6.5', + sm: "translate-x-3.5", + md: "translate-x-5", + lg: "translate-x-[26px]", }; export const Switch: React.FC = ({ @@ -39,85 +45,100 @@ export const Switch: React.FC = ({ checked = false, onChange, disabled = false, - size = 'md', + size = "md", checkedIcon, uncheckedIcon, id, name, - className = '', + className = "", }) => { - const switchId = id || name || (typeof label === 'string' ? label.toLowerCase().replace(/\s+/g, '-') : undefined); - - const handleClick = () => { - if (!disabled && onChange) { - onChange(!checked); - } - }; - - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === ' ' || e.key === 'Enter') { - e.preventDefault(); - handleClick(); - } - }; + const switchId = + id || + name || + (typeof label === "string" + ? label.toLowerCase().replace(/\s+/g, "-") + : undefined); return ( -
- {/* Switch Button */} - + + {(checkedIcon || uncheckedIcon) && ( + + {checked ? checkedIcon : uncheckedIcon} + + )} + + - {/* Label and description */} - {(label || description) && ( -
- {label && ( - - {label} - - )} - {description && ( - - {description} - - )} -
- )} -
+ {/* TEXTOS */} + {(label || description) && ( +
+ {label && ( + + )} + + {description && ( + + {description} + + )} +
+ )} + + ); -}; +}; \ No newline at end of file