import type { CSSProperties } from 'react' import type { PickerLabels } from '../labels' import type { TriggerRenderProps } from '../render-props' import type { PickerTheme } from '../theme' import { injectSpinnerStyle } from './spinner-style' injectSpinnerStyle() type PickerTriggerProps = { label: string value: string | null placeholder: string isLoading: boolean isDisabled: boolean disabledHint?: string hasError: boolean fallbackValue: string theme: PickerTheme labels: PickerLabels testID?: string | undefined id?: string | undefined renderTrigger?: ((props: TriggerRenderProps) => React.ReactNode) | undefined onFallbackChange: (text: string) => void onPress: () => void style?: CSSProperties className?: string | undefined } export function PickerTrigger({ label, value, placeholder, isLoading, isDisabled, disabledHint, hasError, fallbackValue, theme, labels, testID, id, renderTrigger, onFallbackChange, onPress, style, className, }: PickerTriggerProps) { if (renderTrigger) { return ( <> {renderTrigger({ label, displayValue: value, placeholder, isLoading, isDisabled, hasError, onPress, })} > ) } const containerStyle: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 6, ...style, } const labelStyle: CSSProperties = { fontSize: 13, fontWeight: 500, color: theme.labelColor, } const inputBaseStyle: CSSProperties = { display: 'flex', alignItems: 'center', justifyContent: 'space-between', height: 40, borderRadius: 8, border: `1px solid ${isDisabled ? theme.disabledBorderColor : theme.borderColor}`, backgroundColor: isDisabled ? theme.disabledBackground : theme.triggerBackground, paddingInline: 12, fontSize: 14, cursor: isDisabled ? 'default' : 'pointer', width: '100%', boxSizing: 'border-box', outline: 'none', fontFamily: 'inherit', transition: 'border-color 0.15s, background-color 0.15s', } const triggerAccessibilityLabel = isLoading ? labels.loadingLabel(label) : value ? labels.selectedValueLabel(label, value) : placeholder return (