import React, { PropTypes, Component } from 'react';
import { resolveWidget } from '../Widgets';
import previewStyle from './defaultPreviewStyle';
export default class ObjectPreview extends Component {
widgetFor = (field) => {
const { value, getAsset } = this.props;
const widget = resolveWidget(field.get('widget'));
return (
{React.createElement(widget.preview, {
key: field.get('name'),
value: value && value.get(field.get('name')),
field,
getAsset,
})}
);
};
render() {
const { field } = this.props;
const fields = field && field.get('fields');
return {fields ? fields.map(f => this.widgetFor(f)) : null}
;
}
}
ObjectPreview.propTypes = {
value: PropTypes.node,
field: PropTypes.node,
getAsset: PropTypes.func.isRequired,
};