Newer
Older
import styled, { css } from 'styled-components'
import * as mime from 'mime-types'
import { Icon } from '@pubsweet/ui'
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { th } from '@pubsweet/ui-toolkit'
import { B } from '../ui'
import { FileLightbox, fileSort, ImageTypes } from './'
const Thumbnails = styled.div`
display: flex;
flex-wrap: wrap;
align-items: center;
margin: 0;
padding: 0;
`
const Thumbnail = styled.div`
display: flex;
width: 50%;
align-items: center;
padding: calc(${th('gridUnit')} / 2);
@media screen and (max-width: 1370px) {
width: 100%;
}
@media screen and (max-width: 870px) {
width: 33%;
}
@media screen and (max-width: 750px) {
width: 50%;
}
@media screen and (max-width: 450px) {
width: 100%;
}
`
const Thumb = styled.div`
width: 33%;
max-width: 200px;
@media screen and (min-width: 870px) and (max-width: 1370px) {
width: 40%;
}
@media screen and (max-width: 450px) {
width: 40%;
}
`
const ImageBox = styled.div`
height: 0;
padding-top: 98%;
color: ${th('colorTextReverse')};
background-color: ${th('colorBorder')};
border: ${th('borderWidth')} ${th('borderStyle')} ${th('colorBorder')};
${props => props.image && `background-image: ${props.image};`}
background-size: cover;
margin: calc(${th('gridUnit')} / 2);
@media screen and (min-width: 870px) and (max-width: 1370px) {
padding-top: 45%;
}
@media screen and (min-width: 650px) and (max-width: 750px) {
padding-top: 45%;
}
@media screen and (max-width: 450px) {
padding-top: 45%;
}
p {
margin: -70% 0 0;
text-align: center;
font-size: ${th('fontSizeHeading2')};
@media screen and (min-width: 1150px) and (max-width: 1370px) {
margin-top: -35%;
font-size: calc(${th('fontSizeHeading1')} * 1.25);
}
@media screen and (min-width: 1000px) and (max-width: 1150px) {
margin-top: -35%;
font-size: ${th('fontSizeHeading1')};
}
@media screen and (min-width: 870px) and (max-width: 1000px) {
margin-top: -38%;
}
@media screen and (min-width: 650px) and (max-width: 750px) {
margin-top: -38%;
}
@media screen and (max-width: 450px) {
margin-top: -35%;
font-size: ${th('fontSizeHeading1')};
}
}
`
const FileInfo = styled.p`
width: 66%;
margin: 0 calc(${th('gridUnit')} / 2);
font-size: ${th('fontSizeBaseSmall')};
word-break: break-all;
span {
display: inline-block;
margin-right: ${th('gridUnit')};
}
@media screen and (min-width: 870px) and (max-width: 1370px) {
width: 60%;
}
@media screen and (max-width: 450px) {
width: 60%;
}
`
const error = css`
display: inline-flex;
align-items: flex-start;
color: ${th('colorError')};
`
const Bold = styled(B)`
${props => props.error && error}
`
const FileThumbnails = ({ files }) => (
<Thumbnails>
{fileSort(files).map(file => (
<Thumbnail key={file.url}>
<Thumb>
<ImageBox
image={ImageTypes.includes(file.mimeType) && `url('${file.url}')`}
>
{!ImageTypes.includes(file.mimeType) && (
<p>.{mime.extension(file.mimeType)}</p>
)}
</ImageBox>
</Thumb>
<FileInfo>
<FileLightbox file={file} />
<br />
<span>
<Bold error={!file.type}>
Type:
{!file.type && (
<Icon color="currentColor" size={2}>
x-circle
</Icon>
)}
</Bold>
</span>
{file.type !== 'manuscript' && (
<span>
<Bold error={!file.label}>
Label:
{!file.label && (
<Icon color="currentColor" size={2}>
x-circle
</Icon>
)}
</Bold>