d81d0d416f
* Make string the default widget if none is specified * Linting fixes for PreviewPane * Linting fixes for ControlPane * Add date widget * Fix name of date control class * Fix spaces in list control with no fields * Fix linting error for List Control * Fix linting errors in raw editor * Add Select widget * Fix linting error
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import React, { PropTypes } from 'react';
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
export default class SelectControl extends React.Component {
|
|
handleChange = (e) => {
|
|
this.props.onChange(e.target.value);
|
|
};
|
|
|
|
render() {
|
|
const { field, value } = this.props;
|
|
const fieldOptions = field.get('options');
|
|
|
|
if (!fieldOptions) {
|
|
return <div>Error rendering select control for {field.get('name')}: No options</div>;
|
|
}
|
|
|
|
const options = fieldOptions.map((option) => {
|
|
if (typeof option === 'string') {
|
|
return { label: option, value: option };
|
|
}
|
|
return option;
|
|
});
|
|
|
|
return (<select value={value || ''} onChange={this.handleChange}>
|
|
{options.map((option, idx) => <option key={idx} value={option.value}>
|
|
{option.label}
|
|
</option>)}
|
|
</select>);
|
|
}
|
|
}
|
|
|
|
SelectControl.propTypes = {
|
|
onChange: PropTypes.func.isRequired,
|
|
value: PropTypes.node,
|
|
field: ImmutablePropTypes.contains({
|
|
options: ImmutablePropTypes.listOf(PropTypes.oneOf([
|
|
PropTypes.string,
|
|
ImmutablePropTypes.contains({
|
|
label: PropTypes.string.isRequired,
|
|
value: PropTypes.string.isRequired,
|
|
}),
|
|
])).isRequired,
|
|
}),
|
|
};
|