-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5146 from HSLdevcom/DT-6483
DT-6483: Refactor top card
- Loading branch information
Showing
13 changed files
with
475 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { legShape } from '../../util/shapes'; | ||
import Icon from '../Icon'; | ||
import { isRental } from '../../util/legUtils'; | ||
import NaviInstructions from './NaviInstructions'; | ||
import NaviCardExtension from './NaviCardExtension'; | ||
|
||
const iconMap = { | ||
BICYCLE: 'icon-icon_cyclist', | ||
CAR: 'icon-icon_car-withoutBox', | ||
SCOOTER: 'icon-icon_scooter_rider', | ||
WALK: 'icon-icon_walk', | ||
WAIT: 'icon-icon_navigation_wait', | ||
}; | ||
|
||
export default function NaviCard({ leg, nextLeg, legType, cardExpanded }) { | ||
const iconName = legType === 'wait' ? iconMap.WAIT : iconMap[leg.mode]; | ||
let instructions = `navileg-${leg.mode.toLowerCase()}`; | ||
|
||
if (isRental(leg, nextLeg)) { | ||
if (leg.mode === 'WALK' && nextLeg?.mode === 'SCOOTER') { | ||
instructions = `navileg-rent-scooter`; | ||
} else { | ||
instructions = `navileg-rent-cycle`; | ||
} | ||
} | ||
return ( | ||
<div className="navi-top-card"> | ||
<div className="main-card"> | ||
<Icon img={iconName} color="black" className="mode" /> | ||
<div className="instructions"> | ||
<NaviInstructions | ||
leg={leg} | ||
nextLeg={nextLeg} | ||
instructions={instructions} | ||
legType={legType} | ||
/> | ||
<div type="button" className="navitop-arrow"> | ||
<Icon | ||
img="icon-icon_arrow-collapse" | ||
className={`cursor-pointer ${cardExpanded ? 'inverted' : ''}`} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
{cardExpanded && <NaviCardExtension leg={leg} />} | ||
</div> | ||
); | ||
} | ||
|
||
NaviCard.propTypes = { | ||
leg: legShape.isRequired, | ||
nextLeg: legShape.isRequired, | ||
legType: PropTypes.string.isRequired, | ||
cardExpanded: PropTypes.bool, | ||
}; | ||
NaviCard.defaultProps = { | ||
cardExpanded: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import Icon from '../Icon'; | ||
import StopCode from '../StopCode'; | ||
import PlatformNumber from '../PlatformNumber'; | ||
import { getZoneLabel } from '../../util/legUtils'; | ||
import ZoneIcon from '../ZoneIcon'; | ||
import { legShape, configShape } from '../../util/shapes'; | ||
import { getDestinationProperties } from './NaviUtils'; | ||
|
||
const NaviCardExtension = ({ leg }, { config }) => { | ||
const { stop, name } = leg.to; | ||
const { code, platformCode, zoneId, vehicleMode } = stop || {}; | ||
const [place, address] = name?.split(/, (.+)/) || []; | ||
|
||
let destination = {}; | ||
if (stop) { | ||
destination = getDestinationProperties(leg, stop, config); | ||
destination.name = stop.name; | ||
} else { | ||
destination.iconId = 'icon-icon_mapMarker-to'; | ||
destination.className = 'place'; | ||
destination.name = place; | ||
} | ||
return ( | ||
<div className="secondary-info"> | ||
<div className="secondary-divider" /> | ||
<div className="secondary-content"> | ||
<Icon img="navi-expand" className="icon-expand" /> | ||
<Icon | ||
img={destination.iconId} | ||
height={2} | ||
width={2} | ||
className={`destination-icon ${destination.className}`} | ||
/> | ||
<div className="destination"> | ||
{destination.name} | ||
<div className="details"> | ||
{!stop && address && <div className="address">{address}</div>} | ||
{code && <StopCode code={code} />} | ||
{platformCode && ( | ||
<PlatformNumber | ||
number={platformCode} | ||
short | ||
isRailOrSubway={ | ||
vehicleMode === 'RAIL' || vehicleMode === 'SUBWAY' | ||
} | ||
/> | ||
)} | ||
<ZoneIcon | ||
zoneId={getZoneLabel(zoneId, config)} | ||
showUnknown={false} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
NaviCardExtension.propTypes = { | ||
leg: legShape.isRequired, | ||
}; | ||
|
||
NaviCardExtension.contextTypes = { | ||
config: configShape.isRequired, | ||
}; | ||
|
||
export default NaviCardExtension; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.