@opentripplanner/trip-details 8.0.2 → 9.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.
Files changed (78) hide show
  1. package/esm/components/fares-v2-table.js +194 -0
  2. package/esm/components/fares-v2-table.js.map +1 -0
  3. package/esm/components/fares.js +28 -58
  4. package/esm/components/fares.js.map +1 -1
  5. package/esm/index.js +5 -5
  6. package/esm/index.js.map +1 -1
  7. package/esm/styled.js +29 -22
  8. package/esm/styled.js.map +1 -1
  9. package/esm/trip-detail.js +1 -8
  10. package/esm/trip-detail.js.map +1 -1
  11. package/esm/types.js.map +1 -1
  12. package/i18n/en-US.yml +2 -7
  13. package/i18n/es.yml +0 -7
  14. package/i18n/fr.yml +2 -7
  15. package/i18n/ko.yml +2 -9
  16. package/i18n/nb_NO.yml +1 -4
  17. package/i18n/pl.yml +24 -19
  18. package/i18n/ru.yml +3 -10
  19. package/i18n/ta.yml +20 -25
  20. package/i18n/tl.yml +2 -9
  21. package/i18n/tr.yml +0 -7
  22. package/i18n/vi.yml +2 -9
  23. package/i18n/zh_Hans.yml +2 -9
  24. package/i18n/zh_Hant.yml +0 -7
  25. package/lib/components/departure-date.js +45 -42
  26. package/lib/components/departure-date.js.map +1 -1
  27. package/lib/components/emissions.js +57 -64
  28. package/lib/components/emissions.js.map +1 -1
  29. package/lib/components/fares-v2-table.d.ts +9 -0
  30. package/lib/components/fares-v2-table.d.ts.map +1 -0
  31. package/lib/components/fares-v2-table.js +158 -0
  32. package/lib/components/fares-v2-table.js.map +1 -0
  33. package/lib/components/fares.d.ts +4 -4
  34. package/lib/components/fares.d.ts.map +1 -1
  35. package/lib/components/fares.js +87 -151
  36. package/lib/components/fares.js.map +1 -1
  37. package/lib/components/flex-booking-info.js +55 -38
  38. package/lib/components/flex-booking-info.js.map +1 -1
  39. package/lib/components/time-active.js +40 -66
  40. package/lib/components/time-active.js.map +1 -1
  41. package/lib/index.d.ts +3 -3
  42. package/lib/index.d.ts.map +1 -1
  43. package/lib/index.js +53 -66
  44. package/lib/index.js.map +1 -1
  45. package/lib/styled.d.ts +1 -0
  46. package/lib/styled.d.ts.map +1 -1
  47. package/lib/styled.js +120 -86
  48. package/lib/styled.js.map +1 -1
  49. package/lib/trip-detail.d.ts.map +1 -1
  50. package/lib/trip-detail.js +65 -71
  51. package/lib/trip-detail.js.map +1 -1
  52. package/lib/types.d.ts +4 -41
  53. package/lib/types.d.ts.map +1 -1
  54. package/lib/types.js +1 -4
  55. package/lib/types.js.map +1 -1
  56. package/lib/utils.js +17 -23
  57. package/lib/utils.js.map +1 -1
  58. package/package.json +3 -5
  59. package/src/TripDetails.story.tsx +47 -158
  60. package/src/__snapshots__/TripDetails.story.tsx.snap +1726 -924
  61. package/src/components/fares-v2-table.tsx +262 -0
  62. package/src/components/fares.tsx +48 -87
  63. package/src/index.tsx +4 -4
  64. package/src/styled.ts +11 -2
  65. package/src/trip-detail.tsx +1 -10
  66. package/src/types.ts +4 -40
  67. package/tsconfig.json +1 -1
  68. package/tsconfig.tsbuildinfo +1 -1
  69. package/__mocks__/custom-english-messages.yml +0 -14
  70. package/__mocks__/custom-french-messages.yml +0 -9
  71. package/esm/components/fare-table.js +0 -122
  72. package/esm/components/fare-table.js.map +0 -1
  73. package/i18n/i18n-exceptions.json +0 -12
  74. package/lib/components/fare-table.d.ts +0 -5
  75. package/lib/components/fare-table.d.ts.map +0 -1
  76. package/lib/components/fare-table.js +0 -118
  77. package/lib/components/fare-table.js.map +0 -1
  78. package/src/components/fare-table.tsx +0 -215
@@ -1,14 +0,0 @@
1
- otpUi:
2
- TripDetails:
3
- FareTable:
4
- cash: Cash
5
- electronic: ORCA
6
- regular: Regular
7
- senior: Senior
8
- special: LIFT
9
- youth: Youth
10
- departure: >-
11
- <strong>Leave</strong> at <strong>{departureDate, time, short}</strong> on
12
- <strong>{departureDate, date, long}</strong>
13
- title: Custom Trip Details Title
14
- tncFare: Pay <strong>{minTNCFare}-{maxTNCFare}</strong> to {companies}
@@ -1,9 +0,0 @@
1
- otpUi:
2
- TripDetails:
3
- FareTable:
4
- cash: Espèces
5
- electronic: ORCA
6
- regular: Plein tarif
7
- senior: Senior
8
- special: LIFT
9
- youth: Jeune
@@ -1,122 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- import React from "react";
5
- import styled from "styled-components";
6
- import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
7
- import { getItineraryCost, getLegCost, getLegRouteName } from "@opentripplanner/core-utils/lib/itinerary";
8
- import { FormattedMessage, useIntl } from "react-intl";
9
- import { flatten } from "flat";
10
- import { boldText, renderFare } from "../utils";
11
- // Load the default messages.
12
- import defaultEnglishMessages from "../../i18n/en-US.yml";
13
- import { InvisibleA11yLabel } from "../styled";
14
-
15
- // HACK: We should flatten the messages loaded above because
16
- // the YAML loaders behave differently between webpack and our version of jest:
17
- // - the yaml loader for webpack returns a nested object,
18
- // - the yaml loader for jest returns messages with flattened ids.
19
- var defaultMessages = flatten(defaultEnglishMessages);
20
- var TableHeader = styled.thead.withConfig({
21
- displayName: "fare-table__TableHeader",
22
- componentId: "sc-1ntg4ma-0"
23
- })(["th{font-weight:normal;min-width:5ch;padding:0.75em 1.5em;text-align:center;}th:nth-of-type(2n + 1){background:#cccccc22;}th.main{background:#333333;color:#ffffffcc;}"]);
24
- var Table = styled.table.withConfig({
25
- displayName: "fare-table__Table",
26
- componentId: "sc-1ntg4ma-1"
27
- })(["border-collapse:collapse;display:block;margin-bottom:16px;padding:0;td{text-align:right;}td:nth-of-type(2n + 1){background:#cccccc22;}td.no-zebra{background:none;}th:first-of-type{height:40px;}"]);
28
- var TransferIcon = styled(Transfer).withConfig({
29
- displayName: "fare-table__TransferIcon",
30
- componentId: "sc-1ntg4ma-2"
31
- })(["padding-left:4px;"]);
32
- var useGetHeaderString = function useGetHeaderString(headerKey) {
33
- var intl = useIntl();
34
- return intl.formatMessage({
35
- id: "otpUi.TripDetails.FareTable.".concat(headerKey),
36
- description: "Fare leg table header for key ".concat(headerKey),
37
- defaultMessage: defaultEnglishMessages["otpUi.TripDetails.FareTable.".concat(headerKey)]
38
- });
39
- };
40
- var hasFareInfo = function hasFareInfo(column) {
41
- return function (leg) {
42
- return getLegCost(leg, column.mediumId, column.riderCategoryId).price !== undefined;
43
- };
44
- };
45
- var FareTypeTable = function FareTypeTable(_ref) {
46
- var cols = _ref.cols,
47
- headerKey = _ref.headerKey,
48
- legs = _ref.legs;
49
- var intl = useIntl();
50
- var filteredLegs = legs.filter(function (leg) {
51
- var _leg$fareProducts;
52
- return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
53
- });
54
- var colsToRender = cols.filter(function (col) {
55
- return filteredLegs.some(hasFareInfo(col));
56
- }).map(function (col) {
57
- return _objectSpread(_objectSpread({}, col), {}, {
58
- total: filteredLegs.every(hasFareInfo(col)) ? getItineraryCost(filteredLegs, col.mediumId, col.riderCategoryId) : undefined
59
- });
60
- });
61
- var headerString = useGetHeaderString(headerKey);
62
- if (colsToRender.length) {
63
- return /*#__PURE__*/React.createElement(Table, null, /*#__PURE__*/React.createElement(TableHeader, null, /*#__PURE__*/React.createElement("th", {
64
- className: "main",
65
- scope: "col"
66
- }, boldText(headerString)), colsToRender.map(function (col) {
67
- var _fare$currency;
68
- var fare = col.total;
69
- return /*#__PURE__*/React.createElement("th", {
70
- scope: "col",
71
- key: col.columnHeaderKey || "".concat(col.mediumId, "-").concat(col.riderCategoryId)
72
- }, boldText(useGetHeaderString(col.columnHeaderKey)), /*#__PURE__*/React.createElement("br", null), (fare === null || fare === void 0 ? void 0 : fare.amount) !== undefined ? renderFare(fare === null || fare === void 0 || (_fare$currency = fare.currency) === null || _fare$currency === void 0 ? void 0 : _fare$currency.code, fare === null || fare === void 0 ? void 0 : fare.amount) : /*#__PURE__*/React.createElement(React.Fragment, null, "-", /*#__PURE__*/React.createElement(InvisibleA11yLabel, null, /*#__PURE__*/React.createElement(FormattedMessage, {
73
- id: "otpUi.TripDetails.missingFareTotal"
74
- }))));
75
- })), filteredLegs.map(function (leg, index) {
76
- return /*#__PURE__*/React.createElement("tr", {
77
- key: index
78
- }, /*#__PURE__*/React.createElement("td", {
79
- className: "no-zebra"
80
- }, getLegRouteName(leg)), colsToRender.map(function (col) {
81
- var _price$currency, _price$currency2;
82
- var _getLegCost = getLegCost(leg, col.mediumId, col.riderCategoryId),
83
- price = _getLegCost.price,
84
- transferAmount = _getLegCost.transferAmount;
85
- return /*#__PURE__*/React.createElement("td", {
86
- key: col.columnHeaderKey,
87
- title: (transferAmount === null || transferAmount === void 0 ? void 0 : transferAmount.amount) > 0 && intl.formatMessage({
88
- defaultMessage: defaultMessages["otpUi.TripDetails.transferDiscountExplanation"],
89
- description: "Text explaining the transfer discount applied to this fare.",
90
- id: "otpUi.TripDetails.transferDiscountExplanation"
91
- }, {
92
- transferAmount: intl.formatNumber(transferAmount === null || transferAmount === void 0 ? void 0 : transferAmount.amount, {
93
- currency: price === null || price === void 0 || (_price$currency = price.currency) === null || _price$currency === void 0 ? void 0 : _price$currency.code,
94
- currencyDisplay: "narrowSymbol",
95
- style: "currency"
96
- })
97
- })
98
- }, (transferAmount === null || transferAmount === void 0 ? void 0 : transferAmount.amount) > 0 && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TransferIcon, {
99
- size: 16
100
- }), " "), price ? renderFare(price === null || price === void 0 || (_price$currency2 = price.currency) === null || _price$currency2 === void 0 ? void 0 : _price$currency2.code, price === null || price === void 0 ? void 0 : price.amount) : /*#__PURE__*/React.createElement(React.Fragment, null, "-", /*#__PURE__*/React.createElement(InvisibleA11yLabel, null, /*#__PURE__*/React.createElement(FormattedMessage, {
101
- id: "otpUi.TripDetails.legMissingFareInfo"
102
- }))));
103
- }));
104
- }));
105
- }
106
- return null;
107
- };
108
- var FareLegTable = function FareLegTable(_ref2) {
109
- var layout = _ref2.layout,
110
- legs = _ref2.legs;
111
- // the layout argument contains an object for every table to be displayed
112
- return /*#__PURE__*/React.createElement("div", null, layout.map(function (config) {
113
- return /*#__PURE__*/React.createElement(FareTypeTable, {
114
- cols: config.cols,
115
- headerKey: config.headerKey,
116
- key: config.headerKey,
117
- legs: legs
118
- });
119
- }));
120
- };
121
- export default FareLegTable;
122
- //# sourceMappingURL=fare-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fare-table.js","names":["React","styled","Transfer","getItineraryCost","getLegCost","getLegRouteName","FormattedMessage","useIntl","flatten","boldText","renderFare","defaultEnglishMessages","InvisibleA11yLabel","defaultMessages","TableHeader","thead","withConfig","displayName","componentId","Table","table","TransferIcon","useGetHeaderString","headerKey","intl","formatMessage","id","concat","description","defaultMessage","hasFareInfo","column","leg","mediumId","riderCategoryId","price","undefined","FareTypeTable","_ref","cols","legs","filteredLegs","filter","_leg$fareProducts","fareProducts","length","colsToRender","col","some","map","_objectSpread","total","every","headerString","createElement","className","scope","_fare$currency","fare","key","columnHeaderKey","amount","currency","code","Fragment","index","_price$currency","_price$currency2","_getLegCost","transferAmount","title","formatNumber","currencyDisplay","style","size","FareLegTable","_ref2","layout","config"],"sources":["../../src/components/fare-table.tsx"],"sourcesContent":["import { FareProductSelector, Leg } from \"@opentripplanner/types\";\nimport React from \"react\";\nimport styled from \"styled-components\";\nimport { Transfer } from \"@styled-icons/boxicons-regular/Transfer\";\n\nimport {\n getItineraryCost,\n getLegCost,\n getLegRouteName\n} from \"@opentripplanner/core-utils/lib/itinerary\";\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { flatten } from \"flat\";\nimport { boldText, renderFare } from \"../utils\";\n\nimport { FareLegTableProps, FareTableLayout } from \"../types\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../../i18n/en-US.yml\";\nimport { InvisibleA11yLabel } from \"../styled\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);\n\ninterface FareTypeTableProps extends FareTableLayout {\n legs: Leg[];\n}\n\nconst TableHeader = styled.thead`\n th {\n font-weight: normal;\n min-width: 5ch;\n padding: 0.75em 1.5em;\n text-align: center;\n }\n th:nth-of-type(2n + 1) {\n background: #cccccc22;\n }\n th.main {\n background: #333333;\n color: #ffffffcc;\n }\n`;\n\nconst Table = styled.table`\n border-collapse: collapse;\n display: block;\n margin-bottom: 16px;\n padding: 0;\n\n td {\n text-align: right;\n }\n td:nth-of-type(2n + 1) {\n background: #cccccc22;\n }\n td.no-zebra {\n background: none;\n }\n th:first-of-type {\n height: 40px;\n }\n`;\n\nconst TransferIcon = styled(Transfer)`\n padding-left: 4px;\n`;\n\nconst useGetHeaderString = (headerKey: string): string => {\n const intl = useIntl();\n return intl.formatMessage({\n id: `otpUi.TripDetails.FareTable.${headerKey}`,\n description: `Fare leg table header for key ${headerKey}`,\n defaultMessage:\n defaultEnglishMessages[`otpUi.TripDetails.FareTable.${headerKey}`]\n });\n};\n\nconst hasFareInfo = (column: FareProductSelector) => (leg: Leg) =>\n getLegCost(leg, column.mediumId, column.riderCategoryId).price !== undefined;\n\nconst FareTypeTable = ({\n cols,\n headerKey,\n legs\n}: FareTypeTableProps): JSX.Element => {\n const intl = useIntl();\n\n const filteredLegs = legs.filter(leg => leg.fareProducts?.length > 0);\n const colsToRender = cols\n .filter(col => filteredLegs.some(hasFareInfo(col)))\n .map(col => ({\n ...col,\n total: filteredLegs.every(hasFareInfo(col))\n ? getItineraryCost(filteredLegs, col.mediumId, col.riderCategoryId)\n : undefined\n }));\n\n const headerString = useGetHeaderString(headerKey);\n\n if (colsToRender.length) {\n return (\n <Table>\n <TableHeader>\n <th className=\"main\" scope=\"col\">\n {boldText(headerString)}\n </th>\n {colsToRender.map(col => {\n const fare = col.total;\n return (\n <th\n scope=\"col\"\n key={\n col.columnHeaderKey ||\n `${col.mediumId}-${col.riderCategoryId}`\n }\n >\n {boldText(useGetHeaderString(col.columnHeaderKey))}\n <br />\n {fare?.amount !== undefined ? (\n renderFare(fare?.currency?.code, fare?.amount)\n ) : (\n <>\n -\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.missingFareTotal\" />\n </InvisibleA11yLabel>\n </>\n )}\n </th>\n );\n })}\n </TableHeader>\n {filteredLegs.map((leg, index) => (\n <tr key={index}>\n <td className=\"no-zebra\">{getLegRouteName(leg)}</td>\n {colsToRender.map(col => {\n const { price, transferAmount } = getLegCost(\n leg,\n col.mediumId,\n col.riderCategoryId\n );\n return (\n <td\n key={col.columnHeaderKey}\n title={\n transferAmount?.amount > 0 &&\n intl.formatMessage(\n {\n defaultMessage:\n defaultMessages[\n \"otpUi.TripDetails.transferDiscountExplanation\"\n ],\n description:\n \"Text explaining the transfer discount applied to this fare.\",\n id: \"otpUi.TripDetails.transferDiscountExplanation\"\n },\n {\n transferAmount: intl.formatNumber(\n transferAmount?.amount,\n {\n currency: price?.currency?.code,\n currencyDisplay: \"narrowSymbol\",\n style: \"currency\"\n }\n )\n }\n )\n }\n >\n {transferAmount?.amount > 0 && (\n <>\n <TransferIcon size={16} />{\" \"}\n </>\n )}\n {price ? (\n renderFare(price?.currency?.code, price?.amount)\n ) : (\n <>\n -\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.legMissingFareInfo\" />\n </InvisibleA11yLabel>\n </>\n )}\n </td>\n );\n })}\n </tr>\n ))}\n </Table>\n );\n }\n return null;\n};\n\nconst FareLegTable = ({ layout, legs }: FareLegTableProps): JSX.Element => {\n // the layout argument contains an object for every table to be displayed\n return (\n <div>\n {layout.map(config => (\n <FareTypeTable\n cols={config.cols}\n headerKey={config.headerKey}\n key={config.headerKey}\n legs={legs}\n />\n ))}\n </div>\n );\n};\n\nexport default FareLegTable;\n"],"mappings":";;;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,MAAM,MAAM,mBAAmB;AACtC,SAASC,QAAQ,QAAQ,yCAAyC;AAElE,SACEC,gBAAgB,EAChBC,UAAU,EACVC,eAAe,QACV,2CAA2C;AAClD,SAASC,gBAAgB,EAAEC,OAAO,QAAQ,YAAY;AACtD,SAASC,OAAO,QAAQ,MAAM;AAC9B,SAASC,QAAQ,EAAEC,UAAU,QAAQ,UAAU;AAI/C;AACA,OAAOC,sBAAsB,MAAM,sBAAsB;AACzD,SAASC,kBAAkB,QAAQ,WAAW;;AAE9C;AACA;AACA;AACA;AACA,IAAMC,eAAuC,GAAGL,OAAO,CAACG,sBAAsB,CAAC;AAM/E,IAAMG,WAAW,GAAGb,MAAM,CAACc,KAAK,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,6KAc/B;AAED,IAAMC,KAAK,GAAGlB,MAAM,CAACmB,KAAK,CAAAJ,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,yMAkBzB;AAED,IAAMG,YAAY,GAAGpB,MAAM,CAACC,QAAQ,CAAC,CAAAc,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,yBAEpC;AAED,IAAMI,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAIC,SAAiB,EAAa;EACxD,IAAMC,IAAI,GAAGjB,OAAO,CAAC,CAAC;EACtB,OAAOiB,IAAI,CAACC,aAAa,CAAC;IACxBC,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AAsD,aAAA,CAACjC,YAAY;UAACqD,IAAI,EAAE;QAAG,CAAE,CAAC,EAAC,GAC3B,CACH,EACAvC,KAAK,GACJzB,UAAU,CAACyB,KAAK,aAALA,KAAK,gBAAAgC,gBAAA,GAALhC,KAAK,CAAE2B,QAAQ,cAAAK,gBAAA,uBAAfA,gBAAA,CAAiBJ,IAAI,EAAE5B,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAE0B,MAAM,CAAC,gBAEhD7D,KAAA,CAAAsD,aAAA,CAAAtD,KAAA,CAAAgE,QAAA,QAAE,GAEA,eAAAhE,KAAA,CAAAsD,aAAA,CAAC1C,kBAAkB,qBACjBZ,KAAA,CAAAsD,aAAA,CAAChD,gBAAgB;UAACoB,EAAE,EAAC;QAAsC,CAAE,CAC3C,CACpB,CAEF,CAAC;MAET,CAAC,CACC,CAAC;IAAA,CACN,CACI,CAAC;EAEZ;EACA,OAAO,IAAI;AACb,CAAC;AAED,IAAMiD,YAAY,GAAG,SAAfA,YAAYA,CAAAC,KAAA,EAAyD;EAAA,IAAnDC,MAAM,GAAAD,KAAA,CAANC,MAAM;IAAErC,IAAI,GAAAoC,KAAA,CAAJpC,IAAI;EAClC;EACA,oBACExC,KAAA,CAAAsD,aAAA,cACGuB,MAAM,CAAC5B,GAAG,CAAC,UAAA6B,MAAM;IAAA,oBAChB9E,KAAA,CAAAsD,aAAA,CAACjB,aAAa;MACZE,IAAI,EAAEuC,MAAM,CAACvC,IAAK;MAClBhB,SAAS,EAAEuD,MAAM,CAACvD,SAAU;MAC5BoC,GAAG,EAAEmB,MAAM,CAACvD,SAAU;MACtBiB,IAAI,EAAEA;IAAK,CACZ,CAAC;EAAA,CACH,CACE,CAAC;AAEV,CAAC;AAED,eAAemC,YAAY","ignoreList":[]}
@@ -1,12 +0,0 @@
1
- {
2
- "groups": {
3
- "otpUi.TripDetails.FareTable.*": [
4
- "cash",
5
- "electronic",
6
- "regular",
7
- "special",
8
- "senior",
9
- "youth"
10
- ]
11
- }
12
- }
@@ -1,5 +0,0 @@
1
- /// <reference types="react" />
2
- import { FareLegTableProps } from "../types";
3
- declare const FareLegTable: ({ layout, legs }: FareLegTableProps) => JSX.Element;
4
- export default FareLegTable;
5
- //# sourceMappingURL=fare-table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fare-table.d.ts","sourceRoot":"","sources":["../../src/components/fare-table.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,UAAU,CAAC;AAwL9D,QAAA,MAAM,YAAY,qBAAsB,iBAAiB,KAAG,WAc3D,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,118 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _styledComponents = _interopRequireDefault(require("styled-components"));
10
- var _Transfer = require("@styled-icons/boxicons-regular/Transfer");
11
- var _itinerary = require("@opentripplanner/core-utils/lib/itinerary");
12
- var _reactIntl = require("react-intl");
13
- var _flat = require("flat");
14
- var _utils = require("../utils");
15
- var _enUS = _interopRequireDefault(require("../../i18n/en-US.yml"));
16
- var _styled = require("../styled");
17
- // Load the default messages.
18
-
19
- // HACK: We should flatten the messages loaded above because
20
- // the YAML loaders behave differently between webpack and our version of jest:
21
- // - the yaml loader for webpack returns a nested object,
22
- // - the yaml loader for jest returns messages with flattened ids.
23
- const defaultMessages = (0, _flat.flatten)(_enUS.default);
24
- const TableHeader = _styledComponents.default.thead.withConfig({
25
- displayName: "fare-table__TableHeader",
26
- componentId: "sc-1ntg4ma-0"
27
- })(["th{font-weight:normal;min-width:5ch;padding:0.75em 1.5em;text-align:center;}th:nth-of-type(2n + 1){background:#cccccc22;}th.main{background:#333333;color:#ffffffcc;}"]);
28
- const Table = _styledComponents.default.table.withConfig({
29
- displayName: "fare-table__Table",
30
- componentId: "sc-1ntg4ma-1"
31
- })(["border-collapse:collapse;display:block;margin-bottom:16px;padding:0;td{text-align:right;}td:nth-of-type(2n + 1){background:#cccccc22;}td.no-zebra{background:none;}th:first-of-type{height:40px;}"]);
32
- const TransferIcon = (0, _styledComponents.default)(_Transfer.Transfer).withConfig({
33
- displayName: "fare-table__TransferIcon",
34
- componentId: "sc-1ntg4ma-2"
35
- })(["padding-left:4px;"]);
36
- const useGetHeaderString = headerKey => {
37
- const intl = (0, _reactIntl.useIntl)();
38
- return intl.formatMessage({
39
- id: `otpUi.TripDetails.FareTable.${headerKey}`,
40
- description: `Fare leg table header for key ${headerKey}`,
41
- defaultMessage: _enUS.default[`otpUi.TripDetails.FareTable.${headerKey}`]
42
- });
43
- };
44
- const hasFareInfo = column => leg => (0, _itinerary.getLegCost)(leg, column.mediumId, column.riderCategoryId).price !== undefined;
45
- const FareTypeTable = ({
46
- cols,
47
- headerKey,
48
- legs
49
- }) => {
50
- const intl = (0, _reactIntl.useIntl)();
51
- const filteredLegs = legs.filter(leg => {
52
- var _leg$fareProducts;
53
- return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
54
- });
55
- const colsToRender = cols.filter(col => filteredLegs.some(hasFareInfo(col))).map(col => ({
56
- ...col,
57
- total: filteredLegs.every(hasFareInfo(col)) ? (0, _itinerary.getItineraryCost)(filteredLegs, col.mediumId, col.riderCategoryId) : undefined
58
- }));
59
- const headerString = useGetHeaderString(headerKey);
60
- if (colsToRender.length) {
61
- return /*#__PURE__*/_react.default.createElement(Table, null, /*#__PURE__*/_react.default.createElement(TableHeader, null, /*#__PURE__*/_react.default.createElement("th", {
62
- className: "main",
63
- scope: "col"
64
- }, (0, _utils.boldText)(headerString)), colsToRender.map(col => {
65
- var _fare$currency;
66
- const fare = col.total;
67
- return /*#__PURE__*/_react.default.createElement("th", {
68
- scope: "col",
69
- key: col.columnHeaderKey || `${col.mediumId}-${col.riderCategoryId}`
70
- }, (0, _utils.boldText)(useGetHeaderString(col.columnHeaderKey)), /*#__PURE__*/_react.default.createElement("br", null), (fare === null || fare === void 0 ? void 0 : fare.amount) !== undefined ? (0, _utils.renderFare)(fare === null || fare === void 0 || (_fare$currency = fare.currency) === null || _fare$currency === void 0 ? void 0 : _fare$currency.code, fare === null || fare === void 0 ? void 0 : fare.amount) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "-", /*#__PURE__*/_react.default.createElement(_styled.InvisibleA11yLabel, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
71
- id: "otpUi.TripDetails.missingFareTotal"
72
- }))));
73
- })), filteredLegs.map((leg, index) => /*#__PURE__*/_react.default.createElement("tr", {
74
- key: index
75
- }, /*#__PURE__*/_react.default.createElement("td", {
76
- className: "no-zebra"
77
- }, (0, _itinerary.getLegRouteName)(leg)), colsToRender.map(col => {
78
- var _price$currency, _price$currency2;
79
- const {
80
- price,
81
- transferAmount
82
- } = (0, _itinerary.getLegCost)(leg, col.mediumId, col.riderCategoryId);
83
- return /*#__PURE__*/_react.default.createElement("td", {
84
- key: col.columnHeaderKey,
85
- title: (transferAmount === null || transferAmount === void 0 ? void 0 : transferAmount.amount) > 0 && intl.formatMessage({
86
- defaultMessage: defaultMessages["otpUi.TripDetails.transferDiscountExplanation"],
87
- description: "Text explaining the transfer discount applied to this fare.",
88
- id: "otpUi.TripDetails.transferDiscountExplanation"
89
- }, {
90
- transferAmount: intl.formatNumber(transferAmount === null || transferAmount === void 0 ? void 0 : transferAmount.amount, {
91
- currency: price === null || price === void 0 || (_price$currency = price.currency) === null || _price$currency === void 0 ? void 0 : _price$currency.code,
92
- currencyDisplay: "narrowSymbol",
93
- style: "currency"
94
- })
95
- })
96
- }, (transferAmount === null || transferAmount === void 0 ? void 0 : transferAmount.amount) > 0 && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(TransferIcon, {
97
- size: 16
98
- }), " "), price ? (0, _utils.renderFare)(price === null || price === void 0 || (_price$currency2 = price.currency) === null || _price$currency2 === void 0 ? void 0 : _price$currency2.code, price === null || price === void 0 ? void 0 : price.amount) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "-", /*#__PURE__*/_react.default.createElement(_styled.InvisibleA11yLabel, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
99
- id: "otpUi.TripDetails.legMissingFareInfo"
100
- }))));
101
- }))));
102
- }
103
- return null;
104
- };
105
- const FareLegTable = ({
106
- layout,
107
- legs
108
- }) => {
109
- // the layout argument contains an object for every table to be displayed
110
- return /*#__PURE__*/_react.default.createElement("div", null, layout.map(config => /*#__PURE__*/_react.default.createElement(FareTypeTable, {
111
- cols: config.cols,
112
- headerKey: config.headerKey,
113
- key: config.headerKey,
114
- legs: legs
115
- })));
116
- };
117
- var _default = exports.default = FareLegTable;
118
- //# sourceMappingURL=fare-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fare-table.js","names":["_react","_interopRequireDefault","require","_styledComponents","_Transfer","_itinerary","_reactIntl","_flat","_utils","_enUS","_styled","defaultMessages","flatten","defaultEnglishMessages","TableHeader","styled","thead","withConfig","displayName","componentId","Table","table","TransferIcon","Transfer","useGetHeaderString","headerKey","intl","useIntl","formatMessage","id","description","defaultMessage","hasFareInfo","column","leg","getLegCost","mediumId","riderCategoryId","price","undefined","FareTypeTable","cols","legs","filteredLegs","filter","_leg$fareProducts","fareProducts","length","colsToRender","col","some","map","total","every","getItineraryCost","headerString","default","createElement","className","scope","boldText","_fare$currency","fare","key","columnHeaderKey","amount","renderFare","currency","code","Fragment","InvisibleA11yLabel","FormattedMessage","index","getLegRouteName","_price$currency","_price$currency2","transferAmount","title","formatNumber","currencyDisplay","style","size","FareLegTable","layout","config","_default","exports"],"sources":["../../src/components/fare-table.tsx"],"sourcesContent":["import { FareProductSelector, Leg } from \"@opentripplanner/types\";\nimport React from \"react\";\nimport styled from \"styled-components\";\nimport { Transfer } from \"@styled-icons/boxicons-regular/Transfer\";\n\nimport {\n getItineraryCost,\n getLegCost,\n getLegRouteName\n} from \"@opentripplanner/core-utils/lib/itinerary\";\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { flatten } from \"flat\";\nimport { boldText, renderFare } from \"../utils\";\n\nimport { FareLegTableProps, FareTableLayout } from \"../types\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../../i18n/en-US.yml\";\nimport { InvisibleA11yLabel } from \"../styled\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);\n\ninterface FareTypeTableProps extends FareTableLayout {\n legs: Leg[];\n}\n\nconst TableHeader = styled.thead`\n th {\n font-weight: normal;\n min-width: 5ch;\n padding: 0.75em 1.5em;\n text-align: center;\n }\n th:nth-of-type(2n + 1) {\n background: #cccccc22;\n }\n th.main {\n background: #333333;\n color: #ffffffcc;\n }\n`;\n\nconst Table = styled.table`\n border-collapse: collapse;\n display: block;\n margin-bottom: 16px;\n padding: 0;\n\n td {\n text-align: right;\n }\n td:nth-of-type(2n + 1) {\n background: #cccccc22;\n }\n td.no-zebra {\n background: none;\n }\n th:first-of-type {\n height: 40px;\n }\n`;\n\nconst TransferIcon = styled(Transfer)`\n padding-left: 4px;\n`;\n\nconst useGetHeaderString = (headerKey: string): string => {\n const intl = useIntl();\n return intl.formatMessage({\n id: `otpUi.TripDetails.FareTable.${headerKey}`,\n description: `Fare leg table header for key ${headerKey}`,\n defaultMessage:\n defaultEnglishMessages[`otpUi.TripDetails.FareTable.${headerKey}`]\n });\n};\n\nconst hasFareInfo = (column: FareProductSelector) => (leg: Leg) =>\n getLegCost(leg, column.mediumId, column.riderCategoryId).price !== undefined;\n\nconst FareTypeTable = ({\n cols,\n headerKey,\n legs\n}: FareTypeTableProps): JSX.Element => {\n const intl = useIntl();\n\n const filteredLegs = legs.filter(leg => leg.fareProducts?.length > 0);\n const colsToRender = cols\n .filter(col => filteredLegs.some(hasFareInfo(col)))\n .map(col => ({\n ...col,\n total: filteredLegs.every(hasFareInfo(col))\n ? getItineraryCost(filteredLegs, col.mediumId, col.riderCategoryId)\n : undefined\n }));\n\n const headerString = useGetHeaderString(headerKey);\n\n if (colsToRender.length) {\n return (\n <Table>\n <TableHeader>\n <th className=\"main\" scope=\"col\">\n {boldText(headerString)}\n </th>\n {colsToRender.map(col => {\n const fare = col.total;\n return (\n <th\n scope=\"col\"\n key={\n col.columnHeaderKey ||\n `${col.mediumId}-${col.riderCategoryId}`\n }\n >\n {boldText(useGetHeaderString(col.columnHeaderKey))}\n <br />\n {fare?.amount !== undefined ? (\n renderFare(fare?.currency?.code, fare?.amount)\n ) : (\n <>\n -\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.missingFareTotal\" />\n </InvisibleA11yLabel>\n </>\n )}\n </th>\n );\n })}\n </TableHeader>\n {filteredLegs.map((leg, index) => (\n <tr key={index}>\n <td className=\"no-zebra\">{getLegRouteName(leg)}</td>\n {colsToRender.map(col => {\n const { price, transferAmount } = getLegCost(\n leg,\n col.mediumId,\n col.riderCategoryId\n );\n return (\n <td\n key={col.columnHeaderKey}\n title={\n transferAmount?.amount > 0 &&\n intl.formatMessage(\n {\n defaultMessage:\n defaultMessages[\n \"otpUi.TripDetails.transferDiscountExplanation\"\n ],\n description:\n \"Text explaining the transfer discount applied to this fare.\",\n id: \"otpUi.TripDetails.transferDiscountExplanation\"\n },\n {\n transferAmount: intl.formatNumber(\n transferAmount?.amount,\n {\n currency: price?.currency?.code,\n currencyDisplay: \"narrowSymbol\",\n style: \"currency\"\n }\n )\n }\n )\n }\n >\n {transferAmount?.amount > 0 && (\n <>\n <TransferIcon size={16} />{\" \"}\n </>\n )}\n {price ? (\n renderFare(price?.currency?.code, price?.amount)\n ) : (\n <>\n -\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.legMissingFareInfo\" />\n </InvisibleA11yLabel>\n </>\n )}\n </td>\n );\n })}\n </tr>\n ))}\n </Table>\n );\n }\n return null;\n};\n\nconst FareLegTable = ({ layout, legs }: FareLegTableProps): JSX.Element => {\n // the layout argument contains an object for every table to be displayed\n return (\n <div>\n {layout.map(config => (\n <FareTypeTable\n cols={config.cols}\n headerKey={config.headerKey}\n key={config.headerKey}\n legs={legs}\n />\n ))}\n </div>\n );\n};\n\nexport default FareLegTable;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AAKA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAKA,IAAAO,KAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAFA;;AAIA;AACA;AACA;AACA;AACA,MAAMS,eAAuC,GAAG,IAAAC,aAAO,EAACC,aAAsB,CAAC;AAM/E,MAAMC,WAAW,GAAGC,yBAAM,CAACC,KAAK,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,6KAc/B;AAED,MAAMC,KAAK,GAAGL,yBAAM,CAACM,KAAK,CAAAJ,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,yMAkBzB;AAED,MAAMG,YAAY,GAAG,IAAAP,yBAAM,EAACQ,kBAAQ,CAAC,CAAAN,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,yBAEpC;AAED,MAAMK,kBAAkB,GAAIC,SAAiB,IAAa;EACxD,MAAMC,IAAI,GAAG,IAAAC,kBAAO,EAAC,CAAC;EACtB,OAAOD,IAAI,CAACE,aAAa,CAAC;IACxBC,EAAE,EAAE,+BAA+BJ,SAAS,EAAE;IAC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J,IAAA4B,iBAAU,EAAC5B,KAAK,aAALA,KAAK,gBAAAqC,gBAAA,GAALrC,KAAK,CAAE6B,QAAQ,cAAAQ,gBAAA,uBAAfA,gBAAA,CAAiBP,IAAI,EAAE9B,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAE2B,MAAM,CAAC,gBAEhDjE,MAAA,CAAAwD,OAAA,CAAAC,aAAA,CAAAzD,MAAA,CAAAwD,OAAA,CAAAa,QAAA,QAAE,GAEA,eAAArE,MAAA,CAAAwD,OAAA,CAAAC,aAAA,CAAC/C,OAAA,CAAA4D,kBAAkB,qBACjBtE,MAAA,CAAAwD,OAAA,CAAAC,aAAA,CAACnD,UAAA,CAAAiE,gBAAgB;QAAC1C,EAAE,EAAC;MAAsC,CAAE,CAC3C,CACpB,CAEF,CAAC;IAET,CAAC,CACC,CACL,CACI,CAAC;EAEZ;EACA,OAAO,IAAI;AACb,CAAC;AAED,MAAMqD,YAAY,GAAGA,CAAC;EAAEC,MAAM;EAAEzC;AAAwB,CAAC,KAAkB;EACzE;EACA,oBACE1C,MAAA,CAAAwD,OAAA,CAAAC,aAAA,cACG0B,MAAM,CAAChC,GAAG,CAACiC,MAAM,iBAChBpF,MAAA,CAAAwD,OAAA,CAAAC,aAAA,CAACjB,aAAa;IACZC,IAAI,EAAE2C,MAAM,CAAC3C,IAAK;IAClBhB,SAAS,EAAE2D,MAAM,CAAC3D,SAAU;IAC5BsC,GAAG,EAAEqB,MAAM,CAAC3D,SAAU;IACtBiB,IAAI,EAAEA;EAAK,CACZ,CACF,CACE,CAAC;AAEV,CAAC;AAAC,IAAA2C,QAAA,GAAAC,OAAA,CAAA9B,OAAA,GAEa0B,YAAY","ignoreList":[]}
@@ -1,215 +0,0 @@
1
- import { FareProductSelector, Leg } from "@opentripplanner/types";
2
- import React from "react";
3
- import styled from "styled-components";
4
- import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
5
-
6
- import {
7
- getItineraryCost,
8
- getLegCost,
9
- getLegRouteName
10
- } from "@opentripplanner/core-utils/lib/itinerary";
11
- import { FormattedMessage, useIntl } from "react-intl";
12
- import { flatten } from "flat";
13
- import { boldText, renderFare } from "../utils";
14
-
15
- import { FareLegTableProps, FareTableLayout } from "../types";
16
-
17
- // Load the default messages.
18
- import defaultEnglishMessages from "../../i18n/en-US.yml";
19
- import { InvisibleA11yLabel } from "../styled";
20
-
21
- // HACK: We should flatten the messages loaded above because
22
- // the YAML loaders behave differently between webpack and our version of jest:
23
- // - the yaml loader for webpack returns a nested object,
24
- // - the yaml loader for jest returns messages with flattened ids.
25
- const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
26
-
27
- interface FareTypeTableProps extends FareTableLayout {
28
- legs: Leg[];
29
- }
30
-
31
- const TableHeader = styled.thead`
32
- th {
33
- font-weight: normal;
34
- min-width: 5ch;
35
- padding: 0.75em 1.5em;
36
- text-align: center;
37
- }
38
- th:nth-of-type(2n + 1) {
39
- background: #cccccc22;
40
- }
41
- th.main {
42
- background: #333333;
43
- color: #ffffffcc;
44
- }
45
- `;
46
-
47
- const Table = styled.table`
48
- border-collapse: collapse;
49
- display: block;
50
- margin-bottom: 16px;
51
- padding: 0;
52
-
53
- td {
54
- text-align: right;
55
- }
56
- td:nth-of-type(2n + 1) {
57
- background: #cccccc22;
58
- }
59
- td.no-zebra {
60
- background: none;
61
- }
62
- th:first-of-type {
63
- height: 40px;
64
- }
65
- `;
66
-
67
- const TransferIcon = styled(Transfer)`
68
- padding-left: 4px;
69
- `;
70
-
71
- const useGetHeaderString = (headerKey: string): string => {
72
- const intl = useIntl();
73
- return intl.formatMessage({
74
- id: `otpUi.TripDetails.FareTable.${headerKey}`,
75
- description: `Fare leg table header for key ${headerKey}`,
76
- defaultMessage:
77
- defaultEnglishMessages[`otpUi.TripDetails.FareTable.${headerKey}`]
78
- });
79
- };
80
-
81
- const hasFareInfo = (column: FareProductSelector) => (leg: Leg) =>
82
- getLegCost(leg, column.mediumId, column.riderCategoryId).price !== undefined;
83
-
84
- const FareTypeTable = ({
85
- cols,
86
- headerKey,
87
- legs
88
- }: FareTypeTableProps): JSX.Element => {
89
- const intl = useIntl();
90
-
91
- const filteredLegs = legs.filter(leg => leg.fareProducts?.length > 0);
92
- const colsToRender = cols
93
- .filter(col => filteredLegs.some(hasFareInfo(col)))
94
- .map(col => ({
95
- ...col,
96
- total: filteredLegs.every(hasFareInfo(col))
97
- ? getItineraryCost(filteredLegs, col.mediumId, col.riderCategoryId)
98
- : undefined
99
- }));
100
-
101
- const headerString = useGetHeaderString(headerKey);
102
-
103
- if (colsToRender.length) {
104
- return (
105
- <Table>
106
- <TableHeader>
107
- <th className="main" scope="col">
108
- {boldText(headerString)}
109
- </th>
110
- {colsToRender.map(col => {
111
- const fare = col.total;
112
- return (
113
- <th
114
- scope="col"
115
- key={
116
- col.columnHeaderKey ||
117
- `${col.mediumId}-${col.riderCategoryId}`
118
- }
119
- >
120
- {boldText(useGetHeaderString(col.columnHeaderKey))}
121
- <br />
122
- {fare?.amount !== undefined ? (
123
- renderFare(fare?.currency?.code, fare?.amount)
124
- ) : (
125
- <>
126
- -
127
- <InvisibleA11yLabel>
128
- <FormattedMessage id="otpUi.TripDetails.missingFareTotal" />
129
- </InvisibleA11yLabel>
130
- </>
131
- )}
132
- </th>
133
- );
134
- })}
135
- </TableHeader>
136
- {filteredLegs.map((leg, index) => (
137
- <tr key={index}>
138
- <td className="no-zebra">{getLegRouteName(leg)}</td>
139
- {colsToRender.map(col => {
140
- const { price, transferAmount } = getLegCost(
141
- leg,
142
- col.mediumId,
143
- col.riderCategoryId
144
- );
145
- return (
146
- <td
147
- key={col.columnHeaderKey}
148
- title={
149
- transferAmount?.amount > 0 &&
150
- intl.formatMessage(
151
- {
152
- defaultMessage:
153
- defaultMessages[
154
- "otpUi.TripDetails.transferDiscountExplanation"
155
- ],
156
- description:
157
- "Text explaining the transfer discount applied to this fare.",
158
- id: "otpUi.TripDetails.transferDiscountExplanation"
159
- },
160
- {
161
- transferAmount: intl.formatNumber(
162
- transferAmount?.amount,
163
- {
164
- currency: price?.currency?.code,
165
- currencyDisplay: "narrowSymbol",
166
- style: "currency"
167
- }
168
- )
169
- }
170
- )
171
- }
172
- >
173
- {transferAmount?.amount > 0 && (
174
- <>
175
- <TransferIcon size={16} />{" "}
176
- </>
177
- )}
178
- {price ? (
179
- renderFare(price?.currency?.code, price?.amount)
180
- ) : (
181
- <>
182
- -
183
- <InvisibleA11yLabel>
184
- <FormattedMessage id="otpUi.TripDetails.legMissingFareInfo" />
185
- </InvisibleA11yLabel>
186
- </>
187
- )}
188
- </td>
189
- );
190
- })}
191
- </tr>
192
- ))}
193
- </Table>
194
- );
195
- }
196
- return null;
197
- };
198
-
199
- const FareLegTable = ({ layout, legs }: FareLegTableProps): JSX.Element => {
200
- // the layout argument contains an object for every table to be displayed
201
- return (
202
- <div>
203
- {layout.map(config => (
204
- <FareTypeTable
205
- cols={config.cols}
206
- headerKey={config.headerKey}
207
- key={config.headerKey}
208
- legs={legs}
209
- />
210
- ))}
211
- </div>
212
- );
213
- };
214
-
215
- export default FareLegTable;