import React, { useEffect, useMemo, useRef, useState } from 'react'; import type { OptionEntry } from '../../data/locales'; /** Props for {@link SearchableSelect}. */ interface SearchableSelectProps { /** Currently-selected option ``value`` (matches ``OptionEntry.value``). */ value: string; /** Fired with the new ``value`` once the merchant picks an option. */ onChange: (next: string) => void; /** Picker entries - both label and value are searchable substring-style. */ options: ReadonlyArray; /** Trigger placeholder shown when no option is selected yet. */ placeholder?: string; /** Search-field placeholder shown inside the open popup. */ searchPlaceholder?: string; /** Forwarded onto the trigger button - useful for a stable form id. */ id?: string; /** Optional extra class names appended to the trigger. */ className?: string; } /** * Searchable dropdown for long lists (~200 countries, ~180 languages). * The merchant clicks the trigger to open a popup, types into the * search field to filter substring matches, and clicks an option to * commit. Click-outside / Escape closes the popup; the selected * option's label is mirrored back into the trigger. * * Drop-in replacement for native `` setQuery(event.target.value)} placeholder={searchPlaceholder} className="flex-1 bg-transparent text-sm outline-none placeholder:text-gray-400" />
{filteredOptions.length === 0 ? (
No matches.
) : ( filteredOptions.map(option => { const isSelected = option.value === value; return ( ); }) )}
)} ); }; export default SearchableSelect;