From b5258c5200f3ef7f57646e08264fb4c9510abd00 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Sun, 10 Mar 2024 08:52:57 +0200 Subject: [PATCH] Enhancement: Add formatting options to weather widgets (#3093) --- docs/widgets/info/openmeteo.md | 2 ++ docs/widgets/info/openweathermap.md | 2 ++ docs/widgets/info/weather.md | 2 ++ src/components/widgets/openmeteo/openmeteo.jsx | 1 + src/components/widgets/openweathermap/weather.jsx | 2 +- src/components/widgets/weather/weather.jsx | 1 + 6 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/widgets/info/openmeteo.md b/docs/widgets/info/openmeteo.md index 4cc49e269..fb5bb1717 100644 --- a/docs/widgets/info/openmeteo.md +++ b/docs/widgets/info/openmeteo.md @@ -13,6 +13,8 @@ No registration is required at all! See [https://open-meteo.com/en/docs](https:/ timezone: Europe/Kiev # optional units: metric # or imperial cache: 5 # Time in minutes to cache API responses, to stay within limits + format: # optional, Intl.NumberFormat options + maximumFractionDigits: 1 ``` You can optionally not pass a `latitude` and `longitude` and the widget will use your current location (requires a secure context, eg. HTTPS). diff --git a/docs/widgets/info/openweathermap.md b/docs/widgets/info/openweathermap.md index 04733f5dd..320d5d859 100644 --- a/docs/widgets/info/openweathermap.md +++ b/docs/widgets/info/openweathermap.md @@ -14,6 +14,8 @@ The free tier "One Call API" is all that's required, you will need to [subscribe provider: openweathermap apiKey: youropenweathermapkey # required only if not using provider, this reveals api key in requests cache: 5 # Time in minutes to cache API responses, to stay within limits + format: # optional, Intl.NumberFormat options + maximumFractionDigits: 1 ``` You can optionally not pass a `latitude` and `longitude` and the widget will use your current location (requires a secure context, eg. HTTPS). diff --git a/docs/widgets/info/weather.md b/docs/widgets/info/weather.md index 6357f0c05..ab13b6736 100644 --- a/docs/widgets/info/weather.md +++ b/docs/widgets/info/weather.md @@ -15,6 +15,8 @@ The free tier is all that's required, you will need to [register](https://www.we units: metric # or imperial apiKey: yourweatherapikey cache: 5 # Time in minutes to cache API responses, to stay within limits + format: # optional, Intl.NumberFormat options + maximumFractionDigits: 1 ``` You can optionally not pass a `latitude` and `longitude` and the widget will use your current location (requires a secure context, eg. HTTPS). diff --git a/src/components/widgets/openmeteo/openmeteo.jsx b/src/components/widgets/openmeteo/openmeteo.jsx index 8baddfa5d..4c47fc4ab 100644 --- a/src/components/widgets/openmeteo/openmeteo.jsx +++ b/src/components/widgets/openmeteo/openmeteo.jsx @@ -46,6 +46,7 @@ function Widget({ options }) { value: data.current_weather.temperature, style: "unit", unit, + ...options.format, })} {t(`wmo.${data.current_weather.weathercode}-${timeOfDay}`)} diff --git a/src/components/widgets/openweathermap/weather.jsx b/src/components/widgets/openweathermap/weather.jsx index 7b442990c..df0280e3e 100644 --- a/src/components/widgets/openweathermap/weather.jsx +++ b/src/components/widgets/openweathermap/weather.jsx @@ -42,7 +42,7 @@ function Widget({ options }) { {options.label && `${options.label}, `} - {t("common.number", { value: data.main.temp, style: "unit", unit })} + {t("common.number", { value: data.main.temp, style: "unit", unit, ...options.format })} {data.weather[0].description} diff --git a/src/components/widgets/weather/weather.jsx b/src/components/widgets/weather/weather.jsx index 08074ee5f..4ebb08c53 100644 --- a/src/components/widgets/weather/weather.jsx +++ b/src/components/widgets/weather/weather.jsx @@ -45,6 +45,7 @@ function Widget({ options }) { value: options.units === "metric" ? data.current.temp_c : data.current.temp_f, style: "unit", unit, + ...options.format, })} {data.current.condition.text}