import { MapPin, X } from 'lucide-react'; import type React from 'react'; import { useTranslation } from '../../i18n'; import { MAP_CONTROL_SHADOW } from '../Map/mapControlShadow'; // Over a map the field and its list take the map controls' frosted glass instead of a form box. const FLOATING_GLASS: React.CSSProperties = { background: 'var(--sidebar-bg)', backdropFilter: 'blur(20px) saturate(180%)', WebkitBackdropFilter: 'blur(20px) saturate(180%)', boxShadow: MAP_CONTROL_SHADOW, border: 'none', }; // The markup the planner's search fields share: the boxed input with its icon and // clear button (AirportSelect, LocationSelect), the floating list (all three) and // a map search answer as a row (LocationSelect, AddressInput). interface SuggestionInputBoxProps { icon: React.ReactNode; query: string; placeholder: string; onType: (text: string) => void; onOpen: () => void; onKeyDown: (e: React.KeyboardEvent) => void; /** Shown as the clear button while a value is picked. */ onClear?: () => void; /** Floats over a map: a frosted pill like the map controls. */ floating?: boolean; /** Combobox wiring for a field that announces its list (role, aria-expanded, ...). */ inputAria?: React.AriaAttributes & { role?: React.AriaRole }; } export function SuggestionInputBox({ icon, query, placeholder, onType, onOpen, onKeyDown, onClear, inputAria, floating = false, }: SuggestionInputBoxProps) { return (
{icon} onType(e.target.value)} // Opens its list on focus, so a dialog must not focus it by itself (#1302). data-no-autofocus onFocus={onOpen} onKeyDown={onKeyDown} className="bg-transparent text-content" style={{ flex: 1, minWidth: 0, border: 'none', outline: 'none', fontSize: 'calc(13px * var(--fs-scale-body, 1))', }} /> {onClear && ( )}
); } interface SuggestionListProps { /** Shows the loading line while there are no rows yet. */ loading: boolean; rowCount: number; /** A line above the rows, such as "nothing found"; keeps the list open without rows. */ status?: React.ReactNode; /** Wraps the rows in a listbox when the field is a combobox. */ listbox?: { id: string; label: string }; /** Floats over a map: the same frosted glass as the field above it. */ floating?: boolean; children: React.ReactNode; } /** The floating list under the field. Rendered only while it is loading, has rows or a status; the caller checks `open`. */ export function SuggestionList({ loading, rowCount, status, listbox, floating = false, children, }: SuggestionListProps) { const { t } = useTranslation(); if (!loading && rowCount === 0 && !status) return null; return (
{loading && rowCount === 0 && (
{t('common.loading')}
)} {status} {listbox ? (
{children}
) : ( children )}
); } interface SuggestionRowProps { active: boolean; onPick: () => void; onHover: () => void; /** How the row lines up its icon and text. */ align: 'center' | 'flex-start'; /** Set inside a listbox: the row becomes an option the input can point at. */ optionId?: string; children: React.ReactNode; } export function SuggestionRow({ active, onPick, onHover, align, optionId, children }: SuggestionRowProps) { return ( ); } interface PlaceSuggestionProps { name?: string | null; address?: string | null; } /** A place as a row's content: a pin, its name, and its address when that says more. */ export function PlaceSuggestion({ name, address }: PlaceSuggestionProps) { return ( <>
{name || address}
{address && name && name !== address && (
{address}
)}
); }