import { createStyledHOC, styled, View } from '@tamagui/core' import { autoUpdate, useFloatingRaw as useFloating } from '@tamagui/floating' import { useComposedRefs } from '@tamagui/compose-refs' import type { TamaguiElement } from '@tamagui/core' import { composeEventHandlers } from '@tamagui/helpers' import * as React from 'react' import { useSelectContext } from './context' import type { SelectScopedProps, SelectScrollButtonImplProps, SelectScrollButtonProps, SelectScrollButtonExtraProps, SelectScrollButtonImplExtraProps, } from './types' /* ------------------------------------------------------------------------------------------------- * SelectScrollUpButton * -----------------------------------------------------------------------------------------------*/ const SCROLL_UP_BUTTON_NAME = 'SelectScrollUpButton' export const SelectScrollButtonFrame = styled(View, { displayName: 'SelectScrollButton', }) export const SelectScrollUpButton = createStyledHOC( SelectScrollButtonFrame, (propsIn: SelectScrollButtonExtraProps, forwardedRef) => { const props: SelectScopedProps = propsIn return ( ) } ) SelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME /* ------------------------------------------------------------------------------------------------- * SelectScrollDownButton * -----------------------------------------------------------------------------------------------*/ const SCROLL_DOWN_BUTTON_NAME = 'SelectScrollDownButton' export const SelectScrollDownButton = createStyledHOC( SelectScrollButtonFrame, (propsIn: SelectScrollButtonExtraProps, forwardedRef) => { const props: SelectScopedProps = propsIn return ( ) } ) SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME const SelectScrollButtonImpl = React.memo( createStyledHOC( SelectScrollButtonFrame, (propsIn: SelectScrollButtonImplExtraProps, forwardedRef) => { const props: SelectScrollButtonImplProps = propsIn const { scope, dir, partClassName, ...scrollIndicatorProps } = props const { className, onPointerEnter, onPointerLeave, ...frameProps } = scrollIndicatorProps const { open, ...context } = useSelectContext(scope) const floatingRef = context.floatingContext?.refs.floating const isVisible = context[dir === 'down' ? 'canScrollDown' : 'canScrollUp'] const frameRef = React.useRef(null) const arrowRef = dir === 'up' ? context.upArrowRef : context.downArrowRef const { x, y, refs, strategy } = useFloating({ open: open && isVisible, strategy: 'fixed', elements: { reference: floatingRef?.current, }, placement: dir === 'up' ? 'top' : 'bottom', whileElementsMounted: autoUpdate, }) const setFloatingRef = React.useCallback( (node: TamaguiElement | null) => { refs.setFloating(node as HTMLElement | null) if (arrowRef) arrowRef.current = node as HTMLDivElement | null }, [refs.setFloating, arrowRef] ) const composedRef = useComposedRefs(forwardedRef, setFloatingRef) React.useEffect(() => { return () => cancelAnimationFrame(frameRef.current) }, [isVisible]) return (