| | |
| | | flip, |
| | | offset, |
| | | shift, |
| | | size, |
| | | useDismiss, |
| | | useFloating, |
| | | useFocus, |
| | |
| | | open?: boolean |
| | | offset?: number | OffsetOptions |
| | | onOpenChange?: (open: boolean) => void |
| | | triggerPopupSameWidth?: boolean |
| | | } |
| | | |
| | | export function usePortalToFollowElem({ |
| | |
| | | open, |
| | | offset: offsetValue = 0, |
| | | onOpenChange: setControlledOpen, |
| | | triggerPopupSameWidth, |
| | | }: PortalToFollowElemOptions = {}) { |
| | | const setOpen = setControlledOpen |
| | | |
| | |
| | | padding: 5, |
| | | }), |
| | | shift({ padding: 5 }), |
| | | size({ |
| | | apply({ rects, elements }) { |
| | | if (triggerPopupSameWidth) |
| | | elements.floating.style.width = `${rects.reference.width}px` |
| | | }, |
| | | }), |
| | | ], |
| | | }) |
| | | |
| | |
| | | ) |
| | | } |
| | | |
| | | export const PortalToFollowElemTrigger = ( |
| | | { |
| | | ref: propRef, |
| | | children, |
| | | asChild = false, |
| | | ...props |
| | | }: React.HTMLProps<HTMLElement> & { ref?: React.RefObject<HTMLElement>, asChild?: boolean }, |
| | | ) => { |
| | | export const PortalToFollowElemTrigger = React.forwardRef< |
| | | HTMLElement, |
| | | React.HTMLProps<HTMLElement> & { asChild?: boolean } |
| | | >(({ children, asChild = false, ...props }, propRef) => { |
| | | const context = usePortalToFollowElemContext() |
| | | const childrenRef = (children as any).props?.ref |
| | | const childrenRef = (children as any).ref |
| | | const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef]) |
| | | |
| | | // `asChild` allows the user to pass any element as the anchor |
| | |
| | | {children} |
| | | </div> |
| | | ) |
| | | } |
| | | }) |
| | | PortalToFollowElemTrigger.displayName = 'PortalToFollowElemTrigger' |
| | | |
| | | export const PortalToFollowElemContent = ( |
| | | { |
| | | ref: propRef, |
| | | style, |
| | | ...props |
| | | }: React.HTMLProps<HTMLDivElement> & { |
| | | ref?: React.RefObject<HTMLDivElement>; |
| | | }, |
| | | ) => { |
| | | export const PortalToFollowElemContent = React.forwardRef< |
| | | HTMLDivElement, |
| | | React.HTMLProps<HTMLDivElement> |
| | | >(({ style, ...props }, propRef) => { |
| | | const context = usePortalToFollowElemContext() |
| | | const ref = useMergeRefs([context.refs.setFloating, propRef]) |
| | | |
| | |
| | | /> |
| | | </FloatingPortal> |
| | | ) |
| | | } |
| | | }) |
| | | |
| | | PortalToFollowElemContent.displayName = 'PortalToFollowElemContent' |