Proper RTL support in weather forecast card (#2424)

* Proper RTL support in weather forecast card

* States panel force left to right since RTL is not usable

* Updated class names and switched div to span
This commit is contained in:
yosilevy 2019-01-09 22:34:24 +02:00 committed by Bram Kragten
parent 64b405dd4d
commit 2517e5ba60
2 changed files with 58 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import "../components/ha-icon";
import EventsMixin from "../mixins/events-mixin"; import EventsMixin from "../mixins/events-mixin";
import LocalizeMixin from "../mixins/localize-mixin"; import LocalizeMixin from "../mixins/localize-mixin";
import { computeRTL } from "../common/util/compute_rtl";
/* /*
* @appliesMixin LocalizeMixin * @appliesMixin LocalizeMixin
@ -52,6 +53,11 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
color: var(--secondary-text-color); color: var(--secondary-text-color);
} }
:host([rtl]) .name {
margin-left: 0px;
margin-right: 16px;
}
.now { .now {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -65,18 +71,31 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
margin-right: 32px; margin-right: 32px;
} }
:host([rtl]) .main {
margin-right: 0px;
}
.main ha-icon { .main ha-icon {
--iron-icon-height: 72px; --iron-icon-height: 72px;
--iron-icon-width: 72px; --iron-icon-width: 72px;
margin-right: 8px; margin-right: 8px;
} }
:host([rtl]) .main ha-icon {
margin-right: 0px;
}
.main .temp { .main .temp {
font-size: 52px; font-size: 52px;
line-height: 1em; line-height: 1em;
position: relative; position: relative;
} }
:host([rtl]) .main .temp {
direction: ltr;
margin-right: 28px;
}
.main .temp span { .main .temp span {
font-size: 24px; font-size: 24px;
line-height: 1em; line-height: 1em;
@ -84,6 +103,14 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
top: 4px; top: 4px;
} }
.measurand {
display: inline-block;
}
:host([rtl]) .measurand {
direction: ltr;
}
.forecast { .forecast {
margin-top: 16px; margin-top: 16px;
display: flex; display: flex;
@ -100,6 +127,10 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
text-align: center; text-align: center;
} }
:host([rtl]) .forecast .temp {
direction: ltr;
}
.weekday { .weekday {
font-weight: bold; font-weight: bold;
} }
@ -134,7 +165,9 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
> >
<div> <div>
[[localize('ui.card.weather.attributes.air_pressure')]]: [[localize('ui.card.weather.attributes.air_pressure')]]:
<span class="measurand">
[[stateObj.attributes.pressure]] [[getUnit('air_pressure')]] [[stateObj.attributes.pressure]] [[getUnit('air_pressure')]]
</span>
</div> </div>
</template> </template>
<template <template
@ -143,7 +176,9 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
> >
<div> <div>
[[localize('ui.card.weather.attributes.humidity')]]: [[localize('ui.card.weather.attributes.humidity')]]:
[[stateObj.attributes.humidity]] % <span class="measurand"
>[[stateObj.attributes.humidity]] %</span
>
</div> </div>
</template> </template>
<template <template
@ -152,8 +187,10 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
> >
<div> <div>
[[localize('ui.card.weather.attributes.wind_speed')]]: [[localize('ui.card.weather.attributes.wind_speed')]]:
[[getWind(stateObj.attributes.wind_speed, <span class="measurand">
stateObj.attributes.wind_bearing, localize)]] [[getWindSpeed(stateObj.attributes.wind_speed)]]
</span>
[[getWindBearing(stateObj.attributes.wind_bearing, localize)]]
</div> </div>
</template> </template>
</div> </div>
@ -206,6 +243,11 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
type: Array, type: Array,
computed: "computeForecast(stateObj.attributes.forecast)", computed: "computeForecast(stateObj.attributes.forecast)",
}, },
rtl: {
type: Boolean,
reflectToAttribute: true,
computed: "_computeRTL(hass)",
},
}; };
} }
@ -299,14 +341,18 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
return degree; return degree;
} }
getWind(speed, bearing, localize) { getWindSpeed(speed) {
return `${speed} ${this.getUnit("length")}/h`;
}
getWindBearing(bearing, localize) {
if (bearing != null) { if (bearing != null) {
const cardinalDirection = this.windBearingToText(bearing); const cardinalDirection = this.windBearingToText(bearing);
return `${speed} ${this.getUnit("length")}/h (${localize( return `(${localize(
`ui.card.weather.cardinal_direction.${cardinalDirection.toLowerCase()}` `ui.card.weather.cardinal_direction.${cardinalDirection.toLowerCase()}`
) || cardinalDirection})`; ) || cardinalDirection})`;
} }
return `${speed} ${this.getUnit("length")}/h`; return ``;
} }
_showValue(item) { _showValue(item) {
@ -328,5 +374,9 @@ class HaWeatherCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
{ hour: "numeric" } { hour: "numeric" }
); );
} }
_computeRTL(hass) {
return computeRTL(hass);
}
} }
customElements.define("ha-weather-card", HaWeatherCard); customElements.define("ha-weather-card", HaWeatherCard);

View File

@ -28,6 +28,7 @@ class HaPanelDevState extends EventsMixin(PolymerElement) {
.content { .content {
padding: 16px; padding: 16px;
direction: ltr;
} }
ha-entity-picker, ha-entity-picker,