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

feat(location-field): make location group order configurable #771

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 22 additions & 10 deletions packages/location-field/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const LocationField = ({
onTextInputClick = null,
operatorIconMap = {},
preferredLayers = [],
renderOtherFirst = false,
sessionOptionIcon = <Search size={ICON_SIZE} />,
sessionSearches = [],
showClearButton = true,
Expand Down Expand Up @@ -644,8 +645,25 @@ const LocationField = ({
const transitFeaturesPresent =
stopFeatures.length > 0 || stationFeatures.length > 0;

const OtherFeaturesHeader = () => (
<S.MenuGroupHeader as={headingType} bgColor="#333" key="other-header">
<FormattedMessage
description="Text for header above the 'other' category of geocoder results"
id="otpUi.LocationField.other"
/>
</S.MenuGroupHeader>
);

const otherFeaturesElements = otherFeatures.map(feature =>
renderFeature(itemIndex++, feature)
);

// Iterate through the geocoder results
menuItems = menuItems.concat(
renderOtherFirst &&
transitFeaturesPresent &&
otherFeatures.length > 0 && <OtherFeaturesHeader />,
renderOtherFirst && otherFeaturesElements,
stationFeatures.length > 0 && (
<S.MenuGroupHeader
as={headingType}
Expand Down Expand Up @@ -673,16 +691,10 @@ const LocationField = ({
</S.MenuGroupHeader>
),
stopFeatures.map(feature => renderFeature(itemIndex++, feature)),

transitFeaturesPresent && otherFeatures.length > 0 && (
<S.MenuGroupHeader as={headingType} bgColor="#333" key="other-header">
<FormattedMessage
description="Text for header above the 'other'"
id="otpUi.LocationField.other"
/>
</S.MenuGroupHeader>
),
otherFeatures.map(feature => renderFeature(itemIndex++, feature))
!renderOtherFirst &&
transitFeaturesPresent &&
otherFeatures.length > 0 && <OtherFeaturesHeader />,
!renderOtherFirst && otherFeaturesElements
);
}

Expand Down
34 changes: 33 additions & 1 deletion packages/location-field/src/stories/Desktop.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { ComponentMeta } from "@storybook/react";

import { Ship } from "@styled-icons/fa-solid/Ship";
Expand Down Expand Up @@ -251,3 +251,35 @@ export const WithUserSettings = (): JSX.Element => (
userLocationsAndRecentPlaces={userLocationsAndRecentPlaces}
/>
);

export const WithOtherFirst = (): JSX.Element => {
const [otherControl, setOtherControl] = useState(false);
return (
<>
<label htmlFor="other-input">
renderOtherFirst?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make Storybook create the controls using argTypes instead? (Storybook will add that to its "Controls" tab - I should have mentioned that in my previous review but somehow thought you knew) Do that for this story only. Refer to e.g.

for an example.

<input
id="other-input"
type="checkbox"
checked={otherControl}
onChange={() => setOtherControl(!otherControl)}
/>
</label>
<LocationField
currentPosition={currentPosition}
geocoderConfig={geocoderConfig}
getCurrentPosition={getCurrentPosition}
preferredLayers={["example_layer"]}
initialSearchResults={mockedGeocoderResponse.features}
inputPlaceholder="Select from location"
layerColorMap={layerColorMap}
locationType="from"
onLocationSelected={onLocationSelected}
renderOtherFirst={otherControl}
sortByDistance
style={{ fontFamily: "sans-serif" }}
/>
</>
);
};
WithOtherFirst.parameters = a11yOverrideParameters;
Loading
Loading