Checkbox.tsx 840 B

123456789101112131415161718192021222324252627282930
  1. import * as React from 'react';
  2. import { InputLabel } from 'components/common/Input/InputLabel.styled';
  3. import { FormError, InputHint } from 'components/common/Input/Input.styled';
  4. import { ErrorMessage } from '@hookform/error-message';
  5. export interface CheckboxProps {
  6. name: string;
  7. label: React.ReactNode;
  8. hint?: string;
  9. onChange?: (event: React.SyntheticEvent<HTMLInputElement>) => void;
  10. }
  11. const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
  12. ({ name, label, hint, onChange }, ref) => {
  13. return (
  14. <div>
  15. <InputLabel>
  16. <input type="checkbox" ref={ref} onChange={onChange} />
  17. {label}
  18. </InputLabel>
  19. <InputHint>{hint}</InputHint>
  20. <FormError>
  21. <ErrorMessage name={name} />
  22. </FormError>
  23. </div>
  24. );
  25. }
  26. );
  27. export default Checkbox;