/
aaronair
/
Test_task_rt_solution
Обзор
Документация
Войти
/
aaronair
/
Test_task_rt_solution
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/components/LikeButton.tsx
47 строк
1 KB
Ilikedrinkpivo
first_commit
28 май 2026, 14:51
28 май 2026, 14:51
b4498fc
Код
Авторство
О чём код?
import { useInitiativeLike } from "@/hooks/useInitiativeLike"; import { cn } from "@/lib/cn"; interface Props { id: string; initialCount: number; size?: "sm" | "md"; } export function LikeButton({ id, initialCount, size = "sm" }: Props) { const { liked, count, toggle } = useInitiativeLike(id, initialCount); return ( <button type="button" onClick={(e) => { e.stopPropagation(); e.preventDefault(); toggle(); }} aria-pressed={liked} aria-label={liked ? "Убрать лайк" : "Поставить лайк"} className={cn( "inline-flex items-center gap-1.5 rounded-full border transition-colors select-none", size === "sm" ? "px-2.5 py-1 text-xs" : "px-3 py-1.5 text-sm", liked ? "bg-rose-50 border-rose-200 text-rose-600" : "bg-surface-card border-ink-300/60 text-ink-700 hover:bg-surface-muted", )} > <svg viewBox="0 0 24 24" className={cn( size === "sm" ? "h-3.5 w-3.5" : "h-4 w-4", liked ? "fill-rose-500 stroke-rose-500" : "fill-none stroke-current", )} strokeWidth={1.8} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <path d="M12 21s-7-4.534-9.5-9C1.21 9.7 2.5 6 6 6c2 0 3.5 1 6 3.5C14.5 7 16 6 18 6c3.5 0 4.79 3.7 3.5 6-2.5 4.466-9.5 9-9.5 9z" /> </svg> <span className="tabular-nums font-medium">{count}</span> </button> ); }