Checkbox.tsx 569 B

123456789101112131415161718192021222324252627282930313233
  1. import { DetailedHTMLProps, InputHTMLAttributes } from 'react'
  2. type ICheckbox = {
  3. value?: boolean
  4. label?: string
  5. } & Omit<
  6. DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>,
  7. 'value'
  8. >
  9. const Checkbox = ({
  10. name,
  11. label,
  12. id,
  13. value = false,
  14. type,
  15. ...props
  16. }: ICheckbox) => {
  17. return (
  18. <>
  19. {label && <label htmlFor={id || name}>{label}</label>}
  20. <input
  21. id={id || label}
  22. name={name}
  23. checked={value}
  24. type='checkbox'
  25. {...props}
  26. />
  27. </>
  28. )
  29. }
  30. export default Checkbox