Files
SCM-Manager/scm-ui/ui-components/src/forms/DropDown.tsx

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { ChangeEvent } from "react";
import classNames from "classnames";
type Props = {
options: string[];
optionValues?: string[];
optionSelected: (p: string) => void;
preselectedOption?: string;
className: any;
disabled?: boolean;
};
class DropDown extends React.Component<Props> {
render() {
2019-10-21 10:57:56 +02:00
const { options, optionValues, preselectedOption, className, disabled } = this.props;
return (
2019-10-21 10:57:56 +02:00
<div className={classNames(className, "select", disabled ? "disabled" : "")}>
<select value={preselectedOption ? preselectedOption : ""} onChange={this.change} disabled={disabled}>
<option key="" />
{options.map((option, index) => {
return (
2019-10-21 10:57:56 +02:00
<option key={option} value={optionValues && optionValues[index] ? optionValues[index] : option}>
{option}
</option>
);
})}
</select>
</div>
);
}
change = (event: ChangeEvent<HTMLSelectElement>) => {
this.props.optionSelected(event.target.value);
};
}
export default DropDown;