forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFavoriteToggle.tsx
More file actions
43 lines (38 loc) · 1.06 KB
/
FavoriteToggle.tsx
File metadata and controls
43 lines (38 loc) · 1.06 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
import { Star } from "lucide-react";
import { type MouseEvent, useCallback } from "react";
import { Button } from "@/components/ui/button";
import { type FavoriteType, useFavorites } from "@/hooks/useFavorites";
import { cn } from "@/lib/utils";
interface FavoriteToggleProps {
type: FavoriteType;
id: string;
name: string;
}
export const FavoriteToggle = ({ type, id, name }: FavoriteToggleProps) => {
const { isFavorite, toggleFavorite } = useFavorites();
const active = isFavorite(type, id);
const handleClick = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
toggleFavorite({ type, id, name });
},
[type, id, name, toggleFavorite],
);
return (
<Button
onClick={handleClick}
data-testid="favorite-toggle"
className={cn(
"w-fit h-fit p-1 hover:text-warning",
active ? "text-warning" : "text-gray-500/50",
)}
variant="ghost"
size="icon"
>
<Star
className="h-4 w-4"
fill={active ? "oklch(79.5% 0.184 86.047)" : "none"}
/>
</Button>
);
};