Weather
ProNewA forecast card with an animated icon for the current conditions, an hourly strip and a multi-day outlook, in five layouts, three sizes and six themes. The forecast comes from props.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
<Weather>
| Prop | Type | Default |
|---|---|---|
| location* | stringCity or place name. | — |
| current | WeatherNow | — |
| hourly | WeatherHour[] | [] |
| daily | WeatherDay[] | [] |
| layout | "detailed" | "daily" | "hourly" | "current" | "compact"`detailed` shows everything, `daily` and `hourly` one forecast each, `current` only now, and `compact` is a one-line pill. | "detailed" |
| theme | "auto" | "light" | "dark" | "sky" | "sunny" | "blue"`auto` follows the page theme; `sky` paints the weather itself. | "auto" |
| size | "sm" | "md" | "lg" | "md" |
| unit | "c" | "f"The unit your numbers are in. | "c" |
| defaultDisplayUnit | "c" | "f"The unit shown first. Defaults to `unit`. | — |
| unitToggle | booleanA °C / °F switch in the header. | true |
| animated | booleanAnimate the icons. They always hold still under reduced motion. | true |
| updated | stringA short line in the header, such as "Updated 5 min ago". | — |
| loading | boolean | — |
| error | stringAn error message in place of the forecast, with a retry button when `onRetry` is set. | — |
| onRetry | () => void | — |
| className | string | — |
<WeatherIcon>
| Prop | Type | Default |
|---|---|---|
| condition* | WeatherCondition | — |
| night | boolean | — |
| size | numberPixels. | "md" |
| animated | boolean | true |
| label | stringRead by screen readers; leave it out when the condition is written next to the icon. | — |
| className | string | — |
Accessibility
- Conditions are always written out; icons beside text are hidden from screen readers, and lone icons carry a name.
- Highs, lows and rain chances are labelled for screen readers instead of relying on position or color.
- The °C / °F switch is two toggle buttons, and the hourly strip is a focusable region that scrolls with the arrow keys.
- Sun, clouds, rain, snow and lightning hold still under reduced motion.