1
- import React , { Component } from 'react '
1
+ import coreUtils from '@opentripplanner/core-utils '
2
2
import PropTypes from 'prop-types'
3
-
4
- import { calculateFares , calculatePhysicalActivity , getLegIcon , isTransit } from '../../../util/itinerary'
3
+ import React , { Component } from 'react'
4
+ import styled from 'styled-components'
5
+
6
+ import {
7
+ calculateFares ,
8
+ calculatePhysicalActivity ,
9
+ getLegIcon ,
10
+ isTransit
11
+ } from '../../../util/itinerary'
5
12
import { formatDuration , formatTime } from '../../../util/time'
6
13
7
14
// TODO: make this a prop
8
15
const defaultRouteColor = '#008'
9
16
17
+ const Container = styled . div `
18
+ display: ${ ( ) => coreUtils . ui . isMobile ( ) ? 'table' : 'none' } ;
19
+ height: 60px;
20
+ margin-bottom: 15px;
21
+ padding-right: 5px;
22
+ width: 100%;
23
+ `
24
+
25
+ const Detail = styled . div `
26
+ color: #999999;
27
+ font-size: 13px;
28
+ `
29
+
30
+ const Details = styled . div `
31
+ display: table-cell;
32
+ vertical-align: top;
33
+ `
34
+
35
+ const Header = styled . div `
36
+ font-size: 18px;
37
+ font-weight: bold;
38
+ margin-top: -3px;
39
+ `
40
+
41
+ const ModeIcon = styled . div `
42
+ height: 30px;
43
+ width: 30px;
44
+ `
45
+
46
+ const NonTransitSpacer = styled . div `
47
+ height: 30px;
48
+ overflow: hidden
49
+ `
50
+
51
+ const RoutePreivew = styled . div `
52
+ display: inline-block;
53
+ margin-left: 8px;
54
+ vertical-align: top;
55
+ `
56
+
57
+ const Routes = styled . div `
58
+ display: table-cell;
59
+ text-align: right;
60
+ `
61
+
62
+ const ShortName = styled . div `
63
+ background-color: ${ props => getRouteColorForBadge ( props . leg ) } ;
64
+ border-radius: 15px;
65
+ border: 2px solid white;
66
+ box-shadow: 0 0 0.5em #000;
67
+ color: white;
68
+ font-size: 15px;
69
+ font-weight: 500;
70
+ height: 30px;
71
+ margin-top: 6px;
72
+ overflow: hidden;
73
+ padding-top: 4px;
74
+ text-align: center;
75
+ text-overflow: ellipsis;
76
+ white-space: nowrap;
77
+ width: 30px;
78
+ `
79
+
10
80
export default class ItinerarySummary extends Component {
11
81
static propTypes = {
12
82
itinerary : PropTypes . object
@@ -31,52 +101,54 @@ export default class ItinerarySummary extends Component {
31
101
const { caloriesBurned } = calculatePhysicalActivity ( itinerary )
32
102
33
103
return (
34
- < div className = 'itin-summary' onClick = { this . _onSummaryClicked } >
35
- < div className = 'details' >
104
+ < Container onClick = { this . _onSummaryClicked } >
105
+ < Details >
36
106
{ /* Travel time in hrs/mins */ }
37
- < div className = 'header' > { formatDuration ( itinerary . duration ) } </ div >
107
+ < Header > { formatDuration ( itinerary . duration ) } </ Header >
38
108
39
109
{ /* Duration as time range */ }
40
- < div className = 'detail' >
110
+ < Detail >
41
111
{ formatTime ( itinerary . startTime , timeOptions ) } - { formatTime ( itinerary . endTime , timeOptions ) }
42
- </ div >
112
+ </ Detail >
43
113
44
114
{ /* Fare / Calories */ }
45
- < div className = 'detail' >
115
+ < Detail >
46
116
{ minTotalFare > 0 && < span >
47
117
{ centsToString ( minTotalFare ) }
48
118
{ minTotalFare !== maxTotalFare && < span > - { centsToString ( maxTotalFare ) } </ span > }
49
119
< span > • </ span >
50
120
</ span > }
51
121
{ Math . round ( caloriesBurned ) } Cals
52
- </ div >
122
+ </ Detail >
53
123
54
124
{ /* Number of transfers, if applicable */ }
55
125
{ itinerary . transfers > 0 && (
56
- < div className = 'detail' >
126
+ < Detail >
57
127
{ itinerary . transfers } transfer{ itinerary . transfers > 1 ? 's' : '' }
58
- </ div >
128
+ </ Detail >
59
129
) }
60
130
61
- </ div >
62
- < div className = 'routes' >
131
+ </ Details >
132
+ < Routes >
63
133
{ itinerary . legs . filter ( leg => {
64
134
return ! ( leg . mode === 'WALK' && itinerary . transitTime > 0 )
65
135
} ) . map ( ( leg , k ) => {
66
- return < div className = 'route-preview' key = { k } >
67
- < div className = 'mode-icon' > { getLegIcon ( leg , customIcons ) } </ div >
68
- { isTransit ( leg . mode )
69
- ? (
70
- < div className = 'short-name' style = { { backgroundColor : getRouteColorForBadge ( leg ) } } >
71
- { getRouteNameForBadge ( leg ) }
72
- </ div >
73
- )
74
- : ( < div style = { { height : 30 , overflow : 'hidden' } } /> )
75
- }
76
- </ div >
136
+ return (
137
+ < RoutePreivew key = { k } >
138
+ < ModeIcon > { getLegIcon ( leg , customIcons ) } </ ModeIcon >
139
+ { isTransit ( leg . mode )
140
+ ? (
141
+ < ShortName leg = { leg } >
142
+ { getRouteNameForBadge ( leg ) }
143
+ </ ShortName >
144
+ )
145
+ : ( < NonTransitSpacer /> )
146
+ }
147
+ </ RoutePreivew >
148
+ )
77
149
} ) }
78
- </ div >
79
- </ div >
150
+ </ Routes >
151
+ </ Container >
80
152
)
81
153
}
82
154
}
0 commit comments