2018-07-24 13:57:57 -04:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'react-emotion';
|
2018-08-30 16:24:28 -04:00
|
|
|
import { List } from 'immutable';
|
2018-07-24 13:57:57 -04:00
|
|
|
import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
|
|
|
|
|
2018-08-30 16:24:28 -04:00
|
|
|
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-08-07 14:46:54 -06:00
|
|
|
`;
|
2018-07-24 13:57:57 -04:00
|
|
|
|
2018-08-30 16:24:28 -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;
|