ol-form-select.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Form, FormSelectProps } from 'react-bootstrap-5'
  2. import {
  3. FormControl as BS3FormControl,
  4. FormControlProps as BS3FormControlProps,
  5. } from 'react-bootstrap'
  6. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  7. import { getAriaAndDataProps } from '@/features/utils/bootstrap-5'
  8. type OLFormSelectProps = FormSelectProps & {
  9. bs3Props?: Record<string, unknown>
  10. }
  11. function OLFormSelect(props: OLFormSelectProps) {
  12. const { bs3Props, ...bs5Props } = props
  13. const bs3FormSelectProps: BS3FormControlProps = {
  14. children: bs5Props.children,
  15. bsSize: bs5Props.size,
  16. name: bs5Props.name,
  17. value: bs5Props.value,
  18. disabled: bs5Props.disabled,
  19. onChange: bs5Props.onChange as BS3FormControlProps['onChange'],
  20. required: bs5Props.required,
  21. placeholder: bs5Props.placeholder,
  22. className: bs5Props.className,
  23. ...bs3Props,
  24. }
  25. // Get all `aria-*` and `data-*` attributes
  26. const extraProps = getAriaAndDataProps(bs5Props)
  27. return (
  28. <BootstrapVersionSwitcher
  29. bs3={
  30. <BS3FormControl
  31. componentClass="select"
  32. {...bs3FormSelectProps}
  33. {...extraProps}
  34. />
  35. }
  36. bs5={<Form.Select {...bs5Props} />}
  37. />
  38. )
  39. }
  40. export default OLFormSelect