ol-form-select.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. defaultValue: bs5Props.defaultValue,
  19. disabled: bs5Props.disabled,
  20. onChange: bs5Props.onChange as BS3FormControlProps['onChange'],
  21. required: bs5Props.required,
  22. placeholder: bs5Props.placeholder,
  23. className: bs5Props.className,
  24. ...bs3Props,
  25. }
  26. // Get all `aria-*` and `data-*` attributes
  27. const extraProps = getAriaAndDataProps(bs5Props)
  28. return (
  29. <BootstrapVersionSwitcher
  30. bs3={
  31. <BS3FormControl
  32. componentClass="select"
  33. {...bs3FormSelectProps}
  34. {...extraProps}
  35. />
  36. }
  37. bs5={<Form.Select {...bs5Props} />}
  38. />
  39. )
  40. }
  41. export default OLFormSelect