import type { RatingQuestion } from "@formbricks/types/questions"; import { useState } from "react"; import { cn } from "@formbricks/lib/cn"; import Headline from "./Headline"; import Subheader from "./Subheader"; interface RatingQuestionProps { question: RatingQuestion; onSubmit: (data: { [x: string]: any }) => void; lastQuestion: boolean; brandColor: string; } export default function RatingQuestion({ question, onSubmit, lastQuestion, brandColor, }: RatingQuestionProps) { const [selectedChoice, setSelectedChoice] = useState(null); const handleSelect = (number: number) => { setSelectedChoice(number); if (question.required) { onSubmit({ [question.id]: number, }); setSelectedChoice(null); // reset choice } }; return (
{ e.preventDefault(); const data = { [question.id]: selectedChoice, }; setSelectedChoice(null); // reset choice onSubmit(data); }}>
Options
{Array.from({ length: question.range }, (_, i) => i + 1).map((number) => ( ))}

{question.lowerLabel}

{question.upperLabel}

{!question.required && (
)} ); }