-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
61 lines (53 loc) · 1.33 KB
/
index.tsx
File metadata and controls
61 lines (53 loc) · 1.33 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
import CancelIcon from '@assets/svg/x.svg';
import { useState } from 'react';
import { styled } from 'stitches.config';
interface ImagePreviewProps {
url: string;
onDelete: (e: React.MouseEvent<HTMLButtonElement>) => void;
}
export default function ImagePreview({ url, onDelete }: ImagePreviewProps) {
const [showBackdrop, setShowBackdrop] = useState(false);
return (
<SContainer onMouseLeave={() => setShowBackdrop(false)} onMouseEnter={() => setShowBackdrop(true)}>
{showBackdrop && (
<SBackdrop>
<SDeleteButton type="button" onClick={onDelete}>
<CancelIcon />
</SDeleteButton>
</SBackdrop>
)}
<SImage src={url} alt="" />
</SContainer>
);
}
const SContainer = styled('div', {
position: 'relative',
width: '100%',
height: '100%',
maxHeight: '178px',
aspectRatio: '760 / 520',
borderRadius: '10px',
overflow: 'hidden',
});
const SBackdrop = styled('div', {
position: 'absolute',
width: '100%',
height: '100%',
background: 'rgba(42, 42, 42, 0.6)',
borderRadius: '10px',
gap: '8px',
zIndex: 1,
display: 'flex',
});
const SImage = styled('img', {
width: '100%',
height: '100%',
objectFit: 'cover',
});
const SDeleteButton = styled('button', {
display: 'inline',
color: '$gray10',
position: 'absolute',
right: '8px',
top: '8px',
});