37 lines
926 B
JavaScript
Raw Normal View History

2018-07-24 13:57:57 -04:00
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'react-emotion';
import { List } from 'immutable';
2018-07-24 13:57:57 -04:00
import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
const StyledImage = styled(({ getAsset, value }) => (
<img src={getAsset(value)} role="presentation" />
))`
display: block;
2018-07-24 13:57:57 -04:00
max-width: 100%;
height: auto;
`;
2018-07-24 13:57:57 -04:00
const ImagePreviewContent = props => {
const { value, getAsset } = props;
if (Array.isArray(value) || List.isList(value)) {
return value.map(val => <StyledImage key={val} value={val} getAsset={getAsset} />);
}
return <StyledImage {...props} />;
};
const ImagePreview = props => {
return (
<WidgetPreviewContainer>
{props.value ? <ImagePreviewContent {...props} /> : null}
</WidgetPreviewContainer>
);
};
2018-07-24 13:57:57 -04:00
ImagePreview.propTypes = {
getAsset: PropTypes.func.isRequired,
value: PropTypes.node,
};
export default ImagePreview;