forked from React-Group/interstellar_ai
DropDown comments
This commit is contained in:
parent
dc4ed59547
commit
2c867fcc3c
1 changed files with 26 additions and 22 deletions
|
@ -1,35 +1,39 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
// Define the structure of each option in the dropdown
|
||||||
interface Option {
|
interface Option {
|
||||||
value: string; // The actual value to be used
|
value: string; // The actual value to be used
|
||||||
label: string; // The label to display for the option
|
label: string; // The label to display for the option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Define the props for the DropdownSetting component
|
||||||
interface DropdownSettingProps {
|
interface DropdownSettingProps {
|
||||||
label: string; // The label to display
|
label: string; // The label to display above the dropdown
|
||||||
value: string; // The current selected value
|
value: string; // The currently selected value
|
||||||
setValue: (newValue: string) => void; // The method to update the state
|
setValue: (newValue: string) => void; // Method to update the state with the new value
|
||||||
options: Option[]; // List of options for the dropdown
|
options: Option[]; // List of options for the dropdown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Functional component definition
|
||||||
const DropdownSetting: React.FC<DropdownSettingProps> = ({ label, value, setValue, options }) => {
|
const DropdownSetting: React.FC<DropdownSettingProps> = ({ label, value, setValue, options }) => {
|
||||||
const handleSelectChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
// Handler to change the selected option
|
||||||
const newValue = e.target.value;
|
const handleSelectChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
setValue(newValue);
|
const newValue = e.target.value; // Get the new selected value
|
||||||
};
|
setValue(newValue); // Update the state with the new value
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="settings-option">
|
<div className="settings-option"> {/* Container for the dropdown setting */}
|
||||||
<label>{label}</label>
|
<label>{label}</label> {/* Display the label */}
|
||||||
<select value={value} onChange={handleSelectChange}>
|
<select value={value} onChange={handleSelectChange}> {/* Dropdown selection */}
|
||||||
{options.map((option) => (
|
{options.map((option) => ( // Map through options to create <option> elements
|
||||||
<option key={option.value} value={option.value}>
|
<option key={option.value} value={option.value}>
|
||||||
{option.label}
|
{option.label} {/* Display the label for the option */}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DropdownSetting;
|
export default DropdownSetting;
|
||||||
|
|
Loading…
Reference in a new issue