mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 02:10:12 -06:00
Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import Headline from "./Headline";
|
|
import Subheader from "./Subheader";
|
|
import { TSurveyOpenTextQuestion } from "./types";
|
|
|
|
interface OpenTextQuestionProps {
|
|
question: TSurveyOpenTextQuestion;
|
|
onSubmit: (data: { [x: string]: any }) => void;
|
|
lastQuestion: boolean;
|
|
brandColor: string;
|
|
}
|
|
|
|
export default function OpenTextQuestion({
|
|
question,
|
|
onSubmit,
|
|
lastQuestion,
|
|
brandColor,
|
|
}: OpenTextQuestionProps) {
|
|
const [value, setValue] = useState<string>("");
|
|
|
|
return (
|
|
<form
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
|
|
const data = {
|
|
[question.id]: value,
|
|
};
|
|
setValue(""); // reset value
|
|
onSubmit(data);
|
|
}}>
|
|
<Headline headline={question.headline} questionId={question.id} />
|
|
<Subheader subheader={question.subheader} questionId={question.id} />
|
|
<div className="mt-4">
|
|
<textarea
|
|
rows={3}
|
|
name={question.id}
|
|
id={question.id}
|
|
value={value}
|
|
onChange={(e) => setValue(e.target.value)}
|
|
placeholder={question.placeholder}
|
|
required={question.required}
|
|
className="block w-full rounded-md border border-slate-100 bg-slate-50 p-2 shadow-sm focus:border-slate-500 focus:ring-0 sm:text-sm dark:border-slate-500 dark:bg-slate-700 dark:text-white"></textarea>
|
|
</div>
|
|
<div className="mt-4 flex w-full justify-between">
|
|
<div></div>
|
|
<button
|
|
type="submit"
|
|
className="flex items-center rounded-md border border-transparent px-3 py-3 text-base font-medium leading-4 text-white shadow-sm hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-slate-500 focus:ring-offset-2"
|
|
style={{ backgroundColor: brandColor }}>
|
|
{question.buttonLabel || (lastQuestion ? "Finish" : "Next")}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|