@opentripplanner/trip-details 1.5.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,147 +0,0 @@
1
- import React from "react";
2
- import styled from "styled-components";
3
-
4
- import TripDetails from ".";
5
- import * as TripDetailsClasses from "./styled";
6
-
7
- // import mock itinaries. These are all trip plan outputs from OTP.
8
- const bikeOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-only.json");
9
- const bikeRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-rental.json");
10
- const bikeRentalTransitBikeRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-rental-transit-bike-rental.json");
11
- const bikeTransitBikeItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-transit-bike.json");
12
- const eScooterRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/e-scooter-rental.json");
13
- const eScooterRentalTransiteScooterRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/e-scooter-transit-e-scooter.json");
14
- const parkAndRideItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/park-and-ride.json");
15
- const tncTransitTncItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/tnc-transit-tnc.json");
16
- const walkInterlinedTransitItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-interlined-transit-walk.json");
17
- const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-only.json");
18
- const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
19
- const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");
20
-
21
- const StyledTripDetails = styled(TripDetails)`
22
- ${TripDetailsClasses.TripDetailsHeader} {
23
- background-color: pink;
24
- }
25
- `;
26
-
27
- const customMessages = {
28
- title: "Details about this Trip",
29
- transitFare: "Transit Fare",
30
- transitFareDescription:
31
- "Note: actual fare may be lower if you have a transit pass or something like that."
32
- };
33
- const longDateFormat = "MMMM D, YYYY";
34
-
35
- const customKeyMap = {
36
- regular: "Transit Fare",
37
- student: "Student Fare",
38
- senior: "Senior Fare",
39
- tram: "Tram Fare",
40
- special: "Special Fare",
41
- youth: "Youth Fare",
42
- electronicRegular: "Orca Fare",
43
- electronicYouth: "Orca Youth Fare",
44
- electronicSpecial: "Orca Special Fare",
45
- electronicSenior: "Orca Senior Fare"
46
- };
47
-
48
- export default {
49
- title: "TripDetails",
50
- components: TripDetails
51
- };
52
-
53
- export const WalkOnlyItinerary = () => (
54
- <TripDetails itinerary={walkOnlyItinerary} longDateFormat={longDateFormat} />
55
- );
56
-
57
- export const BikeOnlyItinerary = () => (
58
- <TripDetails itinerary={bikeOnlyItinerary} longDateFormat={longDateFormat} />
59
- );
60
-
61
- export const WalkTransitWalkItinerary = () => (
62
- <TripDetails
63
- itinerary={walkTransitWalkItinerary}
64
- longDateFormat={longDateFormat}
65
- />
66
- );
67
-
68
- export const WalkTransitWalkItineraryAndCustomMessages = () => (
69
- <TripDetails
70
- itinerary={walkTransitWalkItinerary}
71
- longDateFormat={longDateFormat}
72
- messages={customMessages}
73
- />
74
- );
75
-
76
- export const StyledWalkTransitWalkItinerary = () => (
77
- <StyledTripDetails
78
- itinerary={walkTransitWalkItinerary}
79
- longDateFormat={longDateFormat}
80
- />
81
- );
82
-
83
- export const BikeTransitBikeItinerary = () => (
84
- <TripDetails
85
- itinerary={bikeTransitBikeItinerary}
86
- longDateFormat={longDateFormat}
87
- />
88
- );
89
-
90
- export const WalkInterlinedTransitItinerary = () => (
91
- <TripDetails
92
- itinerary={walkInterlinedTransitItinerary}
93
- longDateFormat={longDateFormat}
94
- defaultFare="electronicRegular"
95
- fareKeyNameMap={customKeyMap}
96
- />
97
- );
98
-
99
- export const WalkTransitTransferItinerary = () => (
100
- <TripDetails
101
- itinerary={walkTransitWalkTransitWalkItinerary}
102
- longDateFormat={longDateFormat}
103
- />
104
- );
105
-
106
- export const BikeRentalItinerary = () => (
107
- <TripDetails
108
- itinerary={bikeRentalItinerary}
109
- longDateFormat={longDateFormat}
110
- />
111
- );
112
-
113
- export const EScooterRentalItinerary = () => (
114
- <TripDetails
115
- itinerary={eScooterRentalItinerary}
116
- longDateFormat={longDateFormat}
117
- />
118
- );
119
-
120
- export const ParkAndRideItinerary = () => (
121
- <TripDetails
122
- itinerary={parkAndRideItinerary}
123
- longDateFormat={longDateFormat}
124
- />
125
- );
126
-
127
- export const BikeRentalTransitItinerary = () => (
128
- <TripDetails
129
- itinerary={bikeRentalTransitBikeRentalItinerary}
130
- longDateFormat={longDateFormat}
131
- />
132
- );
133
-
134
- export const EScooterRentalTransitItinerary = () => (
135
- <TripDetails
136
- itinerary={eScooterRentalTransiteScooterRentalItinerary}
137
- longDateFormat={longDateFormat}
138
- />
139
- );
140
-
141
- export const TncTransitItinerary = () => (
142
- <TripDetails
143
- itinerary={tncTransitTncItinerary}
144
- longDateFormat={longDateFormat}
145
- fareKeyNameMap={customKeyMap}
146
- />
147
- );
package/src/index.js DELETED
@@ -1,262 +0,0 @@
1
- import coreUtils from "@opentripplanner/core-utils";
2
- import moment from "moment";
3
- import PropTypes from "prop-types";
4
- import React from "react";
5
- import { CalendarAlt } from "@styled-icons/fa-solid/CalendarAlt";
6
- import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
7
- import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
8
-
9
- import * as S from "./styled";
10
- import TripDetail from "./trip-detail";
11
-
12
- const TransitFare = ({
13
- fareKey,
14
- fareNameFallback,
15
- fareKeyNameMap,
16
- transitFares
17
- }) => {
18
- const currentFare = transitFares[fareKey];
19
-
20
- return (
21
- <span>
22
- {fareKeyNameMap[fareKey] || fareNameFallback || fareKey}:{" "}
23
- <b>{currentFare.centsToString(currentFare.transitFare)}</b>
24
- </span>
25
- );
26
- };
27
- TransitFare.propTypes = {
28
- fareKey: PropTypes.string.isRequired,
29
- fareNameFallback: PropTypes.string,
30
- fareKeyNameMap: PropTypes.shape({
31
- [PropTypes.string]: PropTypes.string
32
- }).isRequired,
33
- transitFares: PropTypes.shape({
34
- centsToString: PropTypes.func,
35
- transitFare: PropTypes.number
36
- }).isRequired
37
- };
38
- TransitFare.defaultProps = {
39
- fareNameFallback: undefined
40
- };
41
-
42
- function TripDetails({
43
- className,
44
- defaultFareKey,
45
- itinerary,
46
- fareKeyNameMap,
47
- longDateFormat,
48
- messages,
49
- routingType,
50
- timeOptions
51
- }) {
52
- const date = moment(itinerary.startTime);
53
- messages = coreUtils.messages.mergeMessages(
54
- TripDetails.defaultProps.messages,
55
- messages
56
- );
57
-
58
- // process the transit fare
59
- const {
60
- maxTNCFare,
61
- minTNCFare,
62
- transitFares
63
- } = coreUtils.itinerary.calculateFares(itinerary, true);
64
-
65
- let defaultFare = defaultFareKey;
66
- if (!transitFares[defaultFareKey]) {
67
- defaultFare = "regular";
68
- }
69
-
70
- let companies;
71
- itinerary.legs.forEach(leg => {
72
- if (leg.tncData) {
73
- companies = leg.tncData.company;
74
- }
75
- });
76
- let fare;
77
-
78
- const fareKeys = transitFares && Object.keys(transitFares).sort();
79
-
80
- if (transitFares && fareKeys.length > 0) {
81
- const { dollarsToString } = transitFares[defaultFare];
82
- // Depending on if there are additional fares to display either render a <span> or a <details>
83
- const TransitFareWrapper =
84
- transitFares && fareKeys.length > 1 ? S.TransitFare : S.TransitFareSingle;
85
-
86
- fare = (
87
- <S.Fare>
88
- <TransitFareWrapper>
89
- <summary style={{ display: fareKeys.length > 1 ? "list-item" : "" }}>
90
- <TransitFare
91
- fareNameFallback={messages.transitFare}
92
- fareKey={defaultFare}
93
- fareKeyNameMap={fareKeyNameMap}
94
- transitFares={transitFares}
95
- />
96
- </summary>
97
- {fareKeys.map(fareKey => {
98
- // Don't show the default fare twice!
99
- if (fareKey === defaultFare) {
100
- return null;
101
- }
102
- return (
103
- <TransitFare
104
- fareKey={fareKey}
105
- key={fareKey}
106
- fareKeyNameMap={fareKeyNameMap}
107
- transitFares={transitFares}
108
- />
109
- );
110
- })}
111
- </TransitFareWrapper>
112
- {minTNCFare !== 0 && (
113
- <S.TNCFare>
114
- <br />
115
- <S.TNCFareCompanies>
116
- {companies.toLowerCase()}
117
- </S.TNCFareCompanies>{" "}
118
- {messages.fare}:{" "}
119
- <b>
120
- {dollarsToString(minTNCFare)} - {dollarsToString(maxTNCFare)}
121
- </b>
122
- </S.TNCFare>
123
- )}
124
- </S.Fare>
125
- );
126
- }
127
-
128
- // Compute calories burned.
129
- const {
130
- bikeDuration,
131
- caloriesBurned,
132
- walkDuration
133
- } = coreUtils.itinerary.calculatePhysicalActivity(itinerary);
134
-
135
- return (
136
- <S.TripDetails className={className}>
137
- <S.TripDetailsHeader>{messages.title}</S.TripDetailsHeader>
138
- <S.TripDetailsBody>
139
- <TripDetail
140
- description={messages.departDescription}
141
- icon={<CalendarAlt size={17} />}
142
- summary={
143
- <S.Timing>
144
- <span>
145
- {messages.depart} <b>{date.format(longDateFormat)}</b>
146
- </span>
147
- {routingType === "ITINERARY" && (
148
- <span>
149
- {" "}
150
- {messages.at}{" "}
151
- <b>
152
- {coreUtils.time.formatTime(
153
- itinerary.startTime,
154
- timeOptions
155
- )}
156
- </b>
157
- </span>
158
- )}
159
- </S.Timing>
160
- }
161
- />
162
- {fare && (
163
- <TripDetail
164
- description={messages.transitFareDescription}
165
- icon={<MoneyBillAlt size={17} />}
166
- summary={fare}
167
- />
168
- )}
169
- {caloriesBurned > 0 && (
170
- <TripDetail
171
- icon={<Heartbeat size={17} />}
172
- summary={
173
- <S.CaloriesSummary>
174
- {messages.caloriesBurned}: <b>{Math.round(caloriesBurned)}</b>
175
- </S.CaloriesSummary>
176
- }
177
- description={
178
- <S.CaloriesDescription>
179
- Calories burned is based on{" "}
180
- <b>{Math.round(walkDuration / 60)} minute(s)</b> spent walking
181
- and <b>{Math.round(bikeDuration / 60)} minute(s)</b> spent
182
- biking during this trip. Adapted from{" "}
183
- <a
184
- href="https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4"
185
- rel="noopener noreferrer"
186
- target="_blank"
187
- >
188
- Dietary Guidelines for Americans 2005, page 16, Table 4
189
- </a>
190
- .
191
- </S.CaloriesDescription>
192
- }
193
- />
194
- )}
195
- </S.TripDetailsBody>
196
- </S.TripDetails>
197
- );
198
- }
199
-
200
- TripDetails.propTypes = {
201
- /** Used for additional styling with styled components for example. */
202
- className: PropTypes.string,
203
- /** Determines which transit fare should be displayed by default, should there be multiple transit fare types */
204
- defaultFareKey: PropTypes.string,
205
- /** Itinerary that the user has selected to view, contains multiple legs */
206
- itinerary: coreUtils.types.itineraryType.isRequired,
207
- /** Mapping between fare keys and human-readable names for them */
208
- fareKeyNameMap: PropTypes.shape({
209
- [PropTypes.string]: PropTypes.string
210
- }),
211
- /** the desired format to use for a long date */
212
- longDateFormat: PropTypes.string,
213
- /**
214
- * messages to use for l10n/i8n
215
- *
216
- * Note: messages with default null values included here for visibility.
217
- * Overriding with a truthy string value will cause the expandable help
218
- * message to appear in trip details.
219
- */
220
- messages: PropTypes.shape({
221
- at: PropTypes.string,
222
- caloriesBurned: PropTypes.string,
223
- // FIXME: Add templated string description.
224
- caloriesBurnedDescription: PropTypes.string,
225
- depart: PropTypes.string,
226
- departDescription: PropTypes.string,
227
- title: PropTypes.string,
228
- fare: PropTypes.string,
229
- transitFare: PropTypes.string,
230
- transitFareDescription: PropTypes.string
231
- }),
232
- /** whether the routing type is an itinerary or a profile result */
233
- routingType: PropTypes.string,
234
- /** Contains the preferred format string for time display and a timezone offset */
235
- timeOptions: coreUtils.types.timeOptionsType
236
- };
237
-
238
- TripDetails.defaultProps = {
239
- className: null,
240
- defaultFareKey: "regular",
241
- fareKeyNameMap: {},
242
- longDateFormat: null,
243
- messages: {
244
- at: "at",
245
- caloriesBurned: "Calories Burned",
246
- // FIXME: Add templated string description.
247
- caloriesBurnedDescription: null,
248
- depart: "Depart",
249
- departDescription: null,
250
- title: "Trip Details",
251
- fare: "Fare",
252
- transitFare: "Transit Fare",
253
- transitFareDescription: null
254
- },
255
- routingType: "ITINERARY",
256
- timeOptions: null
257
- };
258
-
259
- export default TripDetails;
260
-
261
- // Rename styled components for export
262
- export { S as Styled };