import flatten from "flat"; import LocationIcon from "@opentripplanner/location-icon"; import { FormattedMessage } from "react-intl"; import React, { ReactElement } from "react"; import * as S from "./styled"; // eslint-disable-next-line prettier/prettier import type { FromToPickerProps, FromToLocation } from "./types"; // Load the default messages. import defaultEnglishMessages from "../i18n/en-US.yml"; export { FromToLocation } const iconSize = "0.9em"; // HACK: We should flatten the messages loaded above because // the YAML loaders behave differently between webpack and our version of jest: // - the yaml loader for webpack returns a nested object, // - the yaml loader for jest returns messages with flattened ids. const defaultMessages: Record = flatten(defaultEnglishMessages); const FromToLocationPicker = ({ label = null, location = null, onFromClick = null, onToClick = null, setLocation = null, showIcons = true }: FromToPickerProps): ReactElement => { const handleFromClick = () => { if (onFromClick) { onFromClick(); return; } setLocation({ location, locationType: "from", reverseGeocode: false }); }; const handleToClick = () => { if (onToClick) { onToClick(); return; } setLocation({ location, locationType: "to", reverseGeocode: false }); }; const labelIfAny = label === true ? ( ) : label return ( <> {labelIfAny} {showIcons && } {showIcons && } ); }; export default FromToLocationPicker; // Rename styled components for export. export { S as Styled };