import { Participant } from "@prisma/client"; import clsx from "clsx"; import { AnimatePresence, motion } from "framer-motion"; import * as React from "react"; import UserAvater from "../user-avatar"; import VoteIcon from "../vote-icon"; import PopularityScore from "./popularity-score"; export interface PollOptionProps { children?: React.ReactNode; numberOfVotes: number; editable?: boolean; vote?: "yes" | "no"; onChange: (vote: "yes" | "no") => void; participants: Participant[]; selectedParticipantId?: string; } const CollapsibleContainer: React.VoidFunctionComponent<{ expanded?: boolean; children?: React.ReactNode; className?: string; }> = ({ className, children, expanded }) => { return ( {children} ); }; const PopInOut: React.VoidFunctionComponent<{ children?: React.ReactNode; className?: string; }> = ({ children, className }) => { return ( {children} ); }; const PollOption: React.VoidFunctionComponent = ({ children, selectedParticipantId, vote, onChange, participants, editable, numberOfVotes, }) => { const difference = selectedParticipantId ? participants.some(({ id }) => id === selectedParticipantId) ? vote === "yes" ? 0 : -1 : vote === "yes" ? 1 : 0 : vote === "yes" ? 1 : 0; const showVotes = !!(selectedParticipantId || editable); return (
{ onChange(vote === "yes" ? "no" : "yes"); }} className={clsx( "flex items-center space-x-3 px-4 py-3 transition duration-75", { "active:bg-indigo-50": editable, "bg-indigo-50/50": editable && vote === "yes", }, )} >
{children}
{participants.length > 0 ? (
{participants .slice(0, participants.length <= 6 ? 6 : 5) .map((participant, i) => { return ( ); })} {participants.length > 6 ? ( +{participants.length - 5} ) : null}
) : null}
{editable ? (
) : vote ? ( ) : null}
); }; export default PollOption;