This is just a technology testing project based on Create React App and TailwindCSS
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

47 lines
2.1KB

  1. import React from 'react'
  2. import { Field, ErrorMessage } from 'formik'
  3. import FormikControlErrorMessage from '../FormikControlErrorMessage'
  4. import newId from '../../../utils/newId';
  5. function FormikControlUserConsent(props) {
  6. const { name, label_template, label_action, ...rest } = props
  7. const label = label_template.replace(/#+/g, '')
  8. const Link = ({ label_template, label_action }) => {
  9. const rx = /^([^#]*)#([^#]+)#([^#]*)$/
  10. if (!label_template || !label_template.match(rx)) return false
  11. const parts = label_template.split(rx);
  12. return <>
  13. {parts[1]}<button type="button" tabIndex="0" onClick={label_action} className="text-primary-800 hover:underline flex-grow rounded-md outline-none focus:outline-none focus:shadow-outline">{parts[2]}</button>{parts[3]}
  14. </>
  15. }
  16. if (!Link({ label_template, label_action })) return false
  17. const htmlId = newId()
  18. return (
  19. <div className="form-control mt-6 mb-4">
  20. <Field name={name}>
  21. {({ field }) => {
  22. return <>
  23. <label htmlFor={htmlId} className="flex items-center p-1 rounded-md cursor-pointer hover:bg-gray-100">
  24. <input
  25. type="checkbox"
  26. id={htmlId}
  27. title={label}
  28. name={name}
  29. {...rest}
  30. className="form-checkbox text-primary-800"
  31. {...field}
  32. checked={field.value}
  33. aria-describedby={name + 'Error'}
  34. />
  35. <span className="ml-8 text-base sm:text-lg "><Link label_template={label_template} label_action={label_action} /></span>
  36. </label>
  37. </>
  38. }}
  39. </Field>
  40. <ErrorMessage component={FormikControlErrorMessage} name={name} label={label} id={name + 'Error'} />
  41. </div>
  42. )
  43. }
  44. export default FormikControlUserConsent