interstellar_ai/app/components/settings/CheckBox.tsx

32 lines
1,010 B
TypeScript
Raw Normal View History

2024-10-01 12:45:21 +02:00
import React from 'react';
2024-10-11 09:27:48 +02:00
// Define the props for the CheckboxSetting component
2024-10-01 12:45:21 +02:00
interface CheckboxSettingProps {
label: string; // The label to display
checked: boolean; // The checked state of the checkbox
setChecked: (value: boolean) => void; // Method to update the state
}
2024-10-11 09:27:48 +02:00
// Functional component definition
2024-10-01 12:45:21 +02:00
const CheckboxSetting: React.FC<CheckboxSettingProps> = ({ label, checked, setChecked }) => {
2024-10-11 09:27:48 +02:00
// Handler to toggle the checkbox state
2024-10-01 12:45:21 +02:00
const handleCheckboxChange = () => {
2024-10-11 09:27:48 +02:00
setChecked(!checked); // Toggle the checked state
2024-10-01 12:45:21 +02:00
};
return (
2024-10-11 09:27:48 +02:00
<div className="settings-option"> {/* Container for the checkbox setting */}
2024-10-01 12:45:21 +02:00
<label>
<input
2024-10-11 09:27:48 +02:00
type="checkbox" // Checkbox input type
checked={checked} // Set the checked state based on the prop
onChange={handleCheckboxChange} // Call the handler on change
2024-10-01 12:45:21 +02:00
/>
2024-10-11 09:27:48 +02:00
{label} {/* Display the label next to the checkbox */}
2024-10-01 12:45:21 +02:00
</label>
</div>
);
};
export default CheckboxSetting;