overleaf/services/web/frontend/js/features/ui/components/bootstrap-3/dropdown-toggle-with-tooltip.tsx
Tim Down 4138f9707a Merge pull request #20860 from overleaf/td-bs5-history-versions-list
Migrate history versions list to Bootstrap 5

GitOrigin-RevId: 4e006ad353cb11eadaefb2df41d2b8591003c664
2024-10-14 11:11:01 +00:00

53 lines
1.2 KiB
TypeScript

import { forwardRef } from 'react'
import Tooltip from '../../../../shared/components/tooltip'
import classnames from 'classnames'
import { DropdownProps } from 'react-bootstrap'
import { MergeAndOverride } from '../../../../../../types/utils'
type CustomToggleProps = MergeAndOverride<
Pick<DropdownProps, 'bsClass' | 'open'>,
{
children: React.ReactNode
isOpened: boolean
bsRole: 'toggle'
className?: string
tooltipProps: Omit<React.ComponentProps<typeof Tooltip>, 'children'>
}
>
const DropdownToggleWithTooltip = forwardRef<
HTMLButtonElement,
CustomToggleProps
>(function (props, ref) {
const {
tooltipProps,
isOpened,
children,
bsClass,
className,
open,
bsRole: _bsRole,
...rest
} = props
const button = (
<button
type="button"
ref={ref}
className={classnames(bsClass, 'btn', className)}
aria-expanded={open}
aria-haspopup="true"
{...rest}
>
{children}
</button>
)
return (
<>{isOpened ? button : <Tooltip {...tooltipProps}>{button}</Tooltip>}</>
)
})
DropdownToggleWithTooltip.displayName = 'DropdownToggleWithTooltip'
export default DropdownToggleWithTooltip