'use client'
import type { MiddlewareState } from '@floating-ui/react'
import {
autoUpdate,
flip,
FloatingFocusManager,
offset,
shift,
size,
useDismiss,
useFloating,
useInteractions,
} from '@floating-ui/react'
import type { PropsWithChildren } from 'react'
import { Portal } from 'rntwsc/components/portal'
import type { ClassName } from 'rntwsc/tw/class-name'
import { clsx } from 'rntwsc/tw/clsx'
export type DropdownProps = PropsWithChildren<{
open: boolean
onClose: () => void
reference: any
}>
const Item = ({ open, onClose, reference, children }: DropdownProps) => {
const { refs, floatingStyles, context } = useFloating({
open,
onOpenChange: v => !v && onClose(),
placement: 'bottom-start',
elements: {
reference,
},
middleware: [
offset(4),
flip({
padding: 8,
}),
shift({
padding: 8,
}),
size({
apply: ({ rects, elements }: MiddlewareState) => {
elements.floating.style.minWidth = `${rects.reference.width}px`
},
padding: 8,
}),
],
whileElementsMounted: autoUpdate,
})
const dismiss = useDismiss(context)
const { getFloatingProps } = useInteractions([dismiss])
if (!open || !reference) {
return null
}
return (