42 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-07-24 13:57:57 -04:00
import React from 'react';
import PropTypes from 'prop-types';
2019-03-15 10:19:57 -04:00
import styled from '@emotion/styled';
import { List } from 'immutable';
2018-07-24 13:57:57 -04:00
import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
const FileLink = styled(({ value, getAsset }) => (
<a href={getAsset(value)} rel="noopener noreferrer" target="_blank">
{value}
</a>
))`
display: block;
`;
function FileLinkList({ values, getAsset }) {
return (
<div>
{values.map(value => (
<FileLink key={value} value={value} getAsset={getAsset} />
))}
</div>
);
}
function FileContent({ value, getAsset }) {
if (Array.isArray(value) || List.isList(value)) {
return <FileLinkList values={value} getAsset={getAsset} />;
}
return <FileLink value={value} getAsset={getAsset} />;
}
const FilePreview = props => (
<WidgetPreviewContainer>{props.value ? <FileContent {...props} /> : null}</WidgetPreviewContainer>
2018-07-24 13:57:57 -04:00
);
FilePreview.propTypes = {
getAsset: PropTypes.func.isRequired,
value: PropTypes.node,
};
export default FilePreview;