"use client"; import * as React from "react"; import { cn } from "./lib/utils"; export interface FeedbackVoteProps extends React.HTMLAttributes { upLabel?: string; downLabel?: string; onVote?: (vote: "up" | "down") => void; } /** Up and down vote pair with live tally stamp. */ export function FeedbackVote({ upLabel = "Useful", downLabel = "Off", onVote, className, ...props }: FeedbackVoteProps) { const [vote, setVote] = React.useState<"up" | "down" | null>(null); const [tally, setTally] = React.useState(42); const cast = (v: "up" | "down") => { if (vote === v) return; setTally((t) => t + (v === "up" ? 1 : -1) - (vote === "up" ? 1 : vote === "down" ? -1 : 0)); setVote(v); onVote?.(v); }; return (
{tally}
); }