-
Notifications
You must be signed in to change notification settings - Fork 733
/
Copy pathMaskThumbnail.tsx
132 lines (127 loc) · 3.39 KB
/
MaskThumbnail.tsx
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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React from 'react';
import clsx from 'clsx';
import BlurIcon from '@material-ui/icons/BlurOnOutlined';
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';
import NoneIcon from '@material-ui/icons/NotInterestedOutlined';
import useVideoContext from '../../../hooks/useVideoContext/useVideoContext';
export type Thumbnail = 'none' | 'image';
interface MaskThumbnailProps {
thumbnail: Thumbnail;
imagePath?: string;
name?: string;
index?: number;
}
const useStyles = makeStyles((theme: Theme) =>
createStyles({
thumbContainer: {
margin: '5px',
width: 'calc(50% - 10px)',
display: 'flex',
position: 'relative',
'&::after': {
content: '""',
paddingBottom: '55.5%',
},
},
thumbIconContainer: {
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderRadius: '10px',
border: `solid ${theme.palette.grey[400]}`,
'&.selected': {
border: `solid ${theme.palette.primary.main}`,
'& svg': {
color: `${theme.palette.primary.main}`,
},
},
},
thumbIcon: {
height: 50,
width: 50,
color: `${theme.palette.grey[400]}`,
'&.selected': {
color: `${theme.palette.primary.main}`,
},
},
thumbImage: {
width: '100%',
height: '100%',
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
objectFit: 'cover',
borderRadius: '10px',
border: `solid ${theme.palette.grey[400]}`,
'&:hover': {
cursor: 'pointer',
'& svg': {
color: `${theme.palette.primary.main}`,
},
'& $thumbOverlay': {
visibility: 'visible',
},
},
'&.selected': {
border: `solid ${theme.palette.primary.main}`,
'& svg': {
color: `${theme.palette.primary.main}`,
},
},
},
thumbOverlay: {
position: 'absolute',
color: 'transparent',
padding: '20px',
fontSize: '14px',
fontWeight: 'bold',
width: '100%',
height: '100%',
borderRadius: '10px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
'&:hover': {
background: 'rgba(95, 93, 128, 0.6)',
color: 'white',
},
},
})
);
export default function MaskThumbnail({ thumbnail, imagePath, name, index }: MaskThumbnailProps) {
const classes = useStyles();
const { maskSettings, setMaskSettings } = useVideoContext();
const isImage = thumbnail === 'image';
const thumbnailSelected = isImage
? maskSettings.index === index && maskSettings.type === 'image'
: maskSettings.type === thumbnail;
const icons = {
none: NoneIcon,
blur: BlurIcon,
image: null,
};
const ThumbnailIcon = icons[thumbnail];
return (
<div
className={classes.thumbContainer}
onClick={() =>
setMaskSettings({
type: thumbnail,
index: index,
})
}
>
{ThumbnailIcon ? (
<div className={clsx(classes.thumbIconContainer, { selected: thumbnailSelected })}>
<ThumbnailIcon className={classes.thumbIcon} />
</div>
) : (
<img className={clsx(classes.thumbImage, { selected: thumbnailSelected })} src={imagePath} alt={name} />
)}
<div className={classes.thumbOverlay}>{name}</div>
</div>
);
}