mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
|
|
//@flow
|
||
|
|
import React from "react";
|
||
|
|
|
||
|
|
export type SelectItem = {
|
||
|
|
value: string,
|
||
|
|
label: string
|
||
|
|
};
|
||
|
|
|
||
|
|
type Props = {
|
||
|
|
label?: string,
|
||
|
|
options: SelectItem[],
|
||
|
|
value?: SelectItem,
|
||
|
|
onChange: string => void
|
||
|
|
};
|
||
|
|
|
||
|
|
class Select extends React.Component<Props> {
|
||
|
|
field: ?HTMLSelectElement;
|
||
|
|
|
||
|
|
handleInput = (event: SyntheticInputEvent<HTMLSelectElement>) => {
|
||
|
|
this.props.onChange(event.target.value);
|
||
|
|
};
|
||
|
|
|
||
|
|
renderLabel = () => {
|
||
|
|
const label = this.props.label;
|
||
|
|
if (label) {
|
||
|
|
return <label className="label">{label}</label>;
|
||
|
|
}
|
||
|
|
return "";
|
||
|
|
};
|
||
|
|
|
||
|
|
render() {
|
||
|
|
const { options, value } = this.props;
|
||
|
|
|
||
|
|
return (
|
||
|
|
<div className="field">
|
||
|
|
{this.renderLabel()}
|
||
|
|
<div className="control select">
|
||
|
|
<select
|
||
|
|
ref={input => {
|
||
|
|
this.field = input;
|
||
|
|
}}
|
||
|
|
value={value}
|
||
|
|
onChange={this.handleInput}
|
||
|
|
>
|
||
|
|
{options.map(opt => {
|
||
|
|
return (
|
||
|
|
<option value={opt.value} key={opt.value}>
|
||
|
|
{opt.label}
|
||
|
|
</option>
|
||
|
|
);
|
||
|
|
})}
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export default Select;
|