@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.
@@ -8,11 +8,11 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
8
8
 
9
9
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
10
 
11
- import PropTypes from "prop-types";
12
11
  import React, { Component } from "react";
13
- import { QuestionCircle, TimesCircle } from "styled-icons/fa-solid";
12
+ import { QuestionCircle } from "@styled-icons/fa-solid/QuestionCircle";
13
+ import { TimesCircle } from "@styled-icons/fa-solid/TimesCircle";
14
14
  import { VelocityTransitionGroup } from "velocity-react";
15
- import * as Styled from "./styled";
15
+ import * as S from "./styled";
16
16
 
17
17
  var TripDetail = /*#__PURE__*/function (_Component) {
18
18
  _inherits(TripDetail, _Component);
@@ -57,22 +57,22 @@ var TripDetail = /*#__PURE__*/function (_Component) {
57
57
  summary = _this$props.summary,
58
58
  description = _this$props.description;
59
59
  var expanded = this.state.expanded;
60
- return /*#__PURE__*/React.createElement(Styled.TripDetail, null, /*#__PURE__*/React.createElement(Styled.TripDetailIcon, null, icon), /*#__PURE__*/React.createElement(Styled.TripDetailSummary, null, summary, description && /*#__PURE__*/React.createElement(Styled.ExpandButton, {
60
+ return /*#__PURE__*/React.createElement(S.TripDetail, null, /*#__PURE__*/React.createElement(S.TripDetailIcon, null, icon), /*#__PURE__*/React.createElement(S.TripDetailSummary, null, summary, description && /*#__PURE__*/React.createElement(S.ExpandButton, {
61
61
  onClick: this.toggle
62
62
  }, /*#__PURE__*/React.createElement(QuestionCircle, {
63
63
  size: "0.92em"
64
- })), /*#__PURE__*/React.createElement(VelocityTransitionGroup, {
64
+ }))), /*#__PURE__*/React.createElement(VelocityTransitionGroup, {
65
65
  enter: {
66
66
  animation: "slideDown"
67
67
  },
68
68
  leave: {
69
69
  animation: "slideUp"
70
70
  }
71
- }, expanded && /*#__PURE__*/React.createElement(Styled.TripDetailDescription, null, /*#__PURE__*/React.createElement(Styled.HideButton, {
71
+ }, expanded && /*#__PURE__*/React.createElement(S.TripDetailDescription, null, /*#__PURE__*/React.createElement(S.HideButton, {
72
72
  onClick: this.onHideClick
73
73
  }, /*#__PURE__*/React.createElement(TimesCircle, {
74
74
  size: "0.92em"
75
- })), description))));
75
+ })), description)));
76
76
  }
77
77
  }]);
78
78
 
@@ -80,12 +80,4 @@ var TripDetail = /*#__PURE__*/function (_Component) {
80
80
  }(Component);
81
81
 
82
82
  export { TripDetail as default };
83
- TripDetail.propTypes = {
84
- icon: PropTypes.node.isRequired,
85
- summary: PropTypes.node.isRequired,
86
- description: PropTypes.node
87
- };
88
- TripDetail.defaultProps = {
89
- description: undefined
90
- };
91
83
  //# sourceMappingURL=trip-detail.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/trip-detail.js"],"names":["PropTypes","React","Component","QuestionCircle","TimesCircle","VelocityTransitionGroup","Styled","TripDetail","props","toggle","expanded","state","onHideClick","onExpandClick","setState","icon","summary","description","animation","propTypes","node","isRequired","defaultProps","undefined"],"mappings":";;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,YAAtB;AACA,OAAOC,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,SAASC,cAAT,EAAyBC,WAAzB,QAA4C,uBAA5C;AACA,SAASC,uBAAT,QAAwC,gBAAxC;AAEA,OAAO,KAAKC,MAAZ,MAAwB,UAAxB;;IAEqBC,U;;;;;AACnB,sBAAYC,KAAZ,EAAmB;AAAA;;AAAA;;AACjB,8BAAMA,KAAN;;AADiB,UAOnBC,MAPmB,GAOV,YAAM;AACb,UAAQC,QAAR,GAAqB,MAAKC,KAA1B,CAAQD,QAAR;AACA,UAAIA,QAAJ,EAAc,MAAKE,WAAL,GAAd,KACK,MAAKC,aAAL;AACN,KAXkB;;AAAA,UAanBA,aAbmB,GAaH,YAAM;AACpB,YAAKC,QAAL,CAAc;AAAEJ,QAAAA,QAAQ,EAAE;AAAZ,OAAd;AACD,KAfkB;;AAAA,UAiBnBE,WAjBmB,GAiBL,YAAM;AAClB,YAAKE,QAAL,CAAc;AAAEJ,QAAAA,QAAQ,EAAE;AAAZ,OAAd;AACD,KAnBkB;;AAEjB,UAAKC,KAAL,GAAa;AACXD,MAAAA,QAAQ,EAAE;AADC,KAAb;AAFiB;AAKlB;;;;WAgBD,kBAAS;AACP,wBAAuC,KAAKF,KAA5C;AAAA,UAAQO,IAAR,eAAQA,IAAR;AAAA,UAAcC,OAAd,eAAcA,OAAd;AAAA,UAAuBC,WAAvB,eAAuBA,WAAvB;AACA,UAAQP,QAAR,GAAqB,KAAKC,KAA1B,CAAQD,QAAR;AACA,0BACE,oBAAC,MAAD,CAAQ,UAAR,qBACE,oBAAC,MAAD,CAAQ,cAAR,QAAwBK,IAAxB,CADF,eAEE,oBAAC,MAAD,CAAQ,iBAAR,QACGC,OADH,EAEGC,WAAW,iBACV,oBAAC,MAAD,CAAQ,YAAR;AAAqB,QAAA,OAAO,EAAE,KAAKR;AAAnC,sBACE,oBAAC,cAAD;AAAgB,QAAA,IAAI,EAAC;AAArB,QADF,CAHJ,eAOE,oBAAC,uBAAD;AACE,QAAA,KAAK,EAAE;AAAES,UAAAA,SAAS,EAAE;AAAb,SADT;AAEE,QAAA,KAAK,EAAE;AAAEA,UAAAA,SAAS,EAAE;AAAb;AAFT,SAIGR,QAAQ,iBACP,oBAAC,MAAD,CAAQ,qBAAR,qBACE,oBAAC,MAAD,CAAQ,UAAR;AAAmB,QAAA,OAAO,EAAE,KAAKE;AAAjC,sBACE,oBAAC,WAAD;AAAa,QAAA,IAAI,EAAC;AAAlB,QADF,CADF,EAIGK,WAJH,CALJ,CAPF,CAFF,CADF;AA0BD;;;;EAnDqCf,S;;SAAnBK,U;AAsDrBA,UAAU,CAACY,SAAX,GAAuB;AACrBJ,EAAAA,IAAI,EAAEf,SAAS,CAACoB,IAAV,CAAeC,UADA;AAErBL,EAAAA,OAAO,EAAEhB,SAAS,CAACoB,IAAV,CAAeC,UAFH;AAGrBJ,EAAAA,WAAW,EAAEjB,SAAS,CAACoB;AAHF,CAAvB;AAMAb,UAAU,CAACe,YAAX,GAA0B;AACxBL,EAAAA,WAAW,EAAEM;AADW,CAA1B","sourcesContent":["import PropTypes from \"prop-types\";\nimport React, { Component } from \"react\";\nimport { QuestionCircle, TimesCircle } from \"styled-icons/fa-solid\";\nimport { VelocityTransitionGroup } from \"velocity-react\";\n\nimport * as Styled from \"./styled\";\n\nexport default class TripDetail extends Component {\n constructor(props) {\n super(props);\n this.state = {\n expanded: false\n };\n }\n\n toggle = () => {\n const { expanded } = this.state;\n if (expanded) this.onHideClick();\n else this.onExpandClick();\n };\n\n onExpandClick = () => {\n this.setState({ expanded: true });\n };\n\n onHideClick = () => {\n this.setState({ expanded: false });\n };\n\n render() {\n const { icon, summary, description } = this.props;\n const { expanded } = this.state;\n return (\n <Styled.TripDetail>\n <Styled.TripDetailIcon>{icon}</Styled.TripDetailIcon>\n <Styled.TripDetailSummary>\n {summary}\n {description && (\n <Styled.ExpandButton onClick={this.toggle}>\n <QuestionCircle size=\"0.92em\" />\n </Styled.ExpandButton>\n )}\n <VelocityTransitionGroup\n enter={{ animation: \"slideDown\" }}\n leave={{ animation: \"slideUp\" }}\n >\n {expanded && (\n <Styled.TripDetailDescription>\n <Styled.HideButton onClick={this.onHideClick}>\n <TimesCircle size=\"0.92em\" />\n </Styled.HideButton>\n {description}\n </Styled.TripDetailDescription>\n )}\n </VelocityTransitionGroup>\n </Styled.TripDetailSummary>\n </Styled.TripDetail>\n );\n }\n}\n\nTripDetail.propTypes = {\n icon: PropTypes.node.isRequired,\n summary: PropTypes.node.isRequired,\n description: PropTypes.node\n};\n\nTripDetail.defaultProps = {\n description: undefined\n};\n"],"file":"trip-detail.js"}
1
+ {"version":3,"sources":["../src/trip-detail.tsx"],"names":["React","Component","QuestionCircle","TimesCircle","VelocityTransitionGroup","S","TripDetail","props","toggle","expanded","state","onHideClick","onExpandClick","setState","icon","summary","description","animation"],"mappings":";;;;;;;;;;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAA+C,OAA/C;AACA,SAASC,cAAT,QAA+B,uCAA/B;AACA,SAASC,WAAT,QAA4B,oCAA5B;AACA,SAASC,uBAAT,QAAwC,gBAAxC;AAEA,OAAO,KAAKC,CAAZ,MAAmB,UAAnB;;IAYqBC,U;;;;;AACnB,sBAAYC,KAAZ,EAA0B;AAAA;;AAAA;;AACxB,8BAAMA,KAAN;;AADwB,UAO1BC,MAP0B,GAOjB,YAAY;AACnB,UAAQC,QAAR,GAAqB,MAAKC,KAA1B,CAAQD,QAAR;AACA,UAAIA,QAAJ,EAAc,MAAKE,WAAL,GAAd,KACK,MAAKC,aAAL;AACN,KAXyB;;AAAA,UAa1BA,aAb0B,GAaV,YAAY;AAC1B,YAAKC,QAAL,CAAc;AAAEJ,QAAAA,QAAQ,EAAE;AAAZ,OAAd;AACD,KAfyB;;AAAA,UAiB1BE,WAjB0B,GAiBZ,YAAY;AACxB,YAAKE,QAAL,CAAc;AAAEJ,QAAAA,QAAQ,EAAE;AAAZ,OAAd;AACD,KAnByB;;AAExB,UAAKC,KAAL,GAAa;AACXD,MAAAA,QAAQ,EAAE;AADC,KAAb;AAFwB;AAKzB;;;;WAgBD,kBAAuB;AACrB,wBAAuC,KAAKF,KAA5C;AAAA,UAAQO,IAAR,eAAQA,IAAR;AAAA,UAAcC,OAAd,eAAcA,OAAd;AAAA,UAAuBC,WAAvB,eAAuBA,WAAvB;AACA,UAAQP,QAAR,GAAqB,KAAKC,KAA1B,CAAQD,QAAR;AACA,0BACE,oBAAC,CAAD,CAAG,UAAH,qBACE,oBAAC,CAAD,CAAG,cAAH,QAAmBK,IAAnB,CADF,eAEE,oBAAC,CAAD,CAAG,iBAAH,QACGC,OADH,EAEGC,WAAW,iBACV,oBAAC,CAAD,CAAG,YAAH;AAAgB,QAAA,OAAO,EAAE,KAAKR;AAA9B,sBACE,oBAAC,cAAD;AAAgB,QAAA,IAAI,EAAC;AAArB,QADF,CAHJ,CAFF,eAUE,oBAAC,uBAAD;AACE,QAAA,KAAK,EAAE;AAAES,UAAAA,SAAS,EAAE;AAAb,SADT;AAEE,QAAA,KAAK,EAAE;AAAEA,UAAAA,SAAS,EAAE;AAAb;AAFT,SAIGR,QAAQ,iBACP,oBAAC,CAAD,CAAG,qBAAH,qBACE,oBAAC,CAAD,CAAG,UAAH;AAAc,QAAA,OAAO,EAAE,KAAKE;AAA5B,sBACE,oBAAC,WAAD;AAAa,QAAA,IAAI,EAAC;AAAlB,QADF,CADF,EAIGK,WAJH,CALJ,CAVF,CADF;AA0BD;;;;EAnDqCf,S;;SAAnBK,U","sourcesContent":["import React, { Component, ReactElement } from \"react\";\nimport { QuestionCircle } from \"@styled-icons/fa-solid/QuestionCircle\";\nimport { TimesCircle } from \"@styled-icons/fa-solid/TimesCircle\";\nimport { VelocityTransitionGroup } from \"velocity-react\";\n\nimport * as S from \"./styled\";\n\ntype Props = {\n description?: ReactElement | string;\n icon: ReactElement;\n summary: ReactElement | string;\n};\n\ntype State = {\n expanded: boolean;\n};\n\nexport default class TripDetail extends Component<Props, State> {\n constructor(props: Props) {\n super(props);\n this.state = {\n expanded: false\n };\n }\n\n toggle = (): void => {\n const { expanded } = this.state;\n if (expanded) this.onHideClick();\n else this.onExpandClick();\n };\n\n onExpandClick = (): void => {\n this.setState({ expanded: true });\n };\n\n onHideClick = (): void => {\n this.setState({ expanded: false });\n };\n\n render(): ReactElement {\n const { icon, summary, description } = this.props;\n const { expanded } = this.state;\n return (\n <S.TripDetail>\n <S.TripDetailIcon>{icon}</S.TripDetailIcon>\n <S.TripDetailSummary>\n {summary}\n {description && (\n <S.ExpandButton onClick={this.toggle}>\n <QuestionCircle size=\"0.92em\" />\n </S.ExpandButton>\n )}\n </S.TripDetailSummary>\n <VelocityTransitionGroup\n enter={{ animation: \"slideDown\" }}\n leave={{ animation: \"slideUp\" }}\n >\n {expanded && (\n <S.TripDetailDescription>\n <S.HideButton onClick={this.onHideClick}>\n <TimesCircle size=\"0.92em\" />\n </S.HideButton>\n {description}\n </S.TripDetailDescription>\n )}\n </VelocityTransitionGroup>\n </S.TripDetail>\n );\n }\n}\n"],"file":"trip-detail.js"}
package/esm/types.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
package/i18n/en-US.yml ADDED
@@ -0,0 +1,43 @@
1
+ # Default messages for the TripDetails component.
2
+ # To use from a react-intl application:
3
+ # - merge the content of this file into the messages object
4
+ # that has your other localized strings,
5
+ # - flatten the ids, i.e. convert a structure such as
6
+ # otpUi > TripDetails > calories
7
+ # into "otpUi.TripDetails.calories" (see TripDetail story for an example),
8
+ # - pass the resulting object to the messages prop of IntlProvider.
9
+ #
10
+ # The meaning of the pseudo <tags> used in the strings below is as follows:
11
+ # - <dietaryLink>: The link to the Dietary Guidelines for Americans will surround the text enclosed by the tag.
12
+ # - <strong>: The enclosed text will be rendered as strong (bold) text (same meaning as in HTML).
13
+
14
+ otpUi:
15
+ TripDetails:
16
+ calories: "Calories Burned: <strong>{calories, number, ::.}</strong>"
17
+ caloriesDescription: "Calories burned is based on
18
+ <strong>{walkMinutes, plural, one {# minute} other {# minutes}}</strong> spent walking and
19
+ <strong>{bikeMinutes, plural, one {# minute} other {# minutes}}</strong> spent biking during this trip.
20
+ Adapted from <dietaryLink>Dietary Guidelines for Americans 2005, page 16, Table 4</dietaryLink>."
21
+ departure: "Depart <strong>{departureDate, date, long}</strong> at <strong>{departureDate, time, short}</strong>"
22
+ flexDropOffMessage: >
23
+ {hasLeadTime, select,
24
+ true {To get off at your destination, you must call
25
+ {hasPhone, select,
26
+ true {{phoneNumber}}
27
+ other {ahead}
28
+ } at least {leadDays, plural, one {# day} other {# days}} in advance}
29
+ other {You must tell the operator where you want to get off.}
30
+ }.
31
+ flexPickupMessage: >
32
+ To take this route, you must call {hasPhone, select,
33
+ true {{phoneNumber}}
34
+ other {ahead}
35
+ }{hasLeadTime, select,
36
+ true { at least {leadDays, plural, one {# day} other {# days}} in advance}
37
+ other {}
38
+ }.
39
+ title: "Trip Details"
40
+ tncFare: "{companies} Fare: <strong>{minTNCFare} - {maxTNCFare}</strong>"
41
+ transitFare: "Transit Fare"
42
+ transitFareEntry: "{name}: <strong>{value}</strong>"
43
+ tripIncludesFlex: This trip includes flexible routes.
package/i18n/fr.yml ADDED
@@ -0,0 +1,31 @@
1
+ # Example translations for the TripDetails component into French.
2
+ otpUi:
3
+ TripDetails:
4
+ calories: "Calories dépensées : <strong>{calories, number, ::.}</strong>"
5
+ caloriesDescription: "La dépense calorique est calculée sur la base de
6
+ {walkMinutes, plural, one {<strong># minute</strong> effectuée} other {<strong># minutes</strong> effectuées}} à pied et
7
+ {bikeMinutes, plural, one {<strong># minute</strong> effectuée} other {<strong># minutes</strong> effectuées}} en vélo sur ce trajet.
8
+ (d'après <dietaryLink>Dietary Guidelines for Americans 2005, page 16, Table 4</dietaryLink>)"
9
+ departure: "Départ le <strong>{departureDate, date, long}</strong> à <strong>{departureDate, time, short}</strong>"
10
+ flexDropOffMessage: >
11
+ {hasLeadTime, select,
12
+ true {Pour descendre à votre destination, vous devez faire une réservation préalable
13
+ {hasPhone, select,
14
+ true {au {phoneNumber}}
15
+ other {}
16
+ } au moins {leadDays, plural, one {# jour} other {# jours}} à l'avance.}
17
+ other {Vous devez informer le conducteur de votre destination.}
18
+ }.
19
+ flexPickupMessage: >
20
+ Pour ce trajet, vous devez faire une réservation préalable {hasPhone, select,
21
+ true {au {phoneNumber}}
22
+ other {}
23
+ }{hasLeadTime, select,
24
+ true { au moins {leadDays, plural, one {# jour} other {# jours}} à l'avance}
25
+ other {}
26
+ }.
27
+ title: "Détails du trajet"
28
+ tncFare: "Tarif {companies} : <strong>{minTNCFare} - {maxTNCFare}</strong>"
29
+ transitFare: "Tarif en transports"
30
+ transitFareEntry: "{name} : <strong>{value}</strong>"
31
+ tripIncludesFlex: Ce trajet comprend un service à la demande (Flex).
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { ReactElement } from "react";
2
+ import * as S from "./styled";
3
+ import { TripDetailsProps } from "./types";
4
+ /**
5
+ * Renders trip details such as departure instructions, fare amount, and calories spent.
6
+ */
7
+ export declare function TripDetails({ CaloriesDetails, className, DepartureDetails, defaultFareKey, FareDetails, fareKeyNameMap, itinerary }: TripDetailsProps): ReactElement;
8
+ export default TripDetails;
9
+ export { S as Styled };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAIA,OAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAS5C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAG9B,OAAO,EAGL,gBAAgB,EACjB,MAAM,SAAS,CAAC;AA0HjB;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAC1B,eAAwC,EACxC,SAAc,EACd,gBAAuB,EACvB,cAA0B,EAC1B,WAAkB,EAClB,cAAmB,EACnB,SAAS,EACV,EAAE,gBAAgB,GAAG,YAAY,CAmPjC;AAED,eAAe,WAAW,CAAC;AAG3B,OAAO,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC"}
package/lib/index.js CHANGED
@@ -5,143 +5,336 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = TripDetails;
8
+ exports.TripDetails = TripDetails;
9
+ exports.Styled = exports.default = void 0;
10
+
11
+ var _flat = _interopRequireDefault(require("flat"));
9
12
 
10
13
  var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
11
14
 
12
- var _moment = _interopRequireDefault(require("moment"));
15
+ var _react = _interopRequireDefault(require("react"));
13
16
 
14
- var _propTypes = _interopRequireDefault(require("prop-types"));
17
+ var _reactIntl = require("react-intl");
15
18
 
16
- var _react = _interopRequireDefault(require("react"));
19
+ var _CalendarAlt = require("@styled-icons/fa-solid/CalendarAlt");
20
+
21
+ var _HandPaper = require("@styled-icons/fa-solid/HandPaper");
22
+
23
+ var _Heartbeat = require("@styled-icons/fa-solid/Heartbeat");
24
+
25
+ var _MoneyBillAlt = require("@styled-icons/fa-solid/MoneyBillAlt");
17
26
 
18
- var _faSolid = require("styled-icons/fa-solid");
27
+ var _PhoneVolume = require("@styled-icons/fa-solid/PhoneVolume");
19
28
 
20
- var Styled = _interopRequireWildcard(require("./styled"));
29
+ var _Route = require("@styled-icons/fa-solid/Route");
30
+
31
+ var S = _interopRequireWildcard(require("./styled"));
32
+
33
+ exports.Styled = S;
21
34
 
22
35
  var _tripDetail = _interopRequireDefault(require("./trip-detail"));
23
36
 
37
+ var _enUS = _interopRequireDefault(require("../i18n/en-US.yml"));
38
+
24
39
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
40
 
26
41
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
42
 
43
+ // @ts-expect-error FIXME: Create TypeScript types for core-utils packages.
44
+ // Load the default messages.
45
+ // HACK: We should flatten the messages loaded above because
46
+ // the YAML loaders behave differently between webpack and our version of jest:
47
+ // - the yaml loader for webpack returns a nested object,
48
+ // - the yaml loader for jest returns messages with flattened ids.
49
+ const defaultMessages = (0, _flat.default)(_enUS.default);
50
+ /**
51
+ * Format text bold (used with FormattedMessage).
52
+ */
53
+ // TODO: Find a better place for this utility.
54
+
55
+ function boldText(contents) {
56
+ return /*#__PURE__*/_react.default.createElement("strong", null, contents);
57
+ }
58
+ /**
59
+ * Render formatted fare.
60
+ * @param currencyCode The ISO currency code to use (USD, GBP, EUR).
61
+ * @param fare The fare value, in currency units, to be shown.
62
+ * @returns The formatted fare value according to the selected locale.
63
+ */
64
+
65
+
66
+ function renderFare(currencyCode, fare) {
67
+ return /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedNumber, {
68
+ currency: currencyCode // For dollars in locales such as 'fr',
69
+ // this will limit the display to just the dollar sign
70
+ // (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').
71
+ ,
72
+ currencyDisplay: "narrowSymbol",
73
+ value: fare // eslint-disable-next-line react/style-prop-object
74
+ ,
75
+ style: "currency"
76
+ });
77
+ }
78
+ /**
79
+ * Helper function to specify the link to dietary table.
80
+ */
81
+
82
+
83
+ function dietaryLink(contents) {
84
+ return /*#__PURE__*/_react.default.createElement("a", {
85
+ href: "https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4",
86
+ rel: "noopener noreferrer",
87
+ target: "_blank"
88
+ }, contents);
89
+ }
90
+ /**
91
+ * Helper function that assembles values for flex pickup/dropoff messages.
92
+ */
93
+
94
+
95
+ function getFlexMessageValues(info) {
96
+ var _info$contactInfo, _info$contactInfo2;
97
+
98
+ return {
99
+ hasLeadTime: _coreUtils.default.itinerary.isAdvanceBookingRequired(info),
100
+ hasPhone: !!(info !== null && info !== void 0 && (_info$contactInfo = info.contactInfo) !== null && _info$contactInfo !== void 0 && _info$contactInfo.phoneNumber),
101
+ leadDays: info.latestBookingTime.daysPrior,
102
+ phoneNumber: info === null || info === void 0 ? void 0 : (_info$contactInfo2 = info.contactInfo) === null || _info$contactInfo2 === void 0 ? void 0 : _info$contactInfo2.phoneNumber
103
+ };
104
+ }
105
+ /**
106
+ * Default rendering if no component is provided for the CaloriesDetails
107
+ * slot in the TripDetails component.
108
+ */
109
+
110
+
111
+ function DefaultCaloriesDetails({
112
+ bikeSeconds,
113
+ calories,
114
+ walkSeconds
115
+ }) {
116
+ return /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
117
+ defaultMessage: defaultMessages["otpUi.TripDetails.caloriesDescription"],
118
+ description: "Text describing how the calories relate to the walking and biking duration of a trip.",
119
+ id: "otpUi.TripDetails.caloriesDescription",
120
+ values: {
121
+ bikeMinutes: Math.round(bikeSeconds / 60),
122
+ calories: Math.round(calories),
123
+ dietaryLink,
124
+ strong: boldText,
125
+ walkMinutes: Math.round(walkSeconds / 60)
126
+ }
127
+ });
128
+ }
129
+ /**
130
+ * Helper component that renders a transit fare entry.
131
+ */
132
+
133
+
134
+ const TransitFare = ({
135
+ fareKey,
136
+ fareNameFallback,
137
+ fareKeyNameMap,
138
+ transitFares
139
+ }) => {
140
+ const currentFare = transitFares[fareKey];
141
+ return /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
142
+ defaultMessage: defaultMessages["otpUi.TripDetails.transitFareEntry"],
143
+ description: "Text showing the price of tickets on public transportation.",
144
+ id: "otpUi.TripDetails.transitFareEntry",
145
+ values: {
146
+ name: fareKeyNameMap[fareKey] || fareNameFallback || fareKey,
147
+ strong: boldText,
148
+ value: renderFare(currentFare.currencyCode, currentFare.transitFare / 100)
149
+ }
150
+ }));
151
+ };
152
+ /**
153
+ * Renders trip details such as departure instructions, fare amount, and calories spent.
154
+ */
155
+
156
+
28
157
  function TripDetails({
29
- className,
30
- itinerary,
31
- longDateFormat,
32
- messages,
33
- routingType,
34
- timeOptions
158
+ CaloriesDetails = DefaultCaloriesDetails,
159
+ className = "",
160
+ DepartureDetails = null,
161
+ defaultFareKey = "regular",
162
+ FareDetails = null,
163
+ fareKeyNameMap = {},
164
+ itinerary
35
165
  }) {
36
- const date = (0, _moment.default)(itinerary.startTime);
37
- messages = _coreUtils.default.messages.mergeMessages(TripDetails.defaultProps.messages, messages); // process the transit fare
166
+ // process the transit fare
167
+ const fareResult = _coreUtils.default.itinerary.calculateFares(itinerary, true);
38
168
 
39
169
  const {
40
- centsToString,
41
- dollarsToString,
42
170
  maxTNCFare,
43
171
  minTNCFare,
44
- transitFare
45
- } = _coreUtils.default.itinerary.calculateFares(itinerary);
172
+ tncCurrencyCode,
173
+ transitFares
174
+ } = fareResult;
175
+ let defaultFare = defaultFareKey;
176
+
177
+ if (!transitFares[defaultFareKey]) {
178
+ defaultFare = "regular";
179
+ }
46
180
 
47
- let companies;
181
+ let companies = "";
48
182
  itinerary.legs.forEach(leg => {
49
183
  if (leg.tncData) {
50
184
  companies = leg.tncData.company;
51
185
  }
52
186
  });
53
187
  let fare;
188
+ const fareKeys = transitFares && Object.keys(transitFares).sort();
189
+
190
+ if (transitFares && fareKeys.length > 0) {
191
+ // Depending on if there are additional fares to display either render a <span> or a <details>
192
+ const TransitFareWrapper = transitFares && fareKeys.length > 1 ? S.TransitFare : S.TransitFareSingle;
193
+ fare = /*#__PURE__*/_react.default.createElement(S.Fare, null, /*#__PURE__*/_react.default.createElement(TransitFareWrapper, null, /*#__PURE__*/_react.default.createElement("summary", {
194
+ style: {
195
+ display: fareKeys.length > 1 ? "list-item" : ""
196
+ }
197
+ }, /*#__PURE__*/_react.default.createElement(TransitFare, {
198
+ fareNameFallback: /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
199
+ defaultMessage: defaultMessages["otpUi.TripDetails.transitFare"],
200
+ description: "Text showing the price of tickets on public transportation.",
201
+ id: "otpUi.TripDetails.transitFare"
202
+ }),
203
+ fareKey: defaultFare,
204
+ fareKeyNameMap: fareKeyNameMap,
205
+ transitFares: transitFares
206
+ })), fareKeys.map(fareKey => {
207
+ // Don't show the default fare twice!
208
+ if (fareKey === defaultFare) {
209
+ return null;
210
+ }
54
211
 
55
- if (transitFare || minTNCFare) {
56
- fare = /*#__PURE__*/_react.default.createElement(Styled.Fare, null, transitFare && /*#__PURE__*/_react.default.createElement(Styled.TransitFare, null, messages.transitFare, ": ", /*#__PURE__*/_react.default.createElement("b", null, centsToString(transitFare))), minTNCFare !== 0 && /*#__PURE__*/_react.default.createElement(Styled.TNCFare, null, /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement(Styled.TNCFareCompanies, null, companies.toLowerCase()), " ", messages.fare, ":", " ", /*#__PURE__*/_react.default.createElement("b", null, dollarsToString(minTNCFare), " - ", dollarsToString(maxTNCFare))));
57
- } // Compute calories burned.
212
+ return /*#__PURE__*/_react.default.createElement(TransitFare, {
213
+ fareKey: fareKey,
214
+ key: fareKey,
215
+ fareKeyNameMap: fareKeyNameMap,
216
+ transitFares: transitFares
217
+ });
218
+ })), minTNCFare !== 0 && /*#__PURE__*/_react.default.createElement(S.TNCFare, null, /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
219
+ defaultMessage: defaultMessages["otpUi.TripDetails.tncFare"],
220
+ description: "Text showing the price paid to transportation network companies.",
221
+ id: "otpUi.TripDetails.tncFare",
222
+ values: {
223
+ companies:
224
+ /*#__PURE__*/
225
+ // S.TNCFareCompanies capitalizes the TNC company ID (e.g. "COMPANY")
226
+ // after it is converted to lowercase, so it renders as "Company".
227
+ _react.default.createElement(S.TNCFareCompanies, null, companies.toLowerCase()),
228
+ maxTNCFare: renderFare(tncCurrencyCode, maxTNCFare),
229
+ minTNCFare: renderFare(tncCurrencyCode, minTNCFare),
230
+ strong: boldText
231
+ }
232
+ })));
233
+ }
58
234
 
235
+ const departureDate = new Date(itinerary.startTime); // Compute calories burned.
59
236
 
60
237
  const {
61
238
  bikeDuration,
62
239
  caloriesBurned,
63
240
  walkDuration
64
- } = _coreUtils.default.itinerary.calculatePhysicalActivity(itinerary);
241
+ } = _coreUtils.default.itinerary.calculatePhysicalActivity(itinerary); // Parse flex info and generate appropriate strings
65
242
 
66
- return /*#__PURE__*/_react.default.createElement(Styled.TripDetails, {
243
+
244
+ const containsFlex = itinerary.legs.some(_coreUtils.default.itinerary.isFlex);
245
+ const pickupBookingInfo = itinerary.legs.map(leg => leg.pickupBookingInfo).filter(info => !!info);
246
+ const dropOffBookingInfo = itinerary.legs.map(leg => leg.dropOffBookingInfo).filter(info => !!info);
247
+ return /*#__PURE__*/_react.default.createElement(S.TripDetails, {
67
248
  className: className
68
- }, /*#__PURE__*/_react.default.createElement(Styled.TripDetailsHeader, null, messages.title), /*#__PURE__*/_react.default.createElement(Styled.TripDetailsBody, null, /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
69
- description: messages.departDescription,
70
- icon: /*#__PURE__*/_react.default.createElement(_faSolid.CalendarAlt, {
249
+ }, /*#__PURE__*/_react.default.createElement(S.TripDetailsHeader, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
250
+ defaultMessage: defaultMessages["otpUi.TripDetails.title"],
251
+ description: "Title (heading) text of the component.",
252
+ id: "otpUi.TripDetails.title"
253
+ })), /*#__PURE__*/_react.default.createElement(S.TripDetailsBody, null, /*#__PURE__*/_react.default.createElement(_tripDetail.default // Any custom description for the Departure message needs to be handled by the slot.
254
+ , {
255
+ description: DepartureDetails && /*#__PURE__*/_react.default.createElement(DepartureDetails, {
256
+ departureDate: departureDate
257
+ }),
258
+ icon: /*#__PURE__*/_react.default.createElement(_CalendarAlt.CalendarAlt, {
71
259
  size: 17
72
260
  }),
73
- summary: /*#__PURE__*/_react.default.createElement(Styled.Timing, null, /*#__PURE__*/_react.default.createElement("span", null, messages.depart, " ", /*#__PURE__*/_react.default.createElement("b", null, date.format(longDateFormat))), routingType === "ITINERARY" && /*#__PURE__*/_react.default.createElement("span", null, " ", messages.at, " ", /*#__PURE__*/_react.default.createElement("b", null, _coreUtils.default.time.formatTime(itinerary.startTime, timeOptions))))
74
- }), fare && /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
75
- description: messages.transitFareDescription,
76
- icon: /*#__PURE__*/_react.default.createElement(_faSolid.MoneyBillAlt, {
261
+ summary: /*#__PURE__*/_react.default.createElement(S.Timing, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
262
+ defaultMessage: defaultMessages["otpUi.TripDetails.departure"],
263
+ description: "Text showing the departure date/time for a trip.",
264
+ id: "otpUi.TripDetails.departure",
265
+ values: {
266
+ departureDate,
267
+ strong: boldText
268
+ }
269
+ }))
270
+ }), fare && /*#__PURE__*/_react.default.createElement(_tripDetail.default // Any custom description for the transit fare needs to be handled by the slot.
271
+ , {
272
+ description: FareDetails && /*#__PURE__*/_react.default.createElement(FareDetails, {
273
+ maxTNCFare: maxTNCFare,
274
+ minTNCFare: minTNCFare,
275
+ transitFares: transitFares
276
+ }),
277
+ icon: /*#__PURE__*/_react.default.createElement(_MoneyBillAlt.MoneyBillAlt, {
77
278
  size: 17
78
279
  }),
79
280
  summary: fare
80
281
  }), caloriesBurned > 0 && /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
81
- icon: /*#__PURE__*/_react.default.createElement(_faSolid.Heartbeat, {
282
+ icon: /*#__PURE__*/_react.default.createElement(_Heartbeat.Heartbeat, {
283
+ size: 17
284
+ }),
285
+ summary: /*#__PURE__*/_react.default.createElement(S.CaloriesSummary, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
286
+ defaultMessage: defaultMessages["otpUi.TripDetails.calories"],
287
+ description: "Text showing the number of calories for the walking and biking legs of a trip.",
288
+ id: "otpUi.TripDetails.calories",
289
+ values: {
290
+ calories: caloriesBurned,
291
+ strong: boldText
292
+ }
293
+ })),
294
+ description: CaloriesDetails && /*#__PURE__*/_react.default.createElement(CaloriesDetails, {
295
+ bikeSeconds: bikeDuration,
296
+ calories: caloriesBurned,
297
+ walkSeconds: walkDuration
298
+ })
299
+ }), containsFlex && /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
300
+ summary: /*#__PURE__*/_react.default.createElement(S.FlexSummary, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
301
+ defaultMessage: defaultMessages["otpUi.TripDetails.tripIncludesFlex"],
302
+ description: "Text stating that portions of the trip include a flex (on-demand) transit service.",
303
+ id: "otpUi.TripDetails.tripIncludesFlex"
304
+ })),
305
+ icon: /*#__PURE__*/_react.default.createElement(_Route.Route, {
306
+ size: 17
307
+ })
308
+ }), pickupBookingInfo && pickupBookingInfo.map(info => /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
309
+ key: info.pickupMessage,
310
+ icon: /*#__PURE__*/_react.default.createElement(_PhoneVolume.PhoneVolume, {
82
311
  size: 17
83
312
  }),
84
- summary: /*#__PURE__*/_react.default.createElement(Styled.CaloriesSummary, null, messages.caloriesBurned, ": ", /*#__PURE__*/_react.default.createElement("b", null, Math.round(caloriesBurned))),
85
- description: /*#__PURE__*/_react.default.createElement(Styled.CaloriesDescription, null, "Calories burned is based on", " ", /*#__PURE__*/_react.default.createElement("b", null, Math.round(walkDuration / 60), " minute(s)"), " spent walking and ", /*#__PURE__*/_react.default.createElement("b", null, Math.round(bikeDuration / 60), " minute(s)"), " spent biking during this trip. Adapted from", " ", /*#__PURE__*/_react.default.createElement("a", {
86
- href: "https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4",
87
- rel: "noopener noreferrer",
88
- target: "_blank"
89
- }, "Dietary Guidelines for Americans 2005, page 16, Table 4"), ".")
90
- })));
313
+ summary: /*#__PURE__*/_react.default.createElement(S.FlexPickupSummary, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
314
+ defaultMessage: defaultMessages["otpUi.TripDetails.flexPickupMessage"],
315
+ description: "Instructions for booking and boarding the flex (on-demand) transit service.",
316
+ id: "otpUi.TripDetails.flexPickupMessage",
317
+ values: getFlexMessageValues(info)
318
+ })),
319
+ description: info.pickupMessage
320
+ })), dropOffBookingInfo && dropOffBookingInfo.map(info => /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
321
+ description: info.dropOffMessage,
322
+ icon: _coreUtils.default.itinerary.isAdvanceBookingRequired(info) ? /*#__PURE__*/_react.default.createElement(_PhoneVolume.PhoneVolume, {
323
+ size: 17
324
+ }) : /*#__PURE__*/_react.default.createElement(_HandPaper.HandPaper, {
325
+ size: 17
326
+ }),
327
+ key: info.dropOffMessage,
328
+ summary: /*#__PURE__*/_react.default.createElement(S.FlexDropOffSummary, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
329
+ defaultMessage: defaultMessages["otpUi.TripDetails.flexDropOffMessage"],
330
+ description: "Instructions for getting off the flex (on-demand) transit service.",
331
+ id: "otpUi.TripDetails.flexDropOffMessage",
332
+ values: getFlexMessageValues(info)
333
+ }))
334
+ }))));
91
335
  }
92
336
 
93
- TripDetails.propTypes = {
94
- /** Used for additional styling with styled components for example. */
95
- className: _propTypes.default.string,
96
-
97
- /** Itinerary that the user has selected to view, contains multiple legs */
98
- itinerary: _coreUtils.default.types.itineraryType.isRequired,
99
-
100
- /** the desired format to use for a long date */
101
- longDateFormat: _propTypes.default.string,
102
-
103
- /**
104
- * messages to use for l10n/i8n
105
- *
106
- * Note: messages with default null values included here for visibility.
107
- * Overriding with a truthy string value will cause the expandable help
108
- * message to appear in trip details.
109
- */
110
- messages: _propTypes.default.shape({
111
- at: _propTypes.default.string,
112
- caloriesBurned: _propTypes.default.string,
113
- // FIXME: Add templated string description.
114
- caloriesBurnedDescription: _propTypes.default.string,
115
- depart: _propTypes.default.string,
116
- departDescription: _propTypes.default.string,
117
- title: _propTypes.default.string,
118
- fare: _propTypes.default.string,
119
- transitFare: _propTypes.default.string,
120
- transitFareDescription: _propTypes.default.string
121
- }),
122
-
123
- /** whether the routing type is an itinerary or a profile result */
124
- routingType: _propTypes.default.string,
125
-
126
- /** Contains the preferred format string for time display and a timezone offset */
127
- timeOptions: _coreUtils.default.types.timeOptionsType
128
- };
129
- TripDetails.defaultProps = {
130
- className: null,
131
- longDateFormat: null,
132
- messages: {
133
- at: "at",
134
- caloriesBurned: "Calories Burned",
135
- // FIXME: Add templated string description.
136
- caloriesBurnedDescription: null,
137
- depart: "Depart",
138
- departDescription: null,
139
- title: "Trip Details",
140
- fare: "Fare",
141
- transitFare: "Transit Fare",
142
- transitFareDescription: null
143
- },
144
- routingType: "ITINERARY",
145
- timeOptions: null
146
- };
337
+ var _default = TripDetails; // Rename styled components for export
338
+
339
+ exports.default = _default;
147
340
  //# sourceMappingURL=index.js.map