-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFavoriteMediaButton.tsx
More file actions
49 lines (44 loc) · 1.21 KB
/
FavoriteMediaButton.tsx
File metadata and controls
49 lines (44 loc) · 1.21 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
import FavoriteIcon from '@mui/icons-material/Favorite';
import IconButton from '@mui/material/IconButton';
import React, { useState } from 'react';
interface FavoriteMediaButtonProps {
thumbnail: {
id: string;
mediaType?: string;
isFavorite?: boolean;
};
handleSingleFavorites?: (id: string, actionAdd: boolean) => void;
}
const FavoriteMediaButton: React.FC<FavoriteMediaButtonProps> = ({
thumbnail,
handleSingleFavorites,
}) => {
const [hovered, setHovered] = useState(false);
const handleOnClick = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
handleSingleFavorites?.(thumbnail.id, !thumbnail.isFavorite);
};
return (
<IconButton
size="small"
onClick={handleOnClick}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
sx={{
position: 'absolute',
bottom: 9,
left: 7,
zIndex: 2,
}}
>
{(() => {
if (hovered && thumbnail.isFavorite != null && !thumbnail.isFavorite) {
return <FavoriteIcon sx={{ color: 'white', fontSize: 24 }} />; // red when hovered and not favorite
} else {
return <FavoriteIcon sx={{ opacity: 0, fontSize: 24 }} />;
}
})()}
</IconButton>
);
};
export default FavoriteMediaButton;