Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

card-list

Template-based list rendering with safe data binding. Fetch or inline JSON, bind to templates, and lay out the cards with the global data-layout system.

Overview

The <card-list> component renders a list of items from JSON data using an HTML <template>. Data binding uses data-field attributes — only safe property paths are allowed, no expressions or method calls.

Supply data inline via data-items, fetch from a URL via src, or assign the .items property. Lay the cards out with the global data-layout system (grid, stack, reel, …) — data-layout-gap and data-layout-min work as on any other element.

Attributes

Attribute Type Default Description
src URL — URL to fetch JSON data from. Expects an array or an object with items or data property.
data-items JSON string — Inline JSON array of items. Takes priority over src.
data-key string id Property name to use as the unique key for each item. Items whose key is missing or duplicated fall back to their index, so keyless data still renders every item.
data-layout string — (block) Any global layout value, e.g. grid, stack, reel. Without it the list is display: block.

Binding Attributes

These go on elements inside the <template> to bind item data.

Attribute Description
data-field="path" Set the element's text content from a property path (e.g. user.name).
data-field-attr="href: url, title: name" Set one or more HTML attributes from property paths. Comma-separated pairs of attribute: path. A null/undefined value removes the attribute; true/false add/remove boolean attributes (aria-* get the literal string). Event handlers and unsafe URLs are refused — see Security.
data-field-html="path" Set innerHTML from a property path. Content is sanitized (scripts, iframes, and event handlers are stripped).
data-field-if="path" Element is shown only if the property value is truthy; otherwise it gets hidden.
data-field-unless="path" Element is shown only if the property value is falsy; otherwise it gets hidden.

Data Sources

Inline Data

Pass a JSON array directly in the data-items attribute. Good for small, static datasets.

Remote Data

Set src to fetch JSON from a URL. The URL is fetched once when the component upgrades (moving the element in the DOM does not re-fetch) and again whenever src changes; a newer request aborts the older one. The component shows a loading state while fetching and an error state on failure — see States.

The response can be a plain array, or an object with an items or data property containing the array.

Nested Properties

Access nested data with dot notation. Array indices are also supported: items[0].title.

Attribute Binding

Use data-field-attr to set HTML attributes from item properties. Comma-separated pairs map attributes to property paths. URL attributes only accept safe URLs, so a javascript: value in the data leaves the link without an href.

Conditional Rendering

Use data-field-if and data-field-unless to show or hide elements based on item data. The elements stay in the card and are toggled with the hidden attribute, so when an item's data changes (via .items or data-items) they come back.

Rich HTML Content

Use data-field-html to render HTML content from a property. Content is sanitized — <script>, <iframe>, <object>, <embed>, <form>, event handlers, and javascript: URIs are all stripped.

Layout

<card-list> has no layout modes of its own: it uses the global data-layout attribute like any other container, including its modifiers.

With data-layout="reel" the cards scroll horizontally (see <layout-reel>). When the cards hold no links or buttons, add role="region", an aria-label and tabindex="0" so keyboard users can scroll the strip and screen readers can name it.

States

While a src fetch is in flight the list has data-loading and aria-busy="true". Loading and error text is written into a <p role="status" data-card-list-status> child the component creates, so screen readers hear it; it is visually hidden while empty. The error banner uses the theme's --color-error-* tokens. data-error is cleared as soon as a new fetch starts. A failed fetch leaves any existing cards (or [data-fallback] content) in place.

Attribute When Visual
data-loading During src fetch Reduced opacity, aria-busy="true", "Loading…" status text.
data-error Fetch failure Error banner (status text) with the message, e.g. HTTP 404.

Events

Event Detail Description
card-list:rendered { count: number } Fired after items are rendered. Bubbles.
card-list:items-changed { items, source } Fired when the items change. source is 'attribute' (from data-items, src or data-key) or 'api' (the .items setter), so frameworks can ignore echoes of their own assignments. Bubbles.
card-list:upgraded — Fired once the component has found its template. Bubbles.

JavaScript API

Method / Property Description
.items Get the current items array, or assign a new array. Assignment runs a keyed diff: cards whose key persists are kept (focus and scroll survive) and re-bound with the new data. Assigning cancels an in-flight src fetch. Items assigned before the element is connected render on upgrade.

Security

All data-field paths are validated against a strict regex. Only simple property access is allowed:

  • Allowed: name, user.email, items[0].title
  • Rejected: price.toFixed(2), `${price}`, price * 1.1, stock > 0 ? 'yes' : 'no'

Invalid paths log a console warning and resolve to empty content.

data-field-html passes the value through the shared HTML sanitizer. data-field-attr is guarded too:

  • Event-handler attributes (on*), style and srcdoc are never written from data.
  • URL attributes (href, src, action, formaction, xlink:href, poster, cite, ping, data, srcset, …) only accept http:, https:, mailto:, tel:, relative URLs and fragments. Anything else (javascript:, data:, vbscript:, …) is refused with a console warning and the attribute is removed.

Progressive Enhancement

Without JavaScript, the <template> renders nothing. Put static content for no-JS readers in a child marked data-fallback: the component removes it on the first successful render (it stays if the fetch fails).

Related

↑