icon-button-wrapper.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { BS3ButtonProps, mapBsButtonSizes } from './button-wrapper'
  2. import { Button as BS3Button } from 'react-bootstrap'
  3. import type { IconButtonProps } from '@/features/ui/components/types/icon-button-props'
  4. import BootstrapVersionSwitcher from '../bootstrap-version-switcher'
  5. import Icon, { IconProps } from '@/shared/components/icon'
  6. import IconButton from '../icon-button'
  7. export type IconButtonWrapperProps = IconButtonProps & {
  8. bs3Props?: {
  9. loading?: React.ReactNode
  10. fw?: IconProps['fw']
  11. }
  12. }
  13. export default function IconButtonWrapper(props: IconButtonWrapperProps) {
  14. const { bs3Props, ...rest } = props
  15. const { fw, ...filterBs3Props } = bs3Props || {}
  16. const bs3ButtonProps: BS3ButtonProps = {
  17. bsStyle: rest.variant,
  18. bsSize: mapBsButtonSizes(rest.size),
  19. disabled: rest.isLoading || rest.disabled,
  20. form: rest.form,
  21. onClick: rest.onClick,
  22. type: rest.type,
  23. ...filterBs3Props,
  24. }
  25. return (
  26. <BootstrapVersionSwitcher
  27. bs3={
  28. <BS3Button {...bs3ButtonProps}>
  29. {bs3Props?.loading}
  30. <Icon
  31. type={rest.icon}
  32. fw={fw}
  33. accessibilityLabel={rest.accessibilityLabel}
  34. />
  35. </BS3Button>
  36. }
  37. bs5={<IconButton {...rest} />}
  38. />
  39. )
  40. }