This is just a technology testing project based on Create React App and TailwindCSS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.0KB

  1. import React from 'react'
  2. import { Field, ErrorMessage } from 'formik'
  3. import FormikControlErrorMessage from '../FormikControlErrorMessage'
  4. import newId from '../../../utils/newId';
  5. function FormikControlCheckbox(props) {
  6. const { name, label, ...rest } = props
  7. return (
  8. <div className="form-control mt-6 mb-4">
  9. <Field name={name}>
  10. {({ field }) => {
  11. const htmlId = newId()
  12. return <>
  13. <label htmlFor={htmlId} className="inline-flex items-center py-1">
  14. <input type="checkbox" id={htmlId} name={name} {...rest} className="form-checkbox text-primary-800" {...field} checked={field.value} />
  15. <span className="ml-4 text-base sm:text-lg ">{label}</span>
  16. </label>
  17. </>
  18. }}
  19. </Field>
  20. <ErrorMessage component={FormikControlErrorMessage} name={name} />
  21. </div>
  22. )
  23. }
  24. export default FormikControlCheckbox