File size: 1,678 Bytes
702763e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use client";

import { useState } from "react";
import classNames from "classnames";

import { Input } from "./input";
import { Select } from "./select";

interface Props {
  loading: boolean;
  onSubmit: (form: FormProps) => void;
}

export interface FormProps {
  username?: string;
  language: Language;
}
export type Language = "en" | "fr" | "es";

export const Form: React.FC<Props> = ({ loading, onSubmit }) => {
  const [form, setForm] = useState<FormProps>({
    username: undefined,
    language: "en",
  });

  return (
    <main className="grid grid-cols-1 gap-6">
      <div>
        <p className="font-semibold text-xs uppercase mb-2 text-zinc-600">
          Hugging Face username
        </p>
        <Input
          value={form.username}
          onChange={(value) => setForm({ ...form, username: value })}
        />
      </div>
      <div>
        <p className="font-semibold text-xs uppercase mb-2 text-zinc-600">
          Language
        </p>
        <Select
          value={form.language}
          onChange={(value) => setForm({ ...form, language: value })}
        />
      </div>
      <div className="flex justify-end">
        <button
          className={classNames(
            "bg-black rounded-full px-5 py-2.5 text-base font-medium text-white hover:bg-zinc-800 disabled:bg-zinc-300 disabled:text-zinc-500 disabled:cursor-not-allowed",
            {
              "animate-pulse": loading,
            }
          )}
          disabled={!form.username || loading}
          onClick={() => onSubmit(form)}
        >
          {loading ? "Roasting in progress..." : "Roast this Hugger 🔥"}
        </button>
      </div>
    </main>
  );
};