ColorSettings comments
This commit is contained in:
parent
c8a8ffaf0a
commit
dc4ed59547
1 changed files with 19 additions and 16 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue