| 123 | // Radix ignores touch pointers, so phones never see the card and a tap goes |
| 124 | // straight to the entry's own destination. |
| 125 | export const PlusPreview = ({ |
| 126 | children, |
| 127 | side = 'right', |
| 128 | align = 'start', |
| 129 | onAction, |
| 130 | onOpen, |
| 131 | context, |
| 132 | }: PlusPreviewProps): ReactElement => { |
| 133 | // After a click the card stays shut until the pointer leaves, otherwise the |
| 134 | // open delay re-fires on the trigger while the next page loads. |
| 135 | const [open, setOpen] = useState(false); |
| 136 | const suppressOpenRef = useRef(false); |
| 137 | |
| 138 | const onOpenChange = useCallback( |
| 139 | (next: boolean) => { |
| 140 | if (next && suppressOpenRef.current) { |
| 141 | return; |
| 142 | } |
| 143 | if (next) { |
| 144 | onOpen?.(); |
| 145 | } |
| 146 | setOpen(next); |
| 147 | }, |
| 148 | [onOpen], |
| 149 | ); |
| 150 | |
| 151 | return ( |
| 152 | <HoverCardPrimitive.Root |
| 153 | openDelay={PREVIEW_OPEN_DELAY} |
| 154 | closeDelay={PREVIEW_CLOSE_DELAY} |
| 155 | open={open} |
| 156 | onOpenChange={onOpenChange} |
| 157 | > |
| 158 | <HoverCardPrimitive.Trigger |
| 159 | asChild |
| 160 | onClick={() => { |
| 161 | suppressOpenRef.current = true; |
| 162 | setOpen(false); |
| 163 | }} |
| 164 | onPointerLeave={() => { |
| 165 | suppressOpenRef.current = false; |
| 166 | }} |
| 167 | onBlur={() => { |
| 168 | suppressOpenRef.current = false; |
| 169 | }} |
| 170 | > |
| 171 | {children} |
| 172 | </HoverCardPrimitive.Trigger> |
| 173 | <HoverCardPrimitive.Portal> |
| 174 | <HoverCardPrimitive.Content |
| 175 | side={side} |
| 176 | align={align} |
| 177 | sideOffset={8} |
| 178 | collisionPadding={12} |
| 179 | className="rail-popup-panel z-tooltip" |
| 180 | > |
| 181 | <PlusPreviewCard onAction={onAction} context={context} /> |
| 182 | </HoverCardPrimitive.Content> |