Add wrapperClassName prop to Tooltip for full-width layout in sidebar. Hide scrollbar when sidebar is collapsed, show custom scrollbar when open. Fix logout button gap in collapsed sidebar. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import * as React from 'react';
|
|
import { useTooltip } from './useTooltip';
|
|
import { TooltipContent } from './TooltipContent';
|
|
import { cn } from '@/lib/utils';
|
|
import type { TooltipProps } from './types';
|
|
|
|
export function Tooltip({
|
|
content,
|
|
children,
|
|
position = 'top',
|
|
trigger = 'hover',
|
|
delay = 200,
|
|
showArrow = true,
|
|
maxWidth,
|
|
disabled = false,
|
|
className,
|
|
wrapperClassName,
|
|
}: TooltipProps) {
|
|
const {
|
|
visible,
|
|
isMounted,
|
|
calculatedPosition,
|
|
tooltipStyle,
|
|
wrapperRef,
|
|
tooltipRef,
|
|
triggerProps,
|
|
} = useTooltip(position, trigger, delay, disabled);
|
|
|
|
if (disabled) {
|
|
return <>{children}</>;
|
|
}
|
|
|
|
const isHover = trigger === 'hover';
|
|
const wrapperProps = isHover ? triggerProps : {};
|
|
const child =
|
|
!isHover &&
|
|
React.isValidElement(children) &&
|
|
React.Children.only(children)
|
|
? React.cloneElement(children, triggerProps as React.HTMLAttributes<HTMLElement>)
|
|
: children;
|
|
|
|
return (
|
|
<div ref={wrapperRef} className={cn('relative inline-block', wrapperClassName)} {...wrapperProps}>
|
|
{child}
|
|
{isMounted && (
|
|
<TooltipContent
|
|
content={content}
|
|
visible={visible}
|
|
calculatedPosition={calculatedPosition}
|
|
tooltipStyle={tooltipStyle}
|
|
tooltipRef={tooltipRef}
|
|
showArrow={showArrow}
|
|
maxWidth={maxWidth}
|
|
className={className}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|