@opentripplanner/trip-details 2.1.0-alpha.2 → 2.1.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.
- package/__mocks__/{custom-messages.yml → custom-english-messages.yml} +7 -0
- package/__mocks__/custom-french-messages.yml +10 -0
- package/esm/fare-table.js +153 -0
- package/esm/fare-table.js.map +1 -0
- package/esm/index.js +23 -43
- package/esm/index.js.map +1 -1
- package/esm/types.js +11 -0
- package/esm/types.js.map +1 -1
- package/esm/utils.js +29 -0
- package/esm/utils.js.map +1 -0
- package/i18n/en-US.yml +7 -0
- package/i18n/fr.yml +7 -0
- package/lib/fare-table.d.ts +4 -0
- package/lib/fare-table.d.ts.map +1 -0
- package/lib/fare-table.js +160 -0
- package/lib/fare-table.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +30 -50
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +24 -11
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +18 -0
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +13 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +41 -0
- package/lib/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/TripDetails.story.tsx +54 -38
- package/src/fare-table.tsx +222 -0
- package/src/index.tsx +35 -61
- package/src/types.ts +25 -11
- package/src/utils.tsx +30 -0
- package/tsconfig.tsbuildinfo +58 -68
- package/esm/fare-detail.js +0 -111
- package/esm/fare-detail.js.map +0 -1
- package/lib/fare-detail.d.ts +0 -3
- package/lib/fare-detail.d.ts.map +0 -1
- package/lib/fare-detail.js +0 -115
- package/lib/fare-detail.js.map +0 -1
- package/src/fare-detail.tsx +0 -154
package/src/fare-detail.tsx
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import { Leg, Money } from "@opentripplanner/types";
|
|
3
|
-
|
|
4
|
-
import React from "react";
|
|
5
|
-
import styled from "styled-components";
|
|
6
|
-
import { FormattedNumber } from "react-intl";
|
|
7
|
-
import { FareDetailsProps } from "./types";
|
|
8
|
-
|
|
9
|
-
interface FareTypeTableProps {
|
|
10
|
-
header: string;
|
|
11
|
-
cols: {
|
|
12
|
-
key: string;
|
|
13
|
-
header: string;
|
|
14
|
-
}[];
|
|
15
|
-
legs: (Leg & { fares: { [key: string]: { price: Money } } })[];
|
|
16
|
-
fareTotals: { [fareKey: string]: Money };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const TableHeader = styled.thead`
|
|
20
|
-
th {
|
|
21
|
-
min-width: 5ch;
|
|
22
|
-
padding: 0.75em 1.5em;
|
|
23
|
-
text-align: center;
|
|
24
|
-
}
|
|
25
|
-
th:nth-of-type(2n + 1) {
|
|
26
|
-
background: #cccccc22;
|
|
27
|
-
}
|
|
28
|
-
th.main {
|
|
29
|
-
color: #ffffffcc;
|
|
30
|
-
background: #333333;
|
|
31
|
-
}
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
const TotalRow = styled.tr`
|
|
35
|
-
border-top: 2px solid #333;
|
|
36
|
-
font-weight: 600;
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
const Table = styled.table`
|
|
40
|
-
border-collapse: collapse;
|
|
41
|
-
display: block;
|
|
42
|
-
font-family: sans-serif;
|
|
43
|
-
margin: -8px;
|
|
44
|
-
/* This line can not be sorted alphabetically, because it must come after the margin rule */
|
|
45
|
-
margin-bottom: 16px;
|
|
46
|
-
padding: 0;
|
|
47
|
-
|
|
48
|
-
td {
|
|
49
|
-
text-align: right;
|
|
50
|
-
}
|
|
51
|
-
td:nth-of-type(2n + 1) {
|
|
52
|
-
background: #cccccc22;
|
|
53
|
-
}
|
|
54
|
-
td.no-zebra {
|
|
55
|
-
background: transparent;
|
|
56
|
-
}
|
|
57
|
-
th:first-of-type {
|
|
58
|
-
height: 40px;
|
|
59
|
-
}
|
|
60
|
-
`;
|
|
61
|
-
|
|
62
|
-
const FareTypeTable = (props: FareTypeTableProps): JSX.Element => {
|
|
63
|
-
const { header, fareTotals, cols, legs } = props;
|
|
64
|
-
return (
|
|
65
|
-
<Table>
|
|
66
|
-
<TableHeader>
|
|
67
|
-
<th className="main">{header}</th>
|
|
68
|
-
{cols.map(col => (
|
|
69
|
-
<th key={col.header}>{col.header}</th>
|
|
70
|
-
))}
|
|
71
|
-
</TableHeader>
|
|
72
|
-
{legs.map((leg, index) => (
|
|
73
|
-
<tr key={index}>
|
|
74
|
-
<td className="no-zebra">{leg.routeShortName}</td>
|
|
75
|
-
{cols.map(col => {
|
|
76
|
-
const fare = leg.fares[col.key];
|
|
77
|
-
return (
|
|
78
|
-
<td key={col.key}>
|
|
79
|
-
<FormattedNumber
|
|
80
|
-
value={fare?.price?.cents / 100 || 0}
|
|
81
|
-
// This isn't a "real" style prop
|
|
82
|
-
// eslint-disable-next-line react/style-prop-object
|
|
83
|
-
style="currency"
|
|
84
|
-
currency={
|
|
85
|
-
fare?.price.currency.currencyCode ||
|
|
86
|
-
// This is how the itinerary-wide currency code is calculated on the back-end
|
|
87
|
-
legs?.[0].fares?.[col.key]?.price?.currency.currencyCode
|
|
88
|
-
}
|
|
89
|
-
currencyDisplay="narrowSymbol"
|
|
90
|
-
/>
|
|
91
|
-
</td>
|
|
92
|
-
);
|
|
93
|
-
})}
|
|
94
|
-
</tr>
|
|
95
|
-
))}
|
|
96
|
-
<TotalRow>
|
|
97
|
-
<td className="no-zebra">Total</td>
|
|
98
|
-
{cols.map(col => {
|
|
99
|
-
const fare = fareTotals[col.key];
|
|
100
|
-
return (
|
|
101
|
-
<td key={col.key}>
|
|
102
|
-
<FormattedNumber
|
|
103
|
-
value={(fare?.cents || 0) / 100}
|
|
104
|
-
// This isn't a "real" style prop
|
|
105
|
-
// eslint-disable-next-line react/style-prop-object
|
|
106
|
-
style="currency"
|
|
107
|
-
currency={fare?.currency?.currencyCode}
|
|
108
|
-
currencyDisplay="narrowSymbol"
|
|
109
|
-
/>
|
|
110
|
-
</td>
|
|
111
|
-
);
|
|
112
|
-
})}
|
|
113
|
-
</TotalRow>
|
|
114
|
-
</Table>
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
119
|
-
export const FareDetails = (props: FareDetailsProps): JSX.Element => {
|
|
120
|
-
const { legs, transitFares, layout } = props;
|
|
121
|
-
const fareKeys = Object.keys(transitFares.details);
|
|
122
|
-
|
|
123
|
-
const legsWithFares = legs
|
|
124
|
-
.map((leg, index) => {
|
|
125
|
-
const fares = fareKeys.reduce((prev, key) => {
|
|
126
|
-
const fareForKey = transitFares.details[key]?.find(
|
|
127
|
-
detail => detail.legIndex === index
|
|
128
|
-
);
|
|
129
|
-
if (fareForKey) {
|
|
130
|
-
prev[key] = fareForKey;
|
|
131
|
-
}
|
|
132
|
-
return prev;
|
|
133
|
-
}, {});
|
|
134
|
-
return {
|
|
135
|
-
...leg,
|
|
136
|
-
fares
|
|
137
|
-
};
|
|
138
|
-
})
|
|
139
|
-
.filter(leg => leg.transitLeg);
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<div>
|
|
143
|
-
{layout.map(config => (
|
|
144
|
-
<FareTypeTable
|
|
145
|
-
header={config.header}
|
|
146
|
-
cols={config.cols}
|
|
147
|
-
key={config.header}
|
|
148
|
-
legs={legsWithFares}
|
|
149
|
-
fareTotals={transitFares.fare}
|
|
150
|
-
/>
|
|
151
|
-
))}
|
|
152
|
-
</div>
|
|
153
|
-
);
|
|
154
|
-
};
|