ol-toggle-button.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { ToggleButton, ToggleButtonProps } from 'react-bootstrap-5'
  2. import {
  3. ToggleButton as BS3ToggleButton,
  4. ToggleButtonProps as BS3ToggleButtonProps,
  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. import classnames from 'classnames'
  9. type OLToggleButtonProps = ToggleButtonProps & {
  10. bs3Props?: BS3ToggleButtonProps
  11. }
  12. function OLToggleButton(props: OLToggleButtonProps) {
  13. const { bs3Props, ...rest } = props
  14. const bs3ToggleButtonProps: BS3ToggleButtonProps & { active?: boolean } = {
  15. type: rest.type,
  16. name: rest.name,
  17. active: rest.active,
  18. checked: rest.checked,
  19. disabled: rest.disabled,
  20. onChange: rest.onChange as BS3ToggleButtonProps['onChange'],
  21. onClick: rest.onClick as BS3ToggleButtonProps['onClick'],
  22. value: rest.value as BS3ToggleButtonProps['value'],
  23. children: rest.children,
  24. className: classnames(`btn-${props.variant || 'primary'}`, rest.className),
  25. ...bs3Props,
  26. }
  27. // Get all `aria-*` and `data-*` attributes
  28. const extraProps = getAriaAndDataProps(rest)
  29. return (
  30. <BootstrapVersionSwitcher
  31. bs3={
  32. <BS3ToggleButton
  33. {...extraProps}
  34. {...bs3ToggleButtonProps}
  35. bsStyle={null}
  36. />
  37. }
  38. bs5={<ToggleButton {...rest} />}
  39. />
  40. )
  41. }
  42. export default OLToggleButton