wwf
3 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
app/components/base/portal-to-follow-elem/index.tsx
@@ -6,7 +6,6 @@
  flip,
  offset,
  shift,
  size,
  useDismiss,
  useFloating,
  useFocus,
@@ -28,7 +27,6 @@
  open?: boolean
  offset?: number | OffsetOptions
  onOpenChange?: (open: boolean) => void
  triggerPopupSameWidth?: boolean
}
export function usePortalToFollowElem({
@@ -36,7 +34,6 @@
  open,
  offset: offsetValue = 0,
  onOpenChange: setControlledOpen,
  triggerPopupSameWidth,
}: PortalToFollowElemOptions = {}) {
  const setOpen = setControlledOpen
@@ -53,12 +50,6 @@
        padding: 5,
      }),
      shift({ padding: 5 }),
      size({
        apply({ rects, elements }) {
          if (triggerPopupSameWidth)
            elements.floating.style.width = `${rects.reference.width}px`
        },
      }),
    ],
  })
@@ -114,16 +105,12 @@
  )
}
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
@@ -150,18 +137,13 @@
      {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])
@@ -182,6 +164,6 @@
      />
    </FloatingPortal>
  )
}
})
PortalToFollowElemContent.displayName = 'PortalToFollowElemContent'