forked from HSLdevcom/digitransit-ui
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathEndLeg.js
95 lines (90 loc) · 3.17 KB
/
EndLeg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import PropTypes from 'prop-types';
import React from 'react';
import moment from 'moment-timezone';
import cx from 'classnames';
import { matchShape } from 'found';
import { FormattedMessage, intlShape } from 'react-intl';
import Icon from './Icon';
import { isKeyboardSelectionEvent } from '../util/browser';
import { parseLocation } from '../util/path';
/* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
function EndLeg(props, context) {
const parsedAddress = parseLocation(context.match.params.to).address;
const [address, place] = props.to.name.split(/, (.+)/) || []; // Splits the string to two parts from the first occurance of ', '
// Below check is needed for unit tests
const [addressFromUrl, placeFromUrl] = !parsedAddress
? [address, place]
: parsedAddress.split(/, (.+)/);
const { stop } = props?.to;
const modeClassName = 'end';
return (
<div key={props.index} className={cx('row', 'itinerary-row')}>
<span className="sr-only">
<FormattedMessage
id="itinerary-details.end-leg"
values={{
time: moment(props.endTime).format('HH:mm'),
destination: props.to.name,
}}
/>
</span>
<div className="small-2 columns itinerary-time-column" aria-hidden="true">
<div className="itinerary-time-column-time">
{moment(props.endTime).format('HH:mm')}
</div>
</div>
<div className={`leg-before ${modeClassName}`} aria-hidden="true">
<div className={`leg-before-circle circle ${modeClassName}`} />
<div className="itinerary-icon-container">
<Icon
img="icon-icon_mapMarker-to"
className="itinerary-icon to to-it"
/>
</div>
</div>
<div className="small-9 columns itinerary-instruction-column to end">
<span className="sr-only">
<FormattedMessage
id="itinerary-summary.show-on-map"
values={{ target: props.to.name || '' }}
/>
</span>
<div className="itinerary-leg-first-row">
<div className="address-container">
<div className="address">{!stop ? address : addressFromUrl}</div>
<div className="place">{place || placeFromUrl}</div>
</div>
<div
className="itinerary-map-action"
onClick={props.focusAction}
onKeyPress={e =>
isKeyboardSelectionEvent(e) && props.focusAction(e)
}
role="button"
tabIndex="0"
aria-label={context.intl.formatMessage(
{ id: 'itinerary-summary.show-on-map' },
{ target: props.to.name },
)}
>
<Icon
img="icon-icon_show-on-map"
className="itinerary-search-icon"
/>
</div>
</div>
</div>
</div>
);
}
EndLeg.propTypes = {
endTime: PropTypes.number.isRequired,
to: PropTypes.object.isRequired,
index: PropTypes.number.isRequired,
focusAction: PropTypes.func.isRequired,
};
EndLeg.contextTypes = {
intl: intlShape.isRequired,
match: matchShape.isRequired,
};
export default EndLeg;