2016-10-28 04:51:37 +02:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import { resolveWidget } from '../Widgets';
|
2016-11-23 16:23:32 -02:00
|
|
|
import previewStyle from './defaultPreviewStyle';
|
2016-10-28 04:51:37 +02:00
|
|
|
|
|
|
|
export default class ObjectPreview extends Component {
|
|
|
|
widgetFor = (field) => {
|
2017-01-10 22:23:22 -02:00
|
|
|
const { value, getAsset } = this.props;
|
2016-10-28 04:51:37 +02:00
|
|
|
const widget = resolveWidget(field.get('widget'));
|
2016-11-23 16:23:32 -02:00
|
|
|
return (
|
|
|
|
<div key={field.get('name')}>
|
|
|
|
{React.createElement(widget.preview, {
|
|
|
|
key: field.get('name'),
|
|
|
|
value: value && value.get(field.get('name')),
|
|
|
|
field,
|
2017-01-10 22:23:22 -02:00
|
|
|
getAsset,
|
2016-11-23 16:23:32 -02:00
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
2016-10-28 04:51:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { field } = this.props;
|
|
|
|
const fields = field && field.get('fields');
|
|
|
|
|
2016-11-23 16:23:32 -02:00
|
|
|
return <div style={previewStyle}>{fields ? fields.map(f => this.widgetFor(f)) : null}</div>;
|
2016-10-28 04:51:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectPreview.propTypes = {
|
|
|
|
value: PropTypes.node,
|
|
|
|
field: PropTypes.node,
|
2017-01-10 22:23:22 -02:00
|
|
|
getAsset: PropTypes.func.isRequired,
|
2016-10-28 04:51:37 +02:00
|
|
|
};
|