Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Weather

ProNew

A 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

pnpm dlx shadcn@latest add @viewport/weather

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

<Weather>

PropTypeDefault
location*string

City or place name.

—
currentWeatherNow—
hourlyWeatherHour[][]
dailyWeatherDay[][]
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`.

—
unitToggleboolean

A °C / °F switch in the header.

true
animatedboolean

Animate the icons. They always hold still under reduced motion.

true
updatedstring

A short line in the header, such as "Updated 5 min ago".

—
loadingboolean—
errorstring

An error message in place of the forecast, with a retry button when `onRetry` is set.

—
onRetry() => void—
classNamestring—

<WeatherIcon>

PropTypeDefault
condition*WeatherCondition—
nightboolean—
sizenumber

Pixels.

"md"
animatedbooleantrue
labelstring

Read by screen readers; leave it out when the condition is written next to the icon.

—
classNamestring—

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.