import { forwardRef } from 'react' import BootstrapVersionSwitcher from '../bootstrap-5/bootstrap-version-switcher' import { Button as BS3Button } from 'react-bootstrap' import type { ButtonProps } from '@/features/ui/components/types/button-props' import type { ButtonProps as BS3ButtonPropsBase } from 'react-bootstrap' import Button from '../bootstrap-5/button' import classnames from 'classnames' import { getAriaAndDataProps } from '@/features/utils/bootstrap-5' import { callFnsInSequence } from '@/utils/functions' export type BS3ButtonSize = 'xsmall' | 'sm' | 'medium' | 'lg' export type OLButtonProps = ButtonProps & { bs3Props?: { loading?: React.ReactNode bsSize?: BS3ButtonSize block?: boolean className?: string onMouseOver?: React.MouseEventHandler onMouseOut?: React.MouseEventHandler onFocus?: React.FocusEventHandler onBlur?: React.FocusEventHandler } } // Resolve type mismatch of the onClick event handler export type BS3ButtonProps = Omit & { onClick?: React.MouseEventHandler } export function bs3ButtonProps(props: ButtonProps) { const bs3ButtonProps: BS3ButtonProps = { bsStyle: null, bsSize: props.size, className: classnames(`btn-${props.variant || 'primary'}`, props.className), disabled: props.isLoading || props.disabled, form: props.form, href: props.href, target: props.target, rel: props.rel, onClick: props.onClick, onMouseDown: props.onMouseDown as BS3ButtonProps['onMouseDown'], type: props.type, draggable: props.draggable, download: props.download, style: props.style, active: props.active, } return bs3ButtonProps } const OLButton = forwardRef( ({ bs3Props = {}, ...rest }, ref) => { const { className: _, ...restBs3Props } = bs3Props // BS3 OverlayTrigger automatically provides 'onMouseOver', 'onMouseOut', 'onFocus', 'onBlur' event handlers const bs3FinalProps = { ...restBs3Props, onMouseOver: callFnsInSequence(bs3Props?.onMouseOver, rest.onMouseOver), onMouseOut: callFnsInSequence(bs3Props?.onMouseOut, rest.onMouseOut), onFocus: callFnsInSequence(bs3Props?.onFocus, rest.onFocus), onBlur: callFnsInSequence(bs3Props?.onBlur, rest.onBlur), } // Get all `aria-*` and `data-*` attributes const extraProps = getAriaAndDataProps(rest) return ( | undefined} > {bs3Props?.loading || rest.children} } bs5={