2025-03-26 13:03:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2025-03-26 13:03:51 +00:00
|
|
|
// 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,
|
|
|
|
}) => {
|
2025-03-26 13:03:51 +00:00
|
|
|
// 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>
|
2025-05-14 13:09:47 +00:00
|
|
|
<button
|
|
|
|
id="check-box"
|
|
|
|
className={"check-box"}
|
|
|
|
onClick={handleOnClick}
|
2025-04-29 12:49:03 +00:00
|
|
|
style={{
|
|
|
|
background: value ? "var(--background-color-accent)" : "",
|
|
|
|
outline: value ? "" : "1px solid var(--border-color)",
|
|
|
|
}}
|
|
|
|
>
|
2025-03-25 06:17:41 +00:00
|
|
|
<div
|
|
|
|
className="check-box-style"
|
|
|
|
style={{
|
2025-04-29 12:49:03 +00:00
|
|
|
left: value ? "16px" : "2px",
|
2025-03-26 13:03:51 +00:00
|
|
|
background: value ? "" : "var(--text-disabled)",
|
2025-03-25 06:17:41 +00:00
|
|
|
}}
|
|
|
|
></div>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name=""
|
|
|
|
id={`toogle-input-${inputKey}`}
|
2025-03-26 13:03:51 +00:00
|
|
|
checked={value}
|
|
|
|
readOnly
|
2025-03-25 06:17:41 +00:00
|
|
|
/>
|
2025-05-14 13:09:47 +00:00
|
|
|
</button>
|
2025-03-25 06:17:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default InputToggle;
|