-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathtrip-duration-summary.tsx
39 lines (34 loc) · 1.31 KB
/
trip-duration-summary.tsx
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
import { FormattedMessage, FormattedTime } from 'react-intl'
import coreUtils from '@opentripplanner/core-utils'
import React from 'react'
import styled from 'styled-components'
import { MonitoredTripProps } from '../types'
import FormattedDuration from '../../util/formatted-duration'
import InvisibleA11yLabel from '../../util/invisible-a11y-label'
const Divider = styled.span`
margin: 0 7px;
`
const { ensureAtLeastOneMinute } = coreUtils.time
const TripSummary = ({ monitoredTrip }: MonitoredTripProps): JSX.Element => {
const { itinerary } = monitoredTrip
const { duration, endTime, startTime } = itinerary
return (
<span>
{/* Set up invisible "labels" for each itinerary field, and comma, so that the output of screen readers is more intelligible. */}
<InvisibleA11yLabel>
<FormattedMessage id="components.TripSummary.leaveAt" />
</InvisibleA11yLabel>
<FormattedTime value={startTime} />—
<InvisibleA11yLabel>
<FormattedMessage id="components.TripSummary.arriveAt" />
</InvisibleA11yLabel>
<FormattedTime value={endTime} />
<InvisibleA11yLabel>, </InvisibleA11yLabel>
<Divider>•</Divider>
<span aria-hidden>
<FormattedDuration duration={ensureAtLeastOneMinute(duration)} />
</span>
</span>
)
}
export default TripSummary