ARatingForm.tsx 1.12 KB
Newer Older
1
import React, { useState } from "react";
Lee SeoYeon's avatar
Lee SeoYeon committed
2
3
4
5
6
7
8
import { RatingType } from "../types";

type Props = {
  element: RatingType;
};

export const ARatingForm = ({ element }: Props) => {
9
10
11
12
13
  const [selectedchoice, setSelectedchoice] = useState("");
  function buttonClick(event: React.MouseEvent<HTMLButtonElement>) {
    event.preventDefault();
    setSelectedchoice(event.currentTarget.name);
  }
Lee SeoYeon's avatar
Lee SeoYeon committed
14
  return (
15
16
    <div className="flex w-full justify-center space-x-12 my-3">
      <label className="mt-3">{element.content.minRateDescription}</label>
Lee SeoYeon's avatar
Lee SeoYeon committed
17
      {element.content.choices.map((choice) => (
18
19
20
21
22
23
24
25
26
27
28
29
30
        <div className="flex gap-4">
          <button
            type="button"
            className="border border-themeColor rounded-full w-12 h-12 text-center hover:bg-slate-300"
            name={choice.text}
            onClick={buttonClick}
            style={{
              backgroundColor:
                selectedchoice === choice.text ? "#58ACFA" : "white",
            }}
          >
            {choice.text}
          </button>
Lee SeoYeon's avatar
Lee SeoYeon committed
31
32
        </div>
      ))}
33
      <label className="mt-3">{element.content.maxRateDescription}</label>
Lee SeoYeon's avatar
Lee SeoYeon committed
34
35
36
    </div>
  );
};