digitransit-ui/app/component/WeatherDetailsPopup.js
2021-01-27 15:16:47 +02:00

62 lines
2 KiB
JavaScript

import PropTypes from 'prop-types';
import React from 'react';
import moment from 'moment';
import Modal from '@hsl-fi/modal';
import { FormattedMessage, intlShape } from 'react-intl';
import Icon from './Icon';
function WeatherDetailsPopup({ weatherData, onClose }, { intl }) {
// DT-4274: Icons for night time is represented adding a 100 to an id. For example:
// iconId 1 (clear sky) for a day is 101 for a night. Subtract this so we don't need duplicate translations.
const weatherIdForDescription =
weatherData.iconId > 100 ? weatherData.iconId - 100 : weatherData.iconId;
return (
<Modal
appElement="#app"
contentLabel=""
closeButtonLabel={intl.formatMessage({ id: 'close' })}
isOpen
onCrossClick={onClose}
variant="small"
className="weather-details-modal"
overlayClassName="weather-modal-overlay"
>
<div className="weather-details-content">
<h3 className="weather-title">
<FormattedMessage id="weather-detail-title" />
{` ${moment(weatherData.time).format('HH:mm')}`}
</h3>
<div className="weather-icon-row">
<Icon img={`icon-icon_weather_${weatherData.iconId}`} />
<span className="weather-temperature">
{`${Math.round(weatherData.temperature) > 1 ? '+' : ''}${Math.round(
weatherData.temperature,
)}\u00B0C`}
</span>
</div>
<p className="weather-description">
<FormattedMessage id={`weather-icon-${weatherIdForDescription}`} />
</p>
<div className="weather-data-source">
<FormattedMessage id="weather-data-source" />
</div>
</div>
</Modal>
);
}
WeatherDetailsPopup.propTypes = {
weatherData: PropTypes.shape({
temperature: PropTypes.number,
iconId: PropTypes.number,
time: PropTypes.number,
}).isRequired,
onClose: PropTypes.func.isRequired,
};
WeatherDetailsPopup.contextTypes = {
intl: intlShape.isRequired,
};
export default WeatherDetailsPopup;