static-cms/src/components/Widgets/ObjectPreview.js

34 lines
911 B
JavaScript
Raw Normal View History

2016-10-28 04:51:37 +02:00
import React, { PropTypes, Component } from 'react';
import { resolveWidget } from '../Widgets';
import previewStyle from './defaultPreviewStyle';
2016-10-28 04:51:37 +02:00
export default class ObjectPreview extends Component {
widgetFor = (field) => {
const { value, getMedia } = this.props;
const widget = resolveWidget(field.get('widget'));
return (
<div key={field.get('name')}>
{React.createElement(widget.preview, {
key: field.get('name'),
value: value && value.get(field.get('name')),
field,
getMedia,
})}
</div>
);
2016-10-28 04:51:37 +02:00
};
render() {
const { field } = this.props;
const fields = field && field.get('fields');
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,
getMedia: PropTypes.func.isRequired,
};