import React, { Component, PropTypes } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { resolveWidget } from '../Widgets'; import styles from './ControlPane.css'; export default class ControlPane extends Component { controlFor(field) { const { entry, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props; const widget = resolveWidget(field.get('widget')); const fieldName = field.get('name'); const value = entry.getIn(['data', fieldName]); if (entry.size === 0 || entry.get('partial') === true) return null; return (
{ React.createElement(widget.control, { field, value, onChange: val => onChange(entry.setIn(['data', fieldName], val)), onAddMedia, onRemoveMedia, getMedia, }) }
); } render() { const { collection } = this.props; if (!collection) { return null; } return (
{ collection .get('fields') .map(field =>
{this.controlFor(field)}
) }
); } } ControlPane.propTypes = { collection: ImmutablePropTypes.map.isRequired, entry: ImmutablePropTypes.map.isRequired, getMedia: PropTypes.func.isRequired, onAddMedia: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, onRemoveMedia: PropTypes.func.isRequired, };