ol-form-checkbox.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Form, FormCheckProps } from 'react-bootstrap'
  2. import { MergeAndOverride } from '../../../../../types/utils'
  3. import FormText from '../form/form-text'
  4. type OLFormCheckboxProps = MergeAndOverride<
  5. FormCheckProps,
  6. {
  7. inputRef?: React.MutableRefObject<HTMLInputElement | null>
  8. } & (
  9. | { description: string; id: string }
  10. | { description?: undefined; id?: string }
  11. )
  12. >
  13. function OLFormCheckbox(props: OLFormCheckboxProps) {
  14. const { inputRef, ...rest } = props
  15. return rest.type === 'radio' ? (
  16. <Form.Check
  17. ref={inputRef}
  18. aria-describedby={rest.description ? `${rest.id}-description` : undefined}
  19. {...rest}
  20. label={
  21. <>
  22. {rest.label}
  23. {rest.description && (
  24. <FormText
  25. id={`${rest.id}-description`}
  26. className="form-check-label-description"
  27. >
  28. {rest.description}
  29. </FormText>
  30. )}
  31. </>
  32. }
  33. />
  34. ) : (
  35. <Form.Check className="form-checkbox" ref={inputRef} {...rest} />
  36. )
  37. }
  38. export default OLFormCheckbox