el.xwx.moe/components/Checkbox.tsx
2023-08-11 01:11:02 -04:00

35 lines
1023 B
TypeScript

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;
className?: string;
onClick: ChangeEventHandler<HTMLInputElement>;
};
export default function Checkbox({ label, state, className, onClick }: Props) {
return (
<label className={`cursor-pointer flex items-center gap-2 ${className}`}>
<input
type="checkbox"
checked={state}
onChange={onClick}
className="peer sr-only"
/>
<FontAwesomeIcon
icon={faSquareCheck}
className="w-5 h-5 text-sky-500 dark:text-sky-300 peer-checked:block hidden"
/>
<FontAwesomeIcon
icon={faSquare}
className="w-5 h-5 text-sky-500 dark:text-sky-300 peer-checked:hidden block"
/>
<span className="text-black dark:text-white rounded select-none">
{label}
</span>
</label>
);
}