-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFilePreview.js
More file actions
65 lines (55 loc) · 1.43 KB
/
FilePreview.js
File metadata and controls
65 lines (55 loc) · 1.43 KB
1
2
3
4
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
import React from 'react'
import styled from 'styled-components'
const imageFormats = ['png', 'jpg', 'jpeg', 'bmp', 'gif']
const Icon = ({ name, extension = '.pdf' }) => (
<FileIcon className={`glyphicon glyphicon-file`}>
<Ext>{extension}</Ext>
</FileIcon>
)
const getExtension = file =>
file.slice((Math.max(0, file.lastIndexOf('.')) || Infinity) + 1)
const isImage = ext => imageFormats.indexOf(ext) > -1
export default ({ preview, renderRemove = () => {} }) => {
const extension = getExtension(preview)
const displayPreview = isImage(extension)
return (
<Container>
{displayPreview ? (
<Preview src={preview} />
) : (
<Icon extension={extension} name={preview} />
)}
{renderRemove(preview)}
</Container>
)
}
const Container = styled.div`
height: 100%;
max-width: 100%;
text-align: center;
<<<<<<< HEAD
position: relative
=======
position: relative;
>>>>>>> dev
`
const Preview = styled.img`
max-width: 100%;
max-height: 100%;
background: #fff;
box-shadow: 0 -1px 1px rgba(0, 0, 0, 0.15), 0 -10px 0 -5px #eee,
0 -10px 1px -4px rgba(0, 0, 0, 0.15);
border-radius: 4px;
`
const FileIcon = styled.i``
const Ext = styled.span`
background: #f4faef;
position: absolute;
transform: translateX(-47px) translateY(27px);
font-size: 12px;
border: 2px solid #5eb404;
text-transform: uppercase;
font-family: tahoma;
padding: 0px 4px;
font-weight: bold;
`