NodeResizer handles positioned at RF wrapper size, but NodeTooltip and NodeStatusIndicator wrappers had no size constraints, causing BaseNode (w-full h-full) to shrink to content size instead of filling the wrapper. Add w-full h-full to NodeTooltip, NodeTooltipTrigger, and NodeStatusIndicator so the full height chain is maintained. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
1.8 KiB
TypeScript
80 lines
1.8 KiB
TypeScript
import { createContext, useContext, useState, useCallback, type ReactNode, type ComponentProps } from 'react'
|
|
import { NodeToolbar, type NodeToolbarProps } from '@xyflow/react'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
interface NodeTooltipContextValue {
|
|
visible: boolean
|
|
show: () => void
|
|
hide: () => void
|
|
}
|
|
|
|
const NodeTooltipContext = createContext<NodeTooltipContextValue>({
|
|
visible: false,
|
|
show: () => {},
|
|
hide: () => {},
|
|
})
|
|
|
|
export function NodeTooltip({ children, className, ...props }: ComponentProps<'div'>) {
|
|
const [visible, setVisible] = useState(false)
|
|
const show = useCallback(() => setVisible(true), [])
|
|
const hide = useCallback(() => setVisible(false), [])
|
|
|
|
return (
|
|
<NodeTooltipContext.Provider value={{ visible, show, hide }}>
|
|
<div className={cn('w-full h-full', className)} {...props}>{children}</div>
|
|
</NodeTooltipContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function NodeTooltipTrigger({
|
|
children,
|
|
className,
|
|
onMouseEnter,
|
|
onMouseLeave,
|
|
...props
|
|
}: ComponentProps<'div'>) {
|
|
const { show, hide } = useContext(NodeTooltipContext)
|
|
|
|
return (
|
|
<div
|
|
className={cn('w-full h-full', className)}
|
|
onMouseEnter={(e) => {
|
|
show()
|
|
onMouseEnter?.(e)
|
|
}}
|
|
onMouseLeave={(e) => {
|
|
hide()
|
|
onMouseLeave?.(e)
|
|
}}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function NodeTooltipContent({
|
|
className,
|
|
position,
|
|
children,
|
|
...props
|
|
}: Omit<NodeToolbarProps, 'children'> & { children: ReactNode }) {
|
|
const { visible } = useContext(NodeTooltipContext)
|
|
|
|
if (!visible) return null
|
|
|
|
return (
|
|
<NodeToolbar
|
|
position={position}
|
|
className={cn(
|
|
'rounded-lg border border-default bg-elevated px-3 py-2',
|
|
'pointer-events-none',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</NodeToolbar>
|
|
)
|
|
}
|