Skip to content

Commit 7a07ce7

Browse files
feat(DateTimeSelector): Merge branch 'otp-ui-datetimeselector' into otp-ui-trip-settings
2 parents 7a67327 + ffd28d8 commit 7a07ce7

File tree

4 files changed

+705
-297
lines changed

4 files changed

+705
-297
lines changed

lib/components/form/date-time-modal.js

Lines changed: 97 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,130 @@
22
import React, { Component } from 'react'
33
import PropTypes from 'prop-types'
44
import { connect } from 'react-redux'
5-
import { Button, ButtonGroup } from 'react-bootstrap'
5+
import styled from 'styled-components'
6+
import { getTimeFormat, getDateFormat } from '@opentripplanner/core-utils/lib/time'
7+
import { DateTimeSelector } from '@opentripplanner/trip-form'
8+
import * as TripFormClasses from '@opentripplanner/trip-form/lib/styled'
69

7-
import DateTimeSelector from './date-time-selector'
810
import { setQueryParam } from '../../actions/form'
911

10-
// Define default routingType labels and components
11-
const rtDefaults = [
12-
{
13-
key: 'ITINERARY',
14-
text: 'Itinerary',
15-
component: <DateTimeSelector />
16-
}, {
17-
key: 'PROFILE',
18-
text: 'Profile',
19-
component: <DateTimeSelector profile />
12+
// Styles for the DateTimeSelector.
13+
// TODO: Find a way to bring OTP CSS classes in here.
14+
// See for instance:
15+
// https://github.com/theKashey/styled-components-mixins
16+
// https://github.com/kingpowerclick/styled-bootstrap-mixins
17+
18+
const StyledDateTimeSelector = styled(DateTimeSelector)`
19+
margin: 0 -15px 20px;
20+
${TripFormClasses.DateTimeSelector.DateTimeRow} {
21+
margin-top: 20px;
22+
}
23+
24+
input {
25+
-webkit-appearance: textfield;
26+
-moz-appearance: textfield;
27+
appearance: textfield;
28+
background-color: #fff;
29+
background-image: none;
30+
border: 1px solid #ccc;
31+
border-radius: 4px;
32+
box-shadow: none;
33+
color: #555;
34+
font-family: inherit;
35+
font-size: 16px;
36+
height: 34px;
37+
padding: 6px 12px;
38+
text-align: center;
39+
&.focused {
40+
outline: 0;
41+
border-color: #66afe9;
42+
font-weight: 400;
43+
box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
44+
}
2045
}
21-
]
46+
47+
button {
48+
-webkit-user-select: none;
49+
-moz-user-select: none;
50+
-ms-user-select: none;
51+
background-color: #fff;
52+
border: 1px solid #ccc;
53+
border-radius: 4px;
54+
color: #333;
55+
cursor: pointer;
56+
font-family: inherit;
57+
font-weight: 400;
58+
font-size: 14px;
59+
line-height: 1.42857143;
60+
outline-offset:-2px;
61+
padding: 6px 12px;
62+
text-align: center;
63+
touch-action: manipulation;
64+
user-select: none;
65+
white-space: nowrap;
66+
67+
&.active {
68+
background-color: #e6e6e6;
69+
border-color: #adadad;
70+
box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
71+
font-weight: 400;
72+
}
73+
&:hover {
74+
background-color: #e6e6e6;
75+
border-color: #adadad;
76+
}
77+
&.active {
78+
background-color: #e6e6e6;
79+
border-color: #adadad;
80+
box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
81+
font-weight: 400;
82+
&:hover {
83+
background-color: #d4d4d4;
84+
border-color: #8c8c8c;
85+
}
86+
}
87+
}
88+
`
2289

2390
class DateTimeModal extends Component {
2491
static propTypes = {
25-
routingType: PropTypes.string,
2692
setQueryParam: PropTypes.func
2793
}
2894

2995
render () {
30-
const { config, routingType, setQueryParam } = this.props
96+
const { date, dateFormatLegacy, departArrive, setQueryParam, time, timeFormatLegacy } = this.props
3197

3298
return (
3399
<div className='date-time-modal'>
34-
{/* The routing-type selection button row. Only show if more than one configured */}
35-
{config.routingTypes.length > 1 && (
36-
<div className='button-row'>
37-
<ButtonGroup justified>
38-
{config.routingTypes.map(rtConfig => {
39-
return (
40-
<ButtonGroup key={rtConfig.key}>
41-
<Button
42-
className={rtConfig.key === routingType ? 'selected' : ''}
43-
onClick={() => {
44-
setQueryParam({ routingType: rtConfig.key })
45-
}}
46-
>
47-
{rtConfig.text || rtDefaults.find(d => d.key === rtConfig.key).text}
48-
</Button>
49-
</ButtonGroup>
50-
)
51-
})}
52-
</ButtonGroup>
53-
</div>
54-
)}
55-
56-
{/* The main panel for the selected routing type */}
57100
<div className='main-panel'>
58-
{rtDefaults.find(d => d.key === routingType).component}
101+
<StyledDateTimeSelector
102+
className='date-time-selector'
103+
date={date}
104+
dateFormatLegacy={dateFormatLegacy}
105+
departArrive={departArrive}
106+
onQueryParamChange={setQueryParam}
107+
time={time}
108+
timeFormatLegacy={timeFormatLegacy}
109+
/>
59110
</div>
60111
</div>
61112
)
62113
}
63114
}
64115

65116
const mapStateToProps = (state, ownProps) => {
66-
const {departArrive, date, time, routingType} = state.otp.currentQuery
117+
const { departArrive, date, time } = state.otp.currentQuery
67118
return {
68119
config: state.otp.config,
69120
departArrive,
70121
date,
71122
time,
72-
routingType
123+
// These props below are for Safari on MacOS, and old browsers
124+
// that don't support `<input type="time|date">`.
125+
// In modern browsers, `<input type="time|date">` already
126+
// formats the time|date according to the OS settings.
127+
timeFormatLegacy: getTimeFormat(state.otp.config),
128+
dateFormatLegacy: getDateFormat(state.otp.config)
73129
}
74130
}
75131

0 commit comments

Comments
 (0)