ol-form.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Form } from 'react-bootstrap-5'
  2. import { Form as BS3Form, FormProps as BS3FormProps } from 'react-bootstrap'
  3. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  4. import { ComponentProps } from 'react'
  5. import classnames from 'classnames'
  6. import { getAriaAndDataProps } from '@/features/utils/bootstrap-5'
  7. type OLFormProps = ComponentProps<typeof Form> & {
  8. bs3Props?: ComponentProps<typeof BS3Form>
  9. }
  10. function OLForm(props: OLFormProps) {
  11. const { bs3Props, ...rest } = props
  12. const bs3FormProps: BS3FormProps = {
  13. componentClass: rest.as,
  14. children: rest.children,
  15. id: rest.id,
  16. onSubmit: rest.onSubmit as BS3FormProps['onSubmit'],
  17. onClick: rest.onClick as BS3FormProps['onClick'],
  18. name: rest.name,
  19. noValidate: rest.noValidate,
  20. role: rest.role,
  21. ...bs3Props,
  22. }
  23. const bs3ClassName = classnames(
  24. rest.className,
  25. rest.validated ? 'was-validated' : null
  26. )
  27. // Get all `aria-*` and `data-*` attributes
  28. const extraProps = getAriaAndDataProps(rest)
  29. return (
  30. <BootstrapVersionSwitcher
  31. bs3={
  32. <BS3Form className={bs3ClassName} {...bs3FormProps} {...extraProps} />
  33. }
  34. bs5={<Form {...rest} />}
  35. />
  36. )
  37. }
  38. export default OLForm