Specimen Stack

A fan of dark-fantasy relic cards. Drag, scroll sideways or use the arrows to browse, and press the card in front to lift it out and turn it over to its data sheet.

Drag or use the arrows. Press the front card to inspect.

Five relic cards fan out under a fixed centre. Drag sideways, throw the fan, scroll sideways on a trackpad, or use the arrows under it, and the cards slide past while the name below follows the one in front. That card leans toward the pointer, with a glare that follows it.

Press the card in front and it lifts out of the fan and turns over to its data sheet: epithet, menace, origin, material, weight and who carries it. Press it again to turn it back. Escape, or a press on the stage around it, puts it back in the fan.

With the keyboard, ← and → browse, Home and End jump to either end, Enter or Space inspects the card in front and turns it over, and Escape closes it. The keys belong to the demo while the pointer is over it or focus is inside it, and to the page everywhere else.

How it works

  • One number places every card. Each card's pose is a function of pos, the index under the centre, so a drag, a throw, a key and a press all move that one number and the fan follows it on a spring.
  • Three springs carry the rest. One for the lift, one for the turn, and one pointer tilt per card. A single frame loop writes a transform and five custom properties per card and stops once everything has settled, so nothing renders while the fan moves.
  • A throw lands where its momentum would carry it. Release a drag and the fan settles on the card the velocity points at. Dragged past either end, the fan gives a little and springs back.
  • The card is drawn once, at a fixed size, and scaled. Its back is laid out a single time, so it cannot reflow or overflow at a small size. The perspective scales with it, so the fan looks the same at every size.
  • The glare is three custom properties. --gx and --gy place a radial light that follows the tilt, --ga fades it in, and it is mirrored on the back since it faces away.
  • Each relic brings two pictures. src is the front, shown full-bleed, and texture is the close-up strip on the back. Leave texture out and the strip crops src instead. The art is dark, so the name and subtitle on the front are light.
  • The sheet is one list of facts. menace, origin, material, weight and bearer fill the back, so the same layout holds a relic, a mineral or anything else with five facts.
  • Reduced motion drops the springs: the fan, the lift and the turn jump to where they are going, and the pointer tilt switches off.

Each card is a real button, and a polite live region reads out the card in front as it changes, then the whole data sheet when a card is opened.

Installation

pnpm dlx shadcn@latest add @uitopia/specimen-stack

Usage

import SpecimenStack from "@/components/ui/specimen-stack";

<SpecimenStack />;

The component draws its own stage, nav row and hint. Pass your own cards with specimens. The line under the name, formula, is a list of parts, where a string is set on the line and a one-item tuple is a subscript, so the markup is real <sub> elements. A new set of ids starts a new fan; a new array with the same ids does not.

<SpecimenStack
  specimens={[
    {
      id: "behelit",
      name: "Crimson Behelit",
      src: "/relics/behelit.webp",
      texture: "/relics/behelit-texture.webp",
      formula: ["Egg of the King"],
      menace: [10, 10],
      origin: "Unknown",
      material: "Blood stone",
      weight: "0.3 kg",
      bearer: "Griffith",
      hue: "#a3121a",
      note: "Its face is never quite in line.",
    },
  ]}
/>

API

PropTypeDefaultDescription
specimensreadonly Specimen[]five relicsThe fan, first card first. See the fields below.
hintstring | falsea short lineThe line under the stage. false hides it.
classNamestring-Classes for the outer wrapper.

A Specimen is { id, name, src, texture?, formula, menace, origin, material, weight, bearer, hue, note }. menace is the low and high ends of a rating out of ten, weight is a string with its unit, and bearer is who carries it. texture is the close-up strip on the back, and falls back to a crop of src. hue is the colour of the swatch on the back of its card.

Artwork

The default five are original SVG illustrations, rendered to webp: a wolf-faced helm, a slab of a greatsword, an egg-shaped stone with a face that sits slightly out of true, a white beaked falcon mask, and a glowing brand on obsidian. Each has a matching texture for the back of its card. The component loads them from uitopia.vercel.app, so it adds no image weight to your bundle but relies on that host. The cards are fan art for the manga Berserk by Kentaro Miura. Pass your own specimens for anything you ship.