-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheckbox.tsx
More file actions
66 lines (62 loc) · 1.84 KB
/
Checkbox.tsx
File metadata and controls
66 lines (62 loc) · 1.84 KB
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
64
65
66
import React from "react";
import { FieldErrors, UseFormRegisterReturn } from "react-hook-form";
import { Filters } from "../../types/opportunities.ts";
interface CheckBoxProps {
formHook: UseFormRegisterReturn;
errors: FieldErrors<{
semesters: never[];
years: never[];
credits: never[];
hourlyPay: string;
majors: never[];
}>;
errorMessage: string;
name: string;
label: string;
options: string[];
type?: "checkbox" | "radio";
filters?: Filters
};
export default function CheckBox({
formHook,
errors,
errorMessage,
name,
label,
options,
type,
filters,
}: CheckBoxProps) {
return (
<div>
<div className="check-input">
<div className="label">
<span className="label-text font-medium">{label}</span>
</div>
{errors && errors[name as keyof typeof errors] && (
<p className="text-red-500">{errorMessage}</p>
)}
<div className="flex2">
{options &&
options.map((item) => {
return (
<div key={item} className="form-control">
<label className="cursor-pointer label">
<span className="label-text">{item}</span>
<input
type={type === "radio" ? "radio" : "checkbox"}
value={item}
{...formHook}
id={item}
className={type === "radio" ? "radio" : "checkbox"}
defaultChecked={(name === "semesters" && filters?.semesters?.includes(item)) || (name === "years" && filters?.years?.includes(Number(item))) || (name === "credits" && filters?.credits?.includes(item) ? true : false)}
/>
</label>
</div>
);
})}
</div>
</div>
</div>
);
};