Cómo funciona
The card's background is nine stacked gradient tints, one per condition; the chosen one fades in over the previous one, which stays opaque underneath. Over the tint is the sky. Its slow parts are CSS layers that only move by transform and fade by opacity: a sun glow, turning shafts of light and a passing sheen; fair-weather clouds in three depths (nearer ones larger, brighter and faster) and a low deck of wide clouds, each cloud a light and a dark tone; a darker band under a heavy sky; fog banks; spray. The condition sets each layer's opacity with a 900ms transition, so the sky changes without a cut. What falls is one canvas: drizzle is sparse, thin and slow, rain medium, heavy rain dense, long, fast and slanted with splashes; a thunderstorm adds a forked bolt and lights the cloud from inside; snow drifts. A still veil over the left column and the top line keeps every word at 4.5:1 or more on every sky, in both themes. The temperature is an odometer: only the digits that change roll, up when warmer and down when colder.
Úsalo para
- A weather widget for one place with a few days ahead.
- Any small card where a handful of tabs switch a big number and a mood, for example a daily summary.
Busca otra opción cuando
- Hour-by-hour detail or many days: use a list or a chart.
- Comparing several cities side by side: use a table.
Uso
import { useState } from 'react'
import { ForecastCard } from './ForecastCard.jsx'
const days = [
{ id: 'mon', label: 'Mon', condition: 'clear', temp: 24, high: 26, low: 17, conditionLabel: 'Clear skies' },
{ id: 'tue', label: 'Tue', condition: 'partly-cloudy', temp: 19, high: 21, low: 15 },
{ id: 'wed', label: 'Wed', condition: 'overcast', temp: 14, high: 16, low: 11 },
{ id: 'thu', label: 'Thu', condition: 'heavy-rain', temp: 9, high: 13, low: 7 },
{ id: 'fri', label: 'Fri', condition: 'thunderstorm', temp: 21, high: 23, low: 14 },
]
export function TownWeather() {
const [day, setDay] = useState('mon')
return <ForecastCard city="Port Elwin" days={days} value={day} onChange={setDay} unit="C" />
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
days | { id, label, condition: 'clear' | 'partly-cloudy' | 'overcast' | 'drizzle' | 'rain' | 'heavy-rain' | 'thunderstorm' | 'snow' | 'fog', temp, high, low, conditionLabel? }[] | — | The days shown as tabs. Temperatures are in Celsius; label is the short weekday in the tab; condition picks the sky (the older sunny, cloudy and storm still work as clear, partly-cloudy and thunderstorm); conditionLabel replaces the built-in name of the condition. |
city | string | — | The city name in the header; also the accessible name of the card. |
value / defaultValue / onChange | string / string / (id) => void | - / days[0].id / - | The chosen day id, controlled or uncontrolled. |
condition | 'clear' | 'partly-cloudy' | 'overcast' | 'drizzle' | 'rain' | 'heavy-rain' | 'thunderstorm' | 'snow' | 'fog' | - | Shows this sky, icon and condition name over whichever day is chosen, for example to preview a weather type; leave it out to follow each day's own condition. |
unit | 'C' | 'F' | 'C' | Shows temperatures in Celsius or converts them to Fahrenheit. Changing it rolls the digits too. |
ambient | boolean | true | Draws the sky behind the card on one canvas: a sun glow with slow light, drifting clouds, a low cloud deck, rain by intensity with splashes, lightning, snow or fog. Off shows the tint alone. |
labels | object | — | Replaces built-in text: tabs, degree(n, unit), high(t), low(t), temperature(t), conditions keyed by condition (clear, partly-cloudy, overcast, drizzle, rain, heavy-rain, thunderstorm, snow, fog), day(day, condition, temp). Shallow-merged over the English defaults. |
...rest | HTMLAttributes | — | Other attributes go to the root <section>. |
Accesibilidad
- The days are a tablist of tab buttons with aria-selected and a roving tabindex; the weather above is the tabpanel labelled by the chosen tab.
- Left and Right move to the previous or next day and wrap around; Home and End go to the first and last day; focus follows the selection.
- Each tab is named in full, for example “Wed, Light rain, 14°C”; the rolling digits are hidden from screen readers and a text copy reads “Temperature 14°C”.
- The tabs are 56px tall, and focus shows as a white ring that stays visible on every tint.
- Leaving digits, icons and lines are aria-hidden and do not take pointer events.
- The condition is always written out, never shown by colour alone.
- Reduced motion swaps the values at once, keeps a short fade on the tint and shows the sky as one still picture: clouds in place, rain and snow drawn but not falling, no lightning flash.
- Lightning is gentle: each strike is two soft pulses (rising over 70ms) at least six seconds after the last, so there are never more than two flashes in a second, and the brightest frame raises the card by a few points of luminance.
- The sky is aria-hidden; the condition is always written out.
Movimiento
Tint: opacity 700ms over the previous tint. Sky layers: opacity 900ms when the condition changes. Clouds cross the card in 84 to 190s (nearer ones faster), the deck in 104 to 170s, the light shafts turn once in 90s, the sheen passes every 12s, the glow and spray breathe over 7s and 3.6s, fog banks sway over 34 to 52s. Rain falls at about 380 to 910px a second depending on intensity, snow at 16 to 46px a second. Digits: each changed digit leaves in 380ms while the new one enters in 420ms with cubic-bezier(0.25, 1.12, 0.4, 1), staggered 55ms from the right, blurred from 4px to 0. Icon: out in 300ms, in in 440ms with a light spring. Lines: out in 140ms, in in 360ms ease-out, 100ms later. Pill: transform 420ms cubic-bezier(0.3, 1.25, 0.5, 1). Everything holds still while the card is off screen or its tab is hidden; the canvas runs only while something falls or flashes.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
ForecastCard.jsxforecast-card.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.







