Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add formatting options to weather widgets #3093

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/widgets/info/openmeteo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 2 additions & 0 deletions docs/widgets/info/openweathermap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 2 additions & 0 deletions docs/widgets/info/weather.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
1 change: 1 addition & 0 deletions src/components/widgets/openmeteo/openmeteo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function Widget({ options }) {
value: data.current_weather.temperature,
style: "unit",
unit,
...options.format,
})}
</PrimaryText>
<SecondaryText>{t(`wmo.${data.current_weather.weathercode}-${timeOfDay}`)}</SecondaryText>
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/openweathermap/weather.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Widget({ options }) {
<Container options={options} additionalClassNames="information-widget-openweathermap">
<PrimaryText>
{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 })}
</PrimaryText>
<SecondaryText>{data.weather[0].description}</SecondaryText>
<WidgetIcon icon={mapIcon(condition, timeOfDay)} size="xl" />
Expand Down
1 change: 1 addition & 0 deletions src/components/widgets/weather/weather.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function Widget({ options }) {
value: options.units === "metric" ? data.current.temp_c : data.current.temp_f,
style: "unit",
unit,
...options.format,
})}
</PrimaryText>
<SecondaryText>{data.current.condition.text}</SecondaryText>
Expand Down