ColorSettings comments

This commit is contained in:
sageTheDM 2024-10-11 09:28:23 +02:00
parent c8a8ffaf0a
commit dc4ed59547

View file

@ -1,29 +1,32 @@
import React from 'react'; import React from 'react';
interface ColorSettingProps { // Define the props for the ColorSetting component
interface ColorSettingProps {
name: string; // The name to display in the <p> tag name: string; // The name to display in the <p> tag
value: string; // The current color value value: string; // The current color value
setValue: (newColor: string) => void; // The method to update the state setValue: (newColor: string) => void; // The method to update the state
cssVariable: string; // The CSS variable name to set cssVariable: string; // The CSS variable name to set
} }
const ColorSetting: React.FC<ColorSettingProps> = ({ name, value, setValue, cssVariable }) => { // Functional component definition
const ColorSetting: React.FC<ColorSettingProps> = ({ name, value, setValue, cssVariable }) => {
// Handler to change the color value
const handleColorChange = (e: React.ChangeEvent<HTMLInputElement>) => { const handleColorChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newColor = e.target.value; const newColor = e.target.value; // Get the new color from the input
setValue(newColor); setValue(newColor); // Update the state with the new color
document.documentElement.style.setProperty(cssVariable, newColor); document.documentElement.style.setProperty(cssVariable, newColor); // Set the CSS variable
}; };
return ( return (
<div className="settings-option"> <div className="settings-option"> {/* Container for the color setting */}
<p>{name}</p> <p>{name}</p> {/* Display the name */}
<input <input
type="color" type="color" // Input type for color picker
value={value} value={value} // Set the input value to the current color
onChange={handleColorChange} onChange={handleColorChange} // Call the handler on change
/> />
</div> </div>
); );
}; };
export default ColorSetting; export default ColorSetting;