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