> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Image Card

A picture or a film with a tag, a title and an expand button set into it on hover, exported from `@fabiocv/ui/image-card`.

```tsx
import { ImageCard } from '@fabiocv/ui/image-card';

<ImageCard.Root src={picture} alt="A rounded rectangle joined to a circle">
  <ImageCard.Tag>Lab</ImageCard.Tag>
  <ImageCard.Title>Sliding connectors</ImageCard.Title>
  <ImageCard.Expand onClick={open} />
</ImageCard.Root>;

<ImageCard.Root
  type="video"
  src={film}
  alt=""
  tone="light"
  href="/work/maserati/"
>
  <ImageCard.Tag>Automotive</ImageCard.Tag>
  <ImageCard.Title>Maserati</ImageCard.Title>
  <ImageCard.Expand />
</ImageCard.Root>;
```

- The parts are not on top of the picture. The card is cut around each of them, with a thin gap, concentric corners and a fillet where a cut meets the card's edge. It is drawn by [Cutout](https://ui.fabio.cv/cutout/index.md).
- The tag sits in the top edge, `16px` from the right end. The title is in the bottom-left corner and the expand button in the bottom-right. Each slides in from its own edge, which `origin` changes. Leave one out and there is no cut for it.
- The title and the button are frosted glass over the picture itself. Over a film, they copy each frame it shows, so they never drift from it.
- The cut and the part move on one spring without a bounce, as a cut past its end would only stall.
- The card is `400px` wide, or as wide as what holds it, and `20:11`. Set its width and shape with `className`.
- It opens on hover and on keyboard focus within it. `open` holds it open or closed. Its parts stay focusable while it is closed, and focusing one opens it.
- Touch never opens it. A tap anywhere on a card with an expand button presses the button, so a touch goes straight through. A click does the same.
- With `href` the whole card is the link, and the expand tab its icon rather than a button, so the browser shows its address on hover. Keyboard focus shows on the expand tab. To one of the app's own pages it goes through [its router](https://ui.fabio.cv/router/index.md).
- `tone` says how bright the picture is: `light` gives the frosted parts dark ink, `dark` light ink. Leave it out and their ink follows the theme.
- A picture is treated as line art: laid over a tint of Foreground muted in the `overlay` blend mode, and inverted in dark. Draw it as dark lines on an opaque light ground, which dark turns into light lines on a dark one. A film shows as it is, with no tint. Without `src` the card is the tint alone, and its ink is Surface.
- A film plays muted on a loop, and its `alt` names it.
- The tag's colours are its own and not tokens: white capitals on `oklch(58% 0.2 45.3)`, in both themes. The orange is that deep so they read at 4.6:1, at `10px`.
- With reduced motion the parts and their cuts land at once, and their content fades in.

| Prop     | Default | What it sets                                                           |
| -------- | ------- | ---------------------------------------------------------------------- |
| `radius` | `6`     | The card's corners, its parts' and every fillet                        |
| `gap`    | `2`     | The space between a part and its cut                                   |
| `zoom`   | `1`     | The picture's scale about its centre                                   |
| `speed`  | `1`     | The rate it opens and closes at, for tuning. `0.25` is a quarter speed |

## Types of `@fabiocv/ui/image-card`

```ts
export type MediaType = 'image' | 'video';

/** How bright the card's picture is. */
export type Tone = 'light' | 'dark';

/** Where a part slides in from. Its timing lives in the card's choreography. */
type InsertionMotion = {
    origin?: CutoutOrigin;
    className?: string;
};

export type ImageCardRootProps = Omit<CutoutRootProps, 'children'> & {
    /** The picture or video. Without one, the card shows its own background. */
    src?: string;
    /** A video plays muted on a loop, and the frosted tabs follow its frames. */
    type?: MediaType;
    alt: string;
    /** Scales the image about its center. 1 fills the card. */
    zoom?: number;
    /**
     * Shows the insertions. Omit it to open on hover and on keyboard focus
     * within. A touch never opens them.
     */
    open?: boolean;
    /**
     * How bright the picture is under the frosted tabs, so their ink reads on
     * it: dark ink on `light`, light ink on `dark`. Omit it to follow the theme.
     * A card without a picture ignores it.
     */
    tone?: Tone;
    /** Plays the choreography at this rate, for tuning it: 0.25 is a quarter speed. */
    speed?: number;
    /** Makes the whole card a link to this address. */
    href?: string;
    children?: ReactNode;
};

declare function Root({ src, type, alt, zoom, tone, open: openProp, radius, gap, speed, href, className, children, onPointerEnter, onPointerLeave, onFocus, onBlur, onClick, ...props }: ImageCardRootProps): import("react").JSX.Element;

export type ImageCardTagProps = InsertionMotion & {
    /** Distance from the card's right edge. */
    alignOffset?: number;
    children: ReactNode;
};

/** Small label in the top edge. Slides down from the edge by default. */
declare function Tag({ origin, alignOffset, className, children, }: ImageCardTagProps): import("react").JSX.Element;

export type ImageCardTitleProps = InsertionMotion & {
    children: ReactNode;
};

/** Frosted title in the bottom-left corner. Slides in from the left by default. */
declare function Title({ origin, className, children }: ImageCardTitleProps): import("react").JSX.Element;

export type ImageCardExpandProps = InsertionMotion & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'className' | 'aria-label'> & {
    /** Accessible name of the button. */
    label?: string;
};

/**
 * Frosted button in the bottom-right corner. Slides in from the right by
 * default. On a card that is a link, it is the link's icon instead.
 */
declare function Expand({ origin, className, label, type, ...button }: ImageCardExpandProps): import("react").JSX.Element;

/**
 * Picture or video card with cutout insertions: a tag on the top edge, a frosted
 * title and an expand button on the bottom corners. They slide in on hover
 * and keyboard focus. A click or tap anywhere on a card with an expand button
 * presses it, so a touch goes straight through without showing the insertions.
 * With `href` the whole card is the link, so the browser shows its address on
 * hover.
 */
export declare const ImageCard: {
    Root: typeof Root;
    Tag: typeof Tag;
    Title: typeof Title;
    Expand: typeof Expand;
};
```

## Examples

### Picture

```tsx
<ImageCard.Root
  src="/image-card/sliding-connectors.png"
  alt="A rounded rectangle joined to a circle"
  zoom={1}
  radius={8}
  gap={2}
>
  <ImageCard.Tag>Lab</ImageCard.Tag>
  <ImageCard.Title>Sliding connectors</ImageCard.Title>
  <ImageCard.Expand />
</ImageCard.Root>
```

### Video

```tsx
<ImageCard.Root
  type="video"
  src="/image-card/maserati.mp4"
  alt="A Maserati, centred in the frame"
  tone="light"
>
  <ImageCard.Tag>Automotive</ImageCard.Tag>
  <ImageCard.Title>Maserati</ImageCard.Title>
  <ImageCard.Expand />
</ImageCard.Root>
```

### Without a picture

```tsx
<ImageCard.Root alt="">
  <ImageCard.Tag>Lab</ImageCard.Tag>
  <ImageCard.Title>Sliding connectors</ImageCard.Title>
  <ImageCard.Expand />
</ImageCard.Root>
```

See it at https://ui.fabio.cv/image-card/.
