Skip to content

Commit

Permalink
*WIP* fix: #116 Add new story and flag outputMetricUnits to location-…
Browse files Browse the repository at this point in the history
…field
  • Loading branch information
amenk committed Feb 11, 2023
1 parent 6ca4257 commit c389bed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/location-field/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const LocationField = ({
onLocationSelected,
onTextInputClick = null,
operatorIconMap = {},
outputMetricUnits = false,
preferredLayers = [],
sessionOptionIcon = <Search size={13} />,
sessionSearches = [],
Expand Down Expand Up @@ -531,6 +532,7 @@ const LocationField = ({
onClick={locationSelected}
stop={stop}
stopOptionIcon={stopOptionIcon}
outputMetricUnits={outputMetricUnits}
/>
);
itemIndex++;
Expand Down
8 changes: 5 additions & 3 deletions packages/location-field/src/options.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import coreUtils from "@opentripplanner/core-utils";
import { humanizeDistanceStringImperial } from "@opentripplanner/humanize-distance";
import { humanizeDistanceString } from "@opentripplanner/humanize-distance";
import React, { ReactElement } from "react";
import { FormattedMessage } from "react-intl";
import { Bus } from "@styled-icons/fa-solid/Bus";
Expand Down Expand Up @@ -75,19 +75,21 @@ export function TransitStopOption({
isActive = false,
onClick,
stop,
stopOptionIcon
stopOptionIcon,
outputMetricUnits = false
}: {
isActive?: boolean;
onClick: () => void;
stop: Stop;
stopOptionIcon: React.ReactNode;
outputMetricUnits?: boolean;
}): React.ReactElement {
return (
<S.MenuItem onClick={onClick} active={isActive}>
<S.StopIconAndDistanceContainer>
{stopOptionIcon}
<S.StopDistance>
{humanizeDistanceStringImperial(stop.dist, true)}
{humanizeDistanceString(stop.dist, outputMetricUnits)}
</S.StopDistance>
</S.StopIconAndDistanceContainer>
<S.StopContentContainer>
Expand Down
15 changes: 15 additions & 0 deletions packages/location-field/src/stories/Mobile.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ export const WithNearbyStops = (): JSX.Element => (
/>
);

export const WithNearbyStopsAndMetricUnits = (): JSX.Element => (
<LocationField
currentPosition={currentPosition}
geocoderConfig={geocoderConfig}
getCurrentPosition={getCurrentPosition}
isStatic
layerColorMap={layerColorMap}
locationType="to"
nearbyStops={nearbyStops}
onLocationSelected={onLocationSelected}
stopsIndex={stopsIndex}
outputMetricUnits
/>
);

export const WithSessionSearches = (): JSX.Element => (
<LocationField
currentPosition={currentPosition}
Expand Down
5 changes: 5 additions & 0 deletions packages/location-field/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export interface LocationFieldProps {
* initial render.
*/
hideExistingValue?: boolean;

/**
* Whether to display metric units
*/
outputMetricUnits?: boolean;
/**
* Placeholder text to show in the input element. If the current position is
* set to have a true fetching property, then the text "Fetching location..."
Expand Down

0 comments on commit c389bed

Please sign in to comment.