Dwinzo_dev/app/src/components/ui/inputs/InputToggle.tsx

48 lines
1.1 KiB
TypeScript
Raw Normal View History

import React from "react";
2025-03-25 06:17:41 +00:00
interface InputToggleProps {
label: string; // Represents the toggle state (on/off)
onClick?: () => void; // Function to handle toggle clicks
value?: boolean;
inputKey: string;
}
// Update InputToggle.tsx to be fully controlled
2025-03-25 06:17:41 +00:00
const InputToggle: React.FC<InputToggleProps> = ({
label,
onClick,
value = false,
inputKey,
}) => {
// Remove internal state and use the value prop directly
2025-03-25 06:17:41 +00:00
function handleOnClick() {
if (onClick) onClick();
}
return (
<div className="input-toggle-container">
<label htmlFor={`toogle-input-${inputKey}`} className="label">
{label}
</label>
<div className={"check-box"} onClick={handleOnClick}>
<div
className="check-box-style"
style={{
left: value ? "50%" : "2px",
background: value ? "" : "var(--text-disabled)",
2025-03-25 06:17:41 +00:00
}}
></div>
<input
type="checkbox"
name=""
id={`toogle-input-${inputKey}`}
checked={value}
readOnly
2025-03-25 06:17:41 +00:00
/>
</div>
</div>
);
};
export default InputToggle;