Behive Tech Component Registry

Image Card

v0.1.2Draft

A card with an image on top and a title, subtitle and meta row below, for artwork lists, artist tiles and booking previews. It composes `atoms.card` with no padding, so fill, border and corners are Card's.

pnpm add @behivetech/molecules.image-card

A card with an image on top and a title, subtitle and meta row below, for artwork lists, artist tiles and booking previews. It composes atoms.card with no padding, so fill, border and corners are Card's.

Usage

Open in new tab

The ```jsx block above runs live on the docs site. Imports are stripped and every registry export is in scope, so you can compose with other components too.

Behaviour

  • With href, the whole card is one link named by the title. Pass linkComponent (for example next/link) for client-side routing. Keep meta non-interactive: the link covers the card. Without href the card is static, with no hover or focus stop.
  • The media box holds its aspectRatio (4/5, 1/1 or 3/2) before the image loads. Give the image its descriptive alt.
  • If an <img> in media fails to load, including before hydration, the box shows an image icon at the same ratio. The icon is labelled unavailableLabel ("Image unavailable") followed by the image's alt text. A new src on the image clears the failure.
  • The title clamps at two lines and the subtitle at one. In a grid row the card fills the row's height and meta sits on its bottom edge.
  • The hover glow reads --brand-glow-violet from @behivetech/cms.base-styles; it is transparent in Light. Glow is on the card, never on text.

Properties

ImageCard props

PropTypeDefaultDescription
media*ReactNode—The image, or any node that holds one (`next/image` with `fill` works). Give the image its descriptive `alt`. If an `<img>` inside fails to load, including before hydration, the media box swaps it for an image icon at the same aspect ratio, labelled with `unavailableLabel` and the alt text. A new `src` on the image clears the failure.
title*ReactNode—Card title, clamped at two lines. It names the link when `href` is set.
aspectRatio"4/5" | "1/1" | "3/2"4/5Aspect ratio of the media box, held before the image loads. Defaults to `4/5`.
classNamestring—Additional class names to merge with the component root element
headingLevel1 | 2 | 3 | 4 | 5 | 63Which heading tag (`h1`-`h6`) wraps the title. Defaults to `3`.
hrefstring—Makes the whole card one link, named by the title. Omit for a static card with no hover and no focus stop.
linkComponentElementTypeaComponent that renders the link, for client-side routing (pass `next/link`). Receives `href` and `className`. Defaults to a plain `a`.
metaReactNode—Optional row on the card's bottom edge (a price, a status badge); keep it non-interactive
subtitleReactNode—Optional line under the title, clamped at one line
unavailableLabelstringImage unavailableLabel for the failed-image fallback, read before the image's alt text. Defaults to "Image unavailable"; pass your translation.

Also accepts the native attributes of its root element (className, aria-*, event handlers, …).

Hooks

useImageStatus hook

Tracks whether the `<img>` inside a wrapper failed to load, whatever component drew it (a plain `<img>` or an app's `next/image`). `resetKey` names the image: a new key clears the failure. An image that broke before hydration fires no event, so a mount also reads `complete` and `naturalWidth`.

useImageStatus(resetKey: string): ImageFailureResult
ParameterTypeDefaultDescription
resetKeystring——

Returns ImageFailureResult