(props: {
onChange: (checked: boolean) => void;
checked: boolean;
label: string;
size?: "sm" | "lg";
})
| 2 | import classNames from "classnames"; |
| 3 | |
| 4 | export default function Checkbox(props: { |
| 5 | onChange: (checked: boolean) => void; |
| 6 | checked: boolean; |
| 7 | label: string; |
| 8 | size?: "sm" | "lg"; |
| 9 | }) { |
| 10 | const size = props.size ?? "sm"; |
| 11 | return ( |
| 12 | <div |
| 13 | className="relative flex flex-row place-items-center cursor-pointer" |
| 14 | onClick={(e) => { |
| 15 | e.stopPropagation(); |
| 16 | props.onChange(!props.checked); |
| 17 | }} |
| 18 | > |
| 19 | <div |
| 20 | className={classNames( |
| 21 | "mr-2", |
| 22 | size === "sm" ? "text-xs md:text-sm" : "text-base md:text-lg", |
| 23 | )} |
| 24 | > |
| 25 | {props.label && ( |
| 26 | <> |
| 27 | <label className="font-medium text-gray-300 cursor-pointer select-none"> |
| 28 | {props.label} |
| 29 | </label> |
| 30 | <span className="sr-only">{props.label}</span> |
| 31 | </> |
| 32 | )} |
| 33 | </div> |
| 34 | <div |
| 35 | className={classNames( |
| 36 | "flex items-center", |
| 37 | size === "sm" ? "h-6" : "h-10", |
| 38 | )} |
| 39 | > |
| 40 | <input |
| 41 | id={props.label} |
| 42 | type="checkbox" |
| 43 | className={classNames( |
| 44 | "rounded border-gray-300 text-purple-700 focus:ring-purple-600 cursor-pointer", |
| 45 | size === "sm" ? "h-4.5 w-4.5" : "h-6 w-6", |
| 46 | )} |
| 47 | onChange={(e) => props.onChange(e.target.checked)} |
| 48 | checked={props.checked} |
| 49 | /> |
| 50 | </div> |
| 51 | </div> |
| 52 | ); |
| 53 | } |
nothing calls this directly
no test coverage detected