@opentripplanner/trip-details 1.3.2 → 2.0.0

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,131 +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
- export default {
36
- title: "TripDetails",
37
- components: TripDetails
38
- };
39
-
40
- export const WalkOnlyItinerary = () => (
41
- <TripDetails itinerary={walkOnlyItinerary} longDateFormat={longDateFormat} />
42
- );
43
-
44
- export const BikeOnlyItinerary = () => (
45
- <TripDetails itinerary={bikeOnlyItinerary} longDateFormat={longDateFormat} />
46
- );
47
-
48
- export const WalkTransitWalkItinerary = () => (
49
- <TripDetails
50
- itinerary={walkTransitWalkItinerary}
51
- longDateFormat={longDateFormat}
52
- />
53
- );
54
-
55
- export const WalkTransitWalkItineraryAndCustomMessages = () => (
56
- <TripDetails
57
- itinerary={walkTransitWalkItinerary}
58
- longDateFormat={longDateFormat}
59
- messages={customMessages}
60
- />
61
- );
62
-
63
- export const StyledWalkTransitWalkItinerary = () => (
64
- <StyledTripDetails
65
- itinerary={walkTransitWalkItinerary}
66
- longDateFormat={longDateFormat}
67
- />
68
- );
69
-
70
- export const BikeTransitBikeItinerary = () => (
71
- <TripDetails
72
- itinerary={bikeTransitBikeItinerary}
73
- longDateFormat={longDateFormat}
74
- />
75
- );
76
-
77
- export const WalkInterlinedTransitItinerary = () => (
78
- <TripDetails
79
- itinerary={walkInterlinedTransitItinerary}
80
- longDateFormat={longDateFormat}
81
- />
82
- );
83
-
84
- export const WalkTransitTransferItinerary = () => (
85
- <TripDetails
86
- itinerary={walkTransitWalkTransitWalkItinerary}
87
- longDateFormat={longDateFormat}
88
- />
89
- );
90
-
91
- export const BikeRentalItinerary = () => (
92
- <TripDetails
93
- itinerary={bikeRentalItinerary}
94
- longDateFormat={longDateFormat}
95
- />
96
- );
97
-
98
- export const EScooterRentalItinerary = () => (
99
- <TripDetails
100
- itinerary={eScooterRentalItinerary}
101
- longDateFormat={longDateFormat}
102
- />
103
- );
104
-
105
- export const ParkAndRideItinerary = () => (
106
- <TripDetails
107
- itinerary={parkAndRideItinerary}
108
- longDateFormat={longDateFormat}
109
- />
110
- );
111
-
112
- export const BikeRentalTransitItinerary = () => (
113
- <TripDetails
114
- itinerary={bikeRentalTransitBikeRentalItinerary}
115
- longDateFormat={longDateFormat}
116
- />
117
- );
118
-
119
- export const EScooterRentalTransitItinerary = () => (
120
- <TripDetails
121
- itinerary={eScooterRentalTransiteScooterRentalItinerary}
122
- longDateFormat={longDateFormat}
123
- />
124
- );
125
-
126
- export const TncTransitItinerary = () => (
127
- <TripDetails
128
- itinerary={tncTransitTncItinerary}
129
- longDateFormat={longDateFormat}
130
- />
131
- );
package/src/index.js DELETED
@@ -1,184 +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, Heartbeat, MoneyBillAlt } from "styled-icons/fa-solid";
6
-
7
- import * as Styled from "./styled";
8
- import TripDetail from "./trip-detail";
9
-
10
- export default function TripDetails({
11
- className,
12
- itinerary,
13
- longDateFormat,
14
- messages,
15
- routingType,
16
- timeOptions
17
- }) {
18
- const date = moment(itinerary.startTime);
19
- messages = coreUtils.messages.mergeMessages(
20
- TripDetails.defaultProps.messages,
21
- messages
22
- );
23
-
24
- // process the transit fare
25
- const {
26
- centsToString,
27
- dollarsToString,
28
- maxTNCFare,
29
- minTNCFare,
30
- transitFare
31
- } = coreUtils.itinerary.calculateFares(itinerary);
32
- let companies;
33
- itinerary.legs.forEach(leg => {
34
- if (leg.tncData) {
35
- companies = leg.tncData.company;
36
- }
37
- });
38
- let fare;
39
- if (transitFare || minTNCFare) {
40
- fare = (
41
- <Styled.Fare>
42
- {transitFare && (
43
- <Styled.TransitFare>
44
- {messages.transitFare}: <b>{centsToString(transitFare)}</b>
45
- </Styled.TransitFare>
46
- )}
47
- {minTNCFare !== 0 && (
48
- <Styled.TNCFare>
49
- <br />
50
- <Styled.TNCFareCompanies>
51
- {companies.toLowerCase()}
52
- </Styled.TNCFareCompanies>{" "}
53
- {messages.fare}:{" "}
54
- <b>
55
- {dollarsToString(minTNCFare)} - {dollarsToString(maxTNCFare)}
56
- </b>
57
- </Styled.TNCFare>
58
- )}
59
- </Styled.Fare>
60
- );
61
- }
62
-
63
- // Compute calories burned.
64
- const {
65
- bikeDuration,
66
- caloriesBurned,
67
- walkDuration
68
- } = coreUtils.itinerary.calculatePhysicalActivity(itinerary);
69
-
70
- return (
71
- <Styled.TripDetails className={className}>
72
- <Styled.TripDetailsHeader>{messages.title}</Styled.TripDetailsHeader>
73
- <Styled.TripDetailsBody>
74
- <TripDetail
75
- description={messages.departDescription}
76
- icon={<CalendarAlt size={17} />}
77
- summary={
78
- <Styled.Timing>
79
- <span>
80
- {messages.depart} <b>{date.format(longDateFormat)}</b>
81
- </span>
82
- {routingType === "ITINERARY" && (
83
- <span>
84
- {" "}
85
- {messages.at}{" "}
86
- <b>
87
- {coreUtils.time.formatTime(
88
- itinerary.startTime,
89
- timeOptions
90
- )}
91
- </b>
92
- </span>
93
- )}
94
- </Styled.Timing>
95
- }
96
- />
97
- {fare && (
98
- <TripDetail
99
- description={messages.transitFareDescription}
100
- icon={<MoneyBillAlt size={17} />}
101
- summary={fare}
102
- />
103
- )}
104
- {caloriesBurned > 0 && (
105
- <TripDetail
106
- icon={<Heartbeat size={17} />}
107
- summary={
108
- <Styled.CaloriesSummary>
109
- {messages.caloriesBurned}: <b>{Math.round(caloriesBurned)}</b>
110
- </Styled.CaloriesSummary>
111
- }
112
- description={
113
- <Styled.CaloriesDescription>
114
- Calories burned is based on{" "}
115
- <b>{Math.round(walkDuration / 60)} minute(s)</b> spent walking
116
- and <b>{Math.round(bikeDuration / 60)} minute(s)</b> spent
117
- biking during this trip. Adapted from{" "}
118
- <a
119
- href="https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4"
120
- rel="noopener noreferrer"
121
- target="_blank"
122
- >
123
- Dietary Guidelines for Americans 2005, page 16, Table 4
124
- </a>
125
- .
126
- </Styled.CaloriesDescription>
127
- }
128
- />
129
- )}
130
- </Styled.TripDetailsBody>
131
- </Styled.TripDetails>
132
- );
133
- }
134
-
135
- TripDetails.propTypes = {
136
- /** Used for additional styling with styled components for example. */
137
- className: PropTypes.string,
138
- /** Itinerary that the user has selected to view, contains multiple legs */
139
- itinerary: coreUtils.types.itineraryType.isRequired,
140
- /** the desired format to use for a long date */
141
- longDateFormat: PropTypes.string,
142
- /**
143
- * messages to use for l10n/i8n
144
- *
145
- * Note: messages with default null values included here for visibility.
146
- * Overriding with a truthy string value will cause the expandable help
147
- * message to appear in trip details.
148
- */
149
- messages: PropTypes.shape({
150
- at: PropTypes.string,
151
- caloriesBurned: PropTypes.string,
152
- // FIXME: Add templated string description.
153
- caloriesBurnedDescription: PropTypes.string,
154
- depart: PropTypes.string,
155
- departDescription: PropTypes.string,
156
- title: PropTypes.string,
157
- fare: PropTypes.string,
158
- transitFare: PropTypes.string,
159
- transitFareDescription: PropTypes.string
160
- }),
161
- /** whether the routing type is an itinerary or a profile result */
162
- routingType: PropTypes.string,
163
- /** Contains the preferred format string for time display and a timezone offset */
164
- timeOptions: coreUtils.types.timeOptionsType
165
- };
166
-
167
- TripDetails.defaultProps = {
168
- className: null,
169
- longDateFormat: null,
170
- messages: {
171
- at: "at",
172
- caloriesBurned: "Calories Burned",
173
- // FIXME: Add templated string description.
174
- caloriesBurnedDescription: null,
175
- depart: "Depart",
176
- departDescription: null,
177
- title: "Trip Details",
178
- fare: "Fare",
179
- transitFare: "Transit Fare",
180
- transitFareDescription: null
181
- },
182
- routingType: "ITINERARY",
183
- timeOptions: null
184
- };
@@ -1,70 +0,0 @@
1
- import PropTypes from "prop-types";
2
- import React, { Component } from "react";
3
- import { QuestionCircle, TimesCircle } from "styled-icons/fa-solid";
4
- import { VelocityTransitionGroup } from "velocity-react";
5
-
6
- import * as Styled from "./styled";
7
-
8
- export default class TripDetail extends Component {
9
- constructor(props) {
10
- super(props);
11
- this.state = {
12
- expanded: false
13
- };
14
- }
15
-
16
- toggle = () => {
17
- const { expanded } = this.state;
18
- if (expanded) this.onHideClick();
19
- else this.onExpandClick();
20
- };
21
-
22
- onExpandClick = () => {
23
- this.setState({ expanded: true });
24
- };
25
-
26
- onHideClick = () => {
27
- this.setState({ expanded: false });
28
- };
29
-
30
- render() {
31
- const { icon, summary, description } = this.props;
32
- const { expanded } = this.state;
33
- return (
34
- <Styled.TripDetail>
35
- <Styled.TripDetailIcon>{icon}</Styled.TripDetailIcon>
36
- <Styled.TripDetailSummary>
37
- {summary}
38
- {description && (
39
- <Styled.ExpandButton onClick={this.toggle}>
40
- <QuestionCircle size="0.92em" />
41
- </Styled.ExpandButton>
42
- )}
43
- <VelocityTransitionGroup
44
- enter={{ animation: "slideDown" }}
45
- leave={{ animation: "slideUp" }}
46
- >
47
- {expanded && (
48
- <Styled.TripDetailDescription>
49
- <Styled.HideButton onClick={this.onHideClick}>
50
- <TimesCircle size="0.92em" />
51
- </Styled.HideButton>
52
- {description}
53
- </Styled.TripDetailDescription>
54
- )}
55
- </VelocityTransitionGroup>
56
- </Styled.TripDetailSummary>
57
- </Styled.TripDetail>
58
- );
59
- }
60
- }
61
-
62
- TripDetail.propTypes = {
63
- icon: PropTypes.node.isRequired,
64
- summary: PropTypes.node.isRequired,
65
- description: PropTypes.node
66
- };
67
-
68
- TripDetail.defaultProps = {
69
- description: undefined
70
- };