import {Children, createContext, useContext, useMemo} from 'react' import {View} from 'react-native' import {utils} from '@bsky.app/alf' import {Popover} from 'radix-ui' import {atoms as a, flatten, select, useTheme} from '#/alf' import { ARROW_SIZE, BUBBLE_MAX_WIDTH, MIN_EDGE_SPACE, } from '#/components/Tooltip/const' import {Text} from '#/components/Typography' // Portal Provider on native, but we actually don't need to do anything here export function Provider({children}: {children: React.ReactNode}) { return <>{children} } Provider.displayName = 'TooltipProvider' type TooltipContextType = { position: 'top' | 'bottom' onVisibleChange: (open: boolean) => void } const TooltipContext = createContext>({ position: 'bottom', }) TooltipContext.displayName = 'TooltipContext' export function Outer({ children, position = 'bottom', visible, onVisibleChange, }: { children: React.ReactNode position?: 'top' | 'bottom' visible: boolean onVisibleChange: (visible: boolean) => void }) { const ctx = useMemo(() => ({position}), [position]) return ( {children} ) } export function Target({children}: {children: React.ReactNode}) { return ( {children} ) } export function Content({ children, label, }: { children: React.ReactNode label: string }) { const t = useTheme() const {position} = useContext(TooltipContext) return ( { if (evt.type === 'dismissableLayer.focusOutside') { evt.preventDefault() } }} style={flatten([ a.rounded_sm, select(t.name, { light: t.atoms.bg, dark: t.atoms.bg_contrast_100, dim: t.atoms.bg_contrast_100, }), { minWidth: 'max-content', boxShadow: select(t.name, { light: `0 0 24px ${utils.alpha(t.palette.black, 0.2)}`, dark: `0 0 24px ${utils.alpha(t.palette.black, 0.2)}`, dim: `0 0 24px ${utils.alpha(t.palette.black, 0.2)}`, }), }, ])}> {children} ) } export function TextBubble({children}: {children: React.ReactNode}) { const c = Children.toArray(children) return ( {c.map((child, i) => ( {child} ))} ) }