import { createStyledContext } from '@tamagui/core' import { getPortal } from '@tamagui/native' import { createContext, type ComponentType } from 'react' import type { SelectContextValue, SelectItemParentContextValue } from './types' // zIndex flows from root Select prop to SelectContent portal export const SelectZIndexContext = createContext(undefined) // the behavior surface renders a raw native select. the styled tamagui surface // supplies its native-select skin through this slot. export const SelectNativeComponentContext = createContext | null>(null) export const { Provider: SelectProvider, useStyledContext: useSelectContext } = createStyledContext(null as any, 'Select') // these values shouldn't change as often for performance to avoid re-rendering every item export const { Provider: SelectItemParentProvider, useStyledContext: useSelectItemParentContext, } = createStyledContext(null as any, 'SelectItem') export const ForwardSelectContext = ({ context, itemContext, children, }: { children?: any context: SelectContextValue itemContext: SelectItemParentContextValue }) => { // when teleport is enabled, context is automatically preserved // so we can skip the forwarding logic for better performance const portalState = getPortal().state if (portalState.type === 'teleport') { return children } // fall back to context forwarding for legacy portal implementations return ( {children} ) }