static-cms/src/components/PreviewPane.js

32 lines
891 B
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
2016-05-30 16:55:32 -07:00
import Widgets from './Widgets';
export default class PreviewPane extends React.Component {
previewFor(field) {
2016-06-10 00:16:01 -03:00
const { entry, getMedia } = this.props;
2016-05-30 16:55:32 -07:00
const widget = Widgets[field.get('widget')] || Widgets._unknown;
return React.createElement(widget.Preview, {
field: field,
2016-06-10 00:16:01 -03:00
value: entry.getIn(['data', field.get('name')]),
getMedia: getMedia,
2016-05-30 16:55:32 -07:00
});
}
render() {
const { collection } = this.props;
if (!collection) { return null; }
2016-05-30 16:55:32 -07:00
return <div>
{collection.get('fields').map((field) => <div key={field.get('name')}>{this.previewFor(field)}</div>)}
2016-05-30 16:55:32 -07:00
</div>;
}
}
PreviewPane.propTypes = {
collection: ImmutablePropTypes.map.isRequired,
entry: ImmutablePropTypes.map.isRequired,
getMedia: PropTypes.func.isRequired,
};