Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5cf0d59
Merge branch 'dev' into otp-ui-icons + typo fix
binh-dam-ibigroup Apr 23, 2020
2d81d30
refactor(line-itin/itinerary.css): Remove unused file from before merge.
binh-dam-ibigroup Apr 23, 2020
16dcedf
fix(lib/index): Should not have removed LineItinerary from lib/index.
binh-dam-ibigroup Apr 24, 2020
f4526d9
Merge branch 'dev' into otp-ui-icons
binh-dam-ibigroup Apr 30, 2020
4aeb823
refactor(print-layout): Extract LegIcon (and ModeIcon) props to examp…
binh-dam-ibigroup Apr 30, 2020
e21ccfa
refactor(LineItinerary): Extract and propagate LegIcon prop from Line…
binh-dam-ibigroup Apr 30, 2020
f6f9d7c
refactor(line-itin): Extract LegIcon prop from line-itin/ItinerarySum…
binh-dam-ibigroup Apr 30, 2020
ac0d817
refactor(mobile): Extract and propagate LegIcon prop to MobileMain sc…
binh-dam-ibigroup Apr 30, 2020
8de95a1
refactor(default-itinerary): Extract LegIcon prop from DefaultItineary.
binh-dam-ibigroup Apr 30, 2020
7512b6e
refactor(SettingsSelectorPanel): Extract and propagate ModeIcon prop …
binh-dam-ibigroup Apr 30, 2020
9a70180
refactor: Remove old customIcons and icons props.
binh-dam-ibigroup Apr 30, 2020
685a484
docs(example.js): Add a note for testing.
binh-dam-ibigroup Apr 30, 2020
02fef27
refactor(ModeIcon prop): Make ModeIcon prop required.
binh-dam-ibigroup Apr 30, 2020
94982a1
fix(example): Fix syntax error
binh-dam-ibigroup May 1, 2020
2842fdc
style: Change style and add comment per PR feedback.
binh-dam-ibigroup May 1, 2020
9219719
refactor(package): Upgrade @opentripplanner packages. Update example.…
binh-dam-ibigroup May 11, 2020
ac4d6db
refactor(icons): move example custom icons into own file
landonreed May 12, 2020
4206465
docs(example): Remove a dummy custom icon example in favor for the ot…
binh-dam-ibigroup May 12, 2020
266ecb4
refactor(example): set useCustomIcons to false
landonreed May 12, 2020
538bf69
Merge branch 'otp-ui-icons' into otp-ui-icons-ltr
landonreed May 12, 2020
ca27560
Merge pull request #164 from opentripplanner/otp-ui-icons-ltr
binh-dam-ibigroup May 12, 2020
404f941
fix(css): Match date and mode selector styles to trimet-mod-otp
binh-dam-ibigroup May 15, 2020
5673af5
Merge branch 'otp-ui-icons' of https://github.com/opentripplanner/otp…
binh-dam-ibigroup May 15, 2020
bc67a45
fix(margins): Fix trip form margins
binh-dam-ibigroup May 15, 2020
e0373e8
style(results-screen): Reorder vars in render()
binh-dam-ibigroup May 15, 2020
6c10ea6
fix(css): Match trimet style for TripDetails, itinerary footer, Place…
binh-dam-ibigroup May 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions custom-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
ClassicBus,
ClassicGondola,
ClassicModeIcon,
Ferry,
LegIcon,
StandardGondola
} from '@opentripplanner/icons'

/**
* For more advanced users, you can replicate and customize components and
* observe the change in icons.
* - For LegIcon: https://github.com/opentripplanner/otp-ui/blob/master/packages/icons/src/trimet-leg-icon.js
* - For ModeIcon: https://github.com/opentripplanner/otp-ui/blob/master/packages/icons/src/trimet-mode-icon.js
* The example below shuffles some icons around from what you might normally
* expect for demonstration purposes.
*/

const CustomTransitIcon = Ferry
const CustomRailIcon = ClassicGondola
const CustomStreetcarIcon = StandardGondola
const CustomBikeRentalIcon = ClassicBus

export const CustomModeIcon = ({ mode, ...props }) => {
if (!mode) return null
switch (mode.toLowerCase()) {
// Place custom icons for each mode here.
case 'transit':
return <CustomTransitIcon {...props} />
case 'rail':
return <CustomRailIcon {...props} />
default:
return <ClassicModeIcon mode={mode} {...props} />
}
}

export const CustomLegIcon = ({ leg, ...props }) => {
if (
leg.routeLongName &&
leg.routeLongName.startsWith('MAX')
) {
return <CustomStreetcarIcon />
} else if (leg.rentedBike) {
return <CustomBikeRentalIcon />
}
return <LegIcon leg={leg} ModeIcon={CustomModeIcon} {...props} />
}
27 changes: 23 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// import this polyfill in order to make webapp compatible with IE 11
import 'es6-math'

import {ClassicLegIcon, ClassicModeIcon} from '@opentripplanner/icons'
import { createHashHistory } from 'history'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import React, { Component } from 'react'
Expand All @@ -9,7 +10,6 @@ import { createStore, combineReducers, applyMiddleware, compose } from 'redux'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import createLogger from 'redux-logger'

// import Bootstrap Grid components for layout
import { Navbar, Grid, Row, Col } from 'react-bootstrap'

Expand All @@ -22,10 +22,23 @@ import {
AppMenu,
createOtpReducer
} from './lib'

// load the OTP configuration
import otpConfig from './config.yml'

// Set useCustomIcons to true to override classic icons with the exports from
// custom-icons.js
const useCustomIcons = false

// Define icon sets for modes.
let MyLegIcon = ClassicLegIcon
let MyModeIcon = ClassicModeIcon

if (useCustomIcons) {
const CustomIcons = require('./custom-icons')
MyLegIcon = CustomIcons.CustomLegIcon
MyModeIcon = CustomIcons.CustomModeIcon
}

// create an initial query for demo/testing purposes
const initialQuery = {
from: {
Expand Down Expand Up @@ -78,7 +91,7 @@ class OtpRRExample extends Component {
<Grid>
<Row className='main-row'>
<Col sm={6} md={4} className='sidebar'>
<DefaultMainPanel />
<DefaultMainPanel LegIcon={MyLegIcon} ModeIcon={MyModeIcon} />
</Col>
<Col sm={6} md={8} className='map-container'>
<Map />
Expand All @@ -90,14 +103,20 @@ class OtpRRExample extends Component {

/** mobile view **/
const mobileView = (
<MobileMain map={(<Map />)} title={(<div className='navbar-title'>OpenTripPlanner</div>)} />
<MobileMain
LegIcon={MyLegIcon}
ModeIcon={MyModeIcon}
map={<Map />}
title={<div className='navbar-title'>OpenTripPlanner</div>}
/>
)

/** the main webapp **/
return (
<ResponsiveWebapp
desktopView={desktopView}
mobileView={mobileView}
LegIcon={MyLegIcon}
/>
)
}
Expand Down
8 changes: 5 additions & 3 deletions lib/components/app/default-main-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class DefaultMainPanel extends Component {
const {
activeSearch,
currentQuery,
customIcons,
itineraryClass,
itineraryFooter,
LegIcon,
mainPanelContent,
ModeIcon,
showUserSettings
} = this.props
const showPlanTripButton = mainPanelContent === 'EDIT_DATETIME' ||
Expand All @@ -35,15 +36,16 @@ class DefaultMainPanel extends Component {
paddingBottom: 15,
overflow: 'auto'
}}>
<DefaultSearchForm icons={customIcons} />
<DefaultSearchForm ModeIcon={ModeIcon} />
{!activeSearch && !showPlanTripButton && showUserSettings &&
<UserSettings />
}
<div className='desktop-narrative-container'>
<NarrativeRoutingResults
itineraryClass={itineraryClass}
itineraryFooter={itineraryFooter}
customIcons={customIcons} />
LegIcon={LegIcon}
/>
</div>
</div>
{showPlanTripButton &&
Expand Down
22 changes: 3 additions & 19 deletions lib/components/app/print-layout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TriMetLegIcon } from '@opentripplanner/icons'
import PrintableItinerary from '@opentripplanner/printable-itinerary'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
Expand All @@ -14,6 +13,7 @@ import { getActiveItinerary } from '../../util/state'
class PrintLayout extends Component {
static propTypes = {
itinerary: PropTypes.object,
LegIcon: PropTypes.elementType.isRequired,
parseQueryString: PropTypes.func
}

Expand Down Expand Up @@ -52,24 +52,8 @@ class PrintLayout extends Component {
root.removeAttribute('class')
}

/**
* Use one of the customIcons if provided,
* (similar to @opentriplanner/trip-form/ModeIcon)
* otherwise, fall back on TriMetLegIcon.
* TODO: Combine all custom icon rendering in one place.
*/
customLegIcon = icons => {
return function ({leg, props}) {
// Check if there is a custom icon (exact match required).
if (icons && leg.mode in icons) {
return icons[leg.mode]
}
return TriMetLegIcon({leg, props})
}
}

render () {
const { config, customIcons, itinerary } = this.props
const { config, itinerary, LegIcon } = this.props
return (
<div className='otp print-layout'>
{/* The header bar, including the Toggle Map and Print buttons */}
Expand Down Expand Up @@ -99,7 +83,7 @@ class PrintLayout extends Component {
<PrintableItinerary
config={config}
itinerary={itinerary}
LegIcon={this.customLegIcon(customIcons)}
LegIcon={LegIcon}
/>
<TripDetails itinerary={itinerary} />
</>
Expand Down
7 changes: 3 additions & 4 deletions lib/components/form/connected-settings-selector-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import UserTripSettings from './user-trip-settings'

class ConnectedSettingsSelectorPanel extends Component {
static propTypes = {
icons: PropTypes.object
ModeIcon: PropTypes.elementType.isRequired
}

render () {
const {
config,
icons,
ModeIcon,
query,
setQueryParam,
showUserSettings
Expand All @@ -30,8 +30,7 @@ class ConnectedSettingsSelectorPanel extends Component {
{showUserSettings && <UserTripSettings />}

<StyledSettingsSelectorPanel
className='settings-selector-panel'
icons={icons}
ModeIcon={ModeIcon}
queryParams={query}
supportedModes={config.modes}
supportedCompanies={config.companies}
Expand Down
10 changes: 4 additions & 6 deletions lib/components/form/default-search-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import React, { Component } from 'react'
import LocationField from './connected-location-field'
import TabbedFormPanel from './tabbed-form-panel'
import SwitchButton from './switch-button'
import defaultIcons from '../icons'

export default class DefaultSearchForm extends Component {
static propTypes = {
icons: PropTypes.object,
mobile: PropTypes.bool
mobile: PropTypes.bool,
ModeIcon: PropTypes.elementType.isRequired
}

static defaultProps = {
icons: defaultIcons,
showFrom: true,
showTo: true
}
Expand All @@ -27,7 +25,7 @@ export default class DefaultSearchForm extends Component {
}

render () {
const { icons, mobile } = this.props
const { mobile, ModeIcon } = this.props
const actionText = mobile ? 'tap' : 'click'

return (
Expand All @@ -50,7 +48,7 @@ export default class DefaultSearchForm extends Component {
</div>
</div>

<TabbedFormPanel icons={icons} />
<TabbedFormPanel ModeIcon={ModeIcon} />
</div>
)
}
Expand Down
1 change: 0 additions & 1 deletion lib/components/form/settings-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SettingsPreview extends Component {
caret: PropTypes.string,
compressed: PropTypes.bool,
editButtonText: PropTypes.element,
icons: PropTypes.object,
showCaret: PropTypes.bool,
onClick: PropTypes.func,

Expand Down
Loading