Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #116 Add outputMetricUnits to config types and use in itinerary-… #538

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export default function AccessLegDescription({
id="otpUi.AccessLegBody.summaryAndDistance"
values={{
// TODO: Implement metric vs imperial (up until now it's just imperial).
distance: humanizeDistanceString(leg.distance, false, intl),
distance: humanizeDistanceString(
leg.distance,
config.outputMetricUnits,
intl
),
mode: modeContent,
place: placeContent
}}
Expand Down
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
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export type Config = {
longDateFormat?: string;
};
homeTimezone: string;
outputMetricUnits: boolean;
modes: ConfiguredModes;
// TODO: add full typing
map?: {
Expand Down