el.xwx.moe/components/Checkbox.tsx

35 lines
1023 B
TypeScript
Raw Normal View History

2023-05-15 14:18:33 -05:00
import { faSquare, faSquareCheck } from "@fortawesome/free-regular-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { ChangeEventHandler } from "react";
type Props = {
label: string;
state: boolean;
2023-05-18 13:02:17 -05:00
className?: string;
2023-05-15 14:18:33 -05:00
onClick: ChangeEventHandler<HTMLInputElement>;
};
2023-05-18 13:02:17 -05:00
export default function Checkbox({ label, state, className, onClick }: Props) {
2023-05-15 14:18:33 -05:00
return (
2023-08-11 00:11:02 -05:00
<label className={`cursor-pointer flex items-center gap-2 ${className}`}>
2023-05-15 14:18:33 -05:00
<input
type="checkbox"
checked={state}
onChange={onClick}
className="peer sr-only"
/>
<FontAwesomeIcon
icon={faSquareCheck}
2023-08-30 23:17:27 -05:00
className="w-5 h-5 text-sky-500 dark:text-sky-500 peer-checked:block hidden"
2023-05-15 14:18:33 -05:00
/>
<FontAwesomeIcon
icon={faSquare}
2023-08-30 23:17:27 -05:00
className="w-5 h-5 text-sky-500 dark:text-sky-500 peer-checked:hidden block"
2023-05-15 14:18:33 -05:00
/>
2023-08-11 00:11:02 -05:00
<span className="text-black dark:text-white rounded select-none">
{label}
</span>
2023-05-15 14:18:33 -05:00
</label>
);
}