Layout
Weather card
Frosted glass card where the weather shows on the glass, rain drops, fog, frost, heat or wind, behind your content.
Example
CrWeather is a frosted glass card: the blur lets the colours behind it through, and the weather is drawn on the glass, behind the content. The content is yours (city, temperature, details): it stays in the page, readable and clickable. condition picks the weather; changing it cross-fades from one effect to the next.
<CrWeather condition="rain">
<h3>Lyon</h3>
<p>14°</p>
<p>Light rain</p>
</CrWeather>Lyon
Thursday, November 12
14°
Light rain
- Humidity
- 82%
- Wind
- 12 km/h
'use client';
import type { CSSProperties } from 'react';
import { useState } from 'react';
import { CrBackground, CrBox, CrSegmented, CrWeather } from '@cristal-ui/react';
const conditions = [
['rain', 'Light rain'],
['storm', 'Heavy rain'],
['fog', 'Fog'],
['frost', 'Frost'],
['heat', 'Heat'],
['clear', 'Clear'],
['wind', 'Wind'],
] as const;
// A vivid backdrop, like a blurred photo behind the card: colours picked by hand, in both themes.
const backdrop = {
'--cr-background-base': '#6d28d9',
'--cr-background-color-1': '#fb923c',
'--cr-background-color-2': '#ec4899',
'--cr-background-color-3': '#22d3ee',
display: 'grid',
placeItems: 'center',
padding: '48px 16px',
borderRadius: 'var(--cr-radius-l)',
} as CSSProperties;
const detail = { margin: 0, fontWeight: 600 };
export default function WeatherCard() {
const [index, setIndex] = useState(0);
const [condition, label] = conditions[index];
return (
<CrBox display="flex" direction="column" gap="lg" align="stretch">
<CrSegmented label="Weather" value={String(index)} onCrChange={(event) => setIndex(Number(event.detail))}>
{conditions.map(([value, text], position) => (
<option key={value} value={position}>
{text}
</option>
))}
</CrSegmented>
<CrBackground variant="aurora" style={backdrop}>
<CrWeather condition={condition} style={{ width: 'min(100%, 320px)', padding: '24px 24px 52px' }}>
<h3 style={{ margin: 0, fontSize: 20 }}>Lyon</h3>
<p style={{ margin: '2px 0 0' }}>Thursday, November 12</p>
<p style={{ margin: '16px 0 0', fontSize: 64, lineHeight: 1, fontWeight: 300 }}>14°</p>
<p style={{ margin: '4px 0 20px', fontSize: 18 }}>{label}</p>
<dl style={{ display: 'flex', gap: 32, margin: 0 }}>
<div>
<dt>Humidity</dt>
<dd style={detail}>82%</dd>
</div>
<div>
<dt>Wind</dt>
<dd style={detail}>12 km/h</dd>
</div>
</dl>
</CrWeather>
</CrBackground>
</CrBox>
);
}condition | On the glass |
|---|---|
clear | a soft sun in the corner, its flares, a glint slowly sweeping the glass and a few sparkles (default) |
rain | drops land, grow as they merge, then run down leaving a trail and small droplets |
storm | heavy rain: many more drops, fast rain streaks, drops streaming down; no lightning |
fog | condensation drifting on the glass; the pointer wipes it like a finger on a misted window, and it slowly comes back |
frost | ice crystals grow in from the edges and corners, then stay with a faint sparkle |
heat | a warm glow rising from the bottom, and the glass highlights shimmering as in scorching air |
wind | fine streaks of air, specks and a few leaves blown across in gusts |
The card takes the size of its content: set padding, width or border-radius as on a div. Leave a little room at the bottom right for the pause button. Put it on a colourful backdrop (a photo, an animated background): that is what gives the glass its colour.
Colours
The glass and the weather follow the theme, light or dark. To change them, set these CSS properties on the card or a parent:
| CSS property | Default |
|---|---|
--cr-weather-glass | the surface, at 58% opacity in the light theme, 70% in the dark one |
--cr-weather-tint | white in the light theme, light grey at 28% opacity in the dark one: highlights, fog, frost, wind streaks |
--cr-weather-warm | amber, darker in the dark theme: sun, heat, leaves |
cr-weather {
--cr-weather-glass: rgb(255 255 255 / 0.7);
--cr-weather-tint: #e0f2fe;
}Behind the glass, the backdrop is blurred, its contrast narrowed, then lightened in the light theme and darkened in the dark one: this is what lets the glass stay translucent while keeping the text readable whatever the backdrop. If you make the glass more transparent or the weather brighter, check the contrast.
Pause and reduced motion
An animation that starts on its own and lasts more than 5 seconds must be stoppable: a small pause button is shown in the bottom right corner, as on the animated background. The weather also stops on its own when the card leaves the screen or the tab is hidden, and starts again when it comes back, unless it is paused.
If your application already has its own control to stop animations, hide the button with controls={false} and drive the pause with paused:
<CrWeather condition="frost" controls={false} paused={!animations}>
…
</CrWeather>If the user asked their system to reduce motion, the card starts paused on a still frame that is already set: drops on the glass, frost grown, fog on the glass. The button still lets them start the animation.
Accessibility
- The weather is decorative: its layer is hidden from screen readers (
aria-hidden) and holds nothing focusable. Say the weather in the content ("Light rain"): that is what carries the information. - Text in
--cr-color-textkeeps a contrast of at least 4.5:1 on every frame, for every condition, in the light and dark themes: the glass is opaque enough and the weather subtle enough. Keep the card text in--cr-color-text;--cr-color-text-mutedis not guaranteed on the glass. - No lightning with
storm: nothing flashes. - Wiping the fog with the pointer is decoration: no information depends on it, nothing happens with the keyboard.
- The pause button is a real button, named "Pause the animation" ("Mettre en pause l'animation" in French), announced as pressed when the animation is stopped.
- In forced colours mode, the weather and its button disappear; the glass becomes a panel in the system colours, with a border.
- Paused, off screen or in a hidden tab, the card computes nothing.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
condition | "clear" | "fog" | "frost" | "heat" | "rain" | "storm" | "wind" | 'clear' | Temps sur le verre : clear (dégagé, reflets de soleil, par défaut), rain (pluie fine, gouttes qui perlent et coulent), storm (forte pluie), fog (buée que le pointeur essuie), frost (givre qui pousse depuis les bords), heat (chaleur qui monte et fait onduler les reflets) ou wind (vent, filets d'air et feuilles). Un changement passe d'un effet à l'autre en fondu. |
controls | boolean | true | Affiche le bouton pause dans le coin. À false seulement si l'application a sa propre commande pour arrêter les animations. |
paused | boolean | false | Met l'animation en pause ; le bouton pause l'inverse. Passe à true au chargement si l'utilisateur a demandé à réduire les animations. |
Slots
| Slot | Description |
|---|---|
| default | Le contenu de la carte. |
CSS parts
To style it from outside: cr-weather::part(name) { … }
| Part | Description |
|---|---|
layer | La couche de l'effet, décorative. |
toggle | Le bouton pause. |