-
Notifications
You must be signed in to change notification settings - Fork 135
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 #4881 from HSLdevcom/DT-5325
DT-5904 (DT-5325) CO2 emissions
- Loading branch information
Showing
28 changed files
with
585 additions
and
11 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,86 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import Icon from './Icon'; | ||
import ItineraryShape from '../prop-types/ItineraryShape'; | ||
import { getCo2Value } from '../util/itineraryUtils'; | ||
|
||
const Emissions = ({ itinerary, carItinerary, emissionsInfolink }) => { | ||
const co2value = getCo2Value(itinerary); | ||
const itineraryIsCar = itinerary.legs.every( | ||
leg => leg.mode === 'CAR' || leg.mode === 'WALK', | ||
); | ||
const carCo2Value = | ||
!itineraryIsCar && carItinerary | ||
? Math.round(carItinerary?.emissionsPerPerson?.co2) | ||
: null; | ||
const useCo2SimpleDesc = !carCo2Value || itineraryIsCar; | ||
const co2DescriptionId = useCo2SimpleDesc | ||
? 'itinerary-co2.description-simple' | ||
: 'itinerary-co2.description'; | ||
|
||
return ( | ||
co2value !== null && | ||
co2value >= 0 && ( | ||
<div className="itinerary-co2-comparison"> | ||
<div className="itinerary-co2-line"> | ||
<div className={cx('divider-top')} /> | ||
<div className="co2-container"> | ||
<div className="co2-description-container"> | ||
<Icon img="icon-icon_co2_leaf" className="co2-leaf" /> | ||
<span | ||
className={cx('itinerary-co2-description', { | ||
simple: useCo2SimpleDesc, | ||
})} | ||
> | ||
<span aria-hidden="true"> | ||
<FormattedMessage | ||
id={co2DescriptionId} | ||
defaultMessage={`CO₂ emissions for this route: ${co2value} g`} | ||
values={{ | ||
co2value, | ||
carCo2Value, | ||
}} | ||
/> | ||
</span> | ||
<span className="sr-only"> | ||
<FormattedMessage | ||
id={`${co2DescriptionId}-sr`} | ||
defaultMessage={`Carbondioxide emissions for this route: ${co2value} g`} | ||
values={{ | ||
co2value, | ||
carCo2Value, | ||
}} | ||
/> | ||
</span> | ||
{emissionsInfolink && ( | ||
<a | ||
className="emissions-info-link" | ||
href={`${emissionsInfolink}`} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
<FormattedMessage | ||
id="itinerary-co2.link" | ||
defaultMessage="Näin vähennämme päästöjä ›" | ||
/> | ||
</a> | ||
)} | ||
</span> | ||
</div> | ||
</div> | ||
<div className={cx('divider-bottom')} /> | ||
</div> | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
Emissions.propTypes = { | ||
itinerary: ItineraryShape.isRequired, | ||
carItinerary: ItineraryShape.isRequired, | ||
emissionsInfolink: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default Emissions; |
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,51 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import Icon from './Icon'; | ||
import ItineraryShape from '../prop-types/ItineraryShape'; | ||
import { getCo2Value } from '../util/itineraryUtils'; | ||
|
||
const EmissionsInfo = ({ itinerary, isMobile }) => { | ||
const co2value = getCo2Value(itinerary); | ||
return ( | ||
co2value !== null && | ||
co2value >= 0 && ( | ||
<div | ||
className={cx('itinerary-co2-information', { | ||
mobile: isMobile, | ||
})} | ||
> | ||
<div className="itinerary-co2-line"> | ||
<div className={cx('co2-container', { mobile: isMobile })}> | ||
<div className="co2-title-container"> | ||
<Icon img="icon-icon_co2_leaf" className="co2-leaf" /> | ||
<span aria-hidden="true" className="itinerary-co2-title"> | ||
<FormattedMessage | ||
id="itinerary-co2.title" | ||
defaultMessage="CO2 emissions for this route" | ||
/> | ||
</span> | ||
<span className="sr-only"> | ||
<FormattedMessage | ||
id="itinerary-co2.title-sr" | ||
defaultMessage="CO2 emissions for this route" | ||
/> | ||
</span> | ||
</div> | ||
<div className="itinerary-co2-value-container"> | ||
<div className="itinerary-co2-value">{co2value} g</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
EmissionsInfo.propTypes = { | ||
itinerary: ItineraryShape.isRequired, | ||
isMobile: PropTypes.bool.isRequired, | ||
}; | ||
|
||
export default EmissionsInfo; |
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
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
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.