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

41 lines
916 B
JavaScript
Raw Normal View History

2018-09-17 14:01:51 +02:00
// @flow
import React from "react";
import classNames from "classnames";
2018-09-17 14:01:51 +02:00
type Props = {
options: string[],
optionSelected: string => void,
preselectedOption?: string,
className: any
2018-10-04 20:02:18 +02:00
};
2018-09-17 14:01:51 +02:00
class DropDown extends React.Component<Props> {
render() {
const { options, preselectedOption, className } = this.props;
2018-10-04 20:02:18 +02:00
return (
<div className={classNames(className, "select")}>
<select
value={preselectedOption ? preselectedOption : ""}
onChange={this.change}
>
2018-10-04 20:02:18 +02:00
<option key="" />
{options.map(option => {
return (
<option key={option} value={option}>
{option}
</option>
);
})}
</select>
</div>
);
2018-09-17 14:01:51 +02:00
}
2018-10-17 14:11:28 +02:00
change = (event: SyntheticInputEvent<HTMLSelectElement>) => {
2018-09-17 14:01:51 +02:00
this.props.optionSelected(event.target.value);
2018-10-04 20:02:18 +02:00
};
2018-09-17 14:01:51 +02:00
}
export default DropDown;