|
2 | 2 | import React, { Component } from 'react'
|
3 | 3 | import PropTypes from 'prop-types'
|
4 | 4 | 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' |
6 | 9 |
|
7 |
| -import DateTimeSelector from './date-time-selector' |
8 | 10 | import { setQueryParam } from '../../actions/form'
|
9 | 11 |
|
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 | + } |
20 | 45 | }
|
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 | +` |
22 | 89 |
|
23 | 90 | class DateTimeModal extends Component {
|
24 | 91 | static propTypes = {
|
25 |
| - routingType: PropTypes.string, |
26 | 92 | setQueryParam: PropTypes.func
|
27 | 93 | }
|
28 | 94 |
|
29 | 95 | render () {
|
30 |
| - const { config, routingType, setQueryParam } = this.props |
| 96 | + const { date, dateFormatLegacy, departArrive, setQueryParam, time, timeFormatLegacy } = this.props |
31 | 97 |
|
32 | 98 | return (
|
33 | 99 | <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 */} |
57 | 100 | <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 | + /> |
59 | 110 | </div>
|
60 | 111 | </div>
|
61 | 112 | )
|
62 | 113 | }
|
63 | 114 | }
|
64 | 115 |
|
65 | 116 | const mapStateToProps = (state, ownProps) => {
|
66 |
| - const {departArrive, date, time, routingType} = state.otp.currentQuery |
| 117 | + const { departArrive, date, time } = state.otp.currentQuery |
67 | 118 | return {
|
68 | 119 | config: state.otp.config,
|
69 | 120 | departArrive,
|
70 | 121 | date,
|
71 | 122 | 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) |
73 | 129 | }
|
74 | 130 | }
|
75 | 131 |
|
|
0 commit comments