2023-04-26 03:52:25 -04:00
|
|
|
import { forwardRef } from 'react'
|
2024-10-14 04:00:41 -04:00
|
|
|
import Tooltip from '../../../../shared/components/tooltip'
|
2023-04-26 03:52:25 -04:00
|
|
|
import classnames from 'classnames'
|
|
|
|
import { DropdownProps } from 'react-bootstrap'
|
2024-10-14 04:00:41 -04:00
|
|
|
import { MergeAndOverride } from '../../../../../../types/utils'
|
2023-04-26 03:52:25 -04:00
|
|
|
|
|
|
|
type CustomToggleProps = MergeAndOverride<
|
2023-05-12 05:19:05 -04:00
|
|
|
Pick<DropdownProps, 'bsClass' | 'open'>,
|
2023-04-26 03:52:25 -04:00
|
|
|
{
|
|
|
|
children: React.ReactNode
|
2023-08-29 06:12:50 -04:00
|
|
|
isOpened: boolean
|
2023-04-26 03:52:25 -04:00
|
|
|
bsRole: 'toggle'
|
|
|
|
className?: string
|
|
|
|
tooltipProps: Omit<React.ComponentProps<typeof Tooltip>, 'children'>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
|
|
|
|
const DropdownToggleWithTooltip = forwardRef<
|
|
|
|
HTMLButtonElement,
|
|
|
|
CustomToggleProps
|
|
|
|
>(function (props, ref) {
|
|
|
|
const {
|
|
|
|
tooltipProps,
|
2023-08-29 06:12:50 -04:00
|
|
|
isOpened,
|
2023-04-26 03:52:25 -04:00
|
|
|
children,
|
|
|
|
bsClass,
|
|
|
|
className,
|
2023-05-12 05:19:05 -04:00
|
|
|
open,
|
2023-04-26 03:52:25 -04:00
|
|
|
bsRole: _bsRole,
|
|
|
|
...rest
|
|
|
|
} = props
|
|
|
|
|
2023-08-29 06:12:50 -04:00
|
|
|
const button = (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
ref={ref}
|
|
|
|
className={classnames(bsClass, 'btn', className)}
|
|
|
|
aria-expanded={open}
|
|
|
|
aria-haspopup="true"
|
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
|
2023-04-26 03:52:25 -04:00
|
|
|
return (
|
2023-08-29 06:12:50 -04:00
|
|
|
<>{isOpened ? button : <Tooltip {...tooltipProps}>{button}</Tooltip>}</>
|
2023-04-26 03:52:25 -04:00
|
|
|
)
|
|
|
|
})
|
2023-08-29 06:12:50 -04:00
|
|
|
|
2023-04-26 03:52:25 -04:00
|
|
|
DropdownToggleWithTooltip.displayName = 'DropdownToggleWithTooltip'
|
|
|
|
|
|
|
|
export default DropdownToggleWithTooltip
|