Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133import {createContext, useContext, useMemo} from 'react'import {View} from 'react-native'import {utils} from '@bsky.app/alf'import * as Popover from '@radix-ui/react-popover'
import {atoms as a, flattenToCSS, useTheme} from '#/alf'import { ARROW_SIZE, BUBBLE_MAX_WIDTH, getTooltipStyle, MIN_EDGE_SPACE, type TooltipColor,} from '#/components/Tooltip/const'import {Text} from '#/components/Typography'
// Portal Provider on native, but we actually don't need to do anything hereexport function Provider({children}: {children: React.ReactNode}) { return <>{children}</>}Provider.displayName = 'TooltipProvider'
type TooltipContextType = { position: 'top' | 'bottom' color: TooltipColor onVisibleChange: (open: boolean) => void}
const TooltipContext = createContext< Pick<TooltipContextType, 'position' | 'color'>>({ position: 'bottom', color: 'default',})TooltipContext.displayName = 'TooltipContext'
export function Outer({ children, position = 'bottom', color = 'default', visible, onVisibleChange,}: { children: React.ReactNode position?: 'top' | 'bottom' color?: TooltipColor visible: boolean onVisibleChange: (visible: boolean) => void}) { const ctx = useMemo(() => ({position, color}), [position, color]) return ( <Popover.Root open={visible} onOpenChange={onVisibleChange}> <TooltipContext.Provider value={ctx}>{children}</TooltipContext.Provider> </Popover.Root> )}
export function Target({children}: {children: React.ReactNode}) { return ( <Popover.Trigger asChild> <View collapsable={false}>{children}</View> </Popover.Trigger> )}
export function Content({ children, label,}: { children: React.ReactNode label: string}) { const t = useTheme() const {position, color} = useContext(TooltipContext) const style = getTooltipStyle(t, color) return ( <Popover.Portal> <Popover.Content className="radix-popover-content" aria-label={label} side={position} sideOffset={4} collisionPadding={MIN_EDGE_SPACE} onInteractOutside={evt => { if (evt.type === 'dismissableLayer.focusOutside') { evt.preventDefault() } }} style={flattenToCSS([ a.rounded_sm, { backgroundColor: style.surface, borderColor: style.border.color, borderWidth: style.border.width, borderStyle: 'solid', minWidth: 'max-content', boxShadow: `0 0 24px ${utils.alpha(t.palette.black, 0.2)}`, }, ])}> <Popover.Arrow width={ARROW_SIZE} height={ARROW_SIZE / 2} fill={style.surface} /> <View style={[a.px_md, a.py_sm, {maxWidth: BUBBLE_MAX_WIDTH}]}> {children} </View> </Popover.Content> </Popover.Portal> )}
export function BubbleText({ children, label,}: { children: React.ReactNode label: string}) { const t = useTheme() const {color} = useContext(TooltipContext) const style = getTooltipStyle(t, color) // eslint-disable-next-line bsky-internal/avoid-unwrapped-text return ( <Content label={label}> <View style={[a.gap_xs]}> <Text style={[a.text_sm, a.leading_snug, {color: style.text}]}> {children} </Text> </View> </Content> )}