Checkbox.tsx 585 B

123456789101112131415161718192021222324
  1. import { JSX } from "preact";
  2. interface CheckboxProps extends JSX.InputHTMLAttributes<HTMLInputElement> {
  3. label?: string;
  4. }
  5. export default function Checkbox({
  6. label,
  7. className = "",
  8. ...props
  9. }: CheckboxProps) {
  10. const checkboxClasses = `w-4 h-4 ${className}`;
  11. if (label) {
  12. return (
  13. <label className="flex items-center">
  14. <input type="checkbox" className={checkboxClasses} {...props} />
  15. {label && <span className="ml-2">{label}</span>}
  16. </label>
  17. );
  18. }
  19. return <input type="checkbox" className={checkboxClasses} {...props} />;
  20. }