static-cms/src/components/Widgets/ObjectPreview.js
Cássio Souza a4d7622ade Asset API (#204)
Asset API
2017-01-10 22:23:22 -02:00

34 lines
911 B
JavaScript

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 (
<div key={field.get('name')}>
{React.createElement(widget.preview, {
key: field.get('name'),
value: value && value.get(field.get('name')),
field,
getAsset,
})}
</div>
);
};
render() {
const { field } = this.props;
const fields = field && field.get('fields');
return <div style={previewStyle}>{fields ? fields.map(f => this.widgetFor(f)) : null}</div>;
}
}
ObjectPreview.propTypes = {
value: PropTypes.node,
field: PropTypes.node,
getAsset: PropTypes.func.isRequired,
};