# Card

Source: https://material.spynejs.com/components/cards
Part of: Material shell gallery, Google's Material Design 3 for SpyneJS. Index: https://material.spynejs.com/llms.txt

Material's card. A page shows its sub-pages as cards, and a card is a link to its page. A card has no keys of its own: it is a sub-page's node in the model. The surface a section sits on is a card too, and a page item's `container` key says whether it has one.

## In an app model

A card is a sub-page’s node, in its page’s `content`. The page it opens is that same node:

```json
{
  "pageId": "components",
  "topicId": "buttons",
  "title": "Button",
  "meta": "Five variants, five sizes, two shapes.",
  "ctaText": "Open",
  "href": "#",
  "attrImageSrc": "imgs/gallery/buttons.svg",
  "attrImageAlt": "",
  "pageItems": []
}
```

| Key of a sub-page’s node | Means |
| --- | --- |
| `pageId` | the page the card is on |
| `topicId` | the sub-page it opens |
| `title` | the card’s title |
| `meta` | its supporting text |
| `ctaText` | the words at its foot |
| `attrImageSrc` | its picture |
| `attrImageAlt` | the picture’s words for a reader who cannot see it |
| `pageItems` | what the page it opens shows |

- A sub-page needs its route as well: its `topicId` under its `pageId`, in `src/index.js`.
- Which card a thing is follows from where it is, not from a key. A card inside a page is outlined. The surface a section sits on is elevated.
- A page item says whether it has that surface in its `container` key: `{ "isEnabled": true }` for the elevated surface, `{ "isEnabled": false }` to sit straight on the page.
- `"classOptions": { "variant": "muted" }` in `container` is the Shell’s option for a quieter surface. In the Material template that surface is the page’s own colour with no shadow, so only its padding shows.

## The markup

The template writes a card as a list item holding a link. The link’s class, `page-card`, is what makes it a card that can be pressed, and what the move down into its page starts from:

```html
<li class="card">
  <a
    href="#"
    data-channel="ROUTE"
    data-page-id="components"
    data-topic-id="buttons"
    data-event-prevent-default="true"
    class="page-card"
  >
    <div class="card__image-wrapper">
      <img alt="" src="imgs/gallery/buttons.svg" class="card__image" />
    </div>
    <div class="card__content">
      <h2 class="card__title">Button</h2>
      <p class="card__meta">Five variants, five sizes, two shapes.</p>
      <p class="card__meta card__meta__cta">Open</p>
    </div>
  </a>
</li>
```

## Where it is in the template

| File | What it holds | By name |
| --- | --- | --- |
| `src/app/components/page-items/templates/cards-container-view.tmpl.html` | a card’s markup |  |
| `src/app/components/page-items/cards-container-view.js` | the view that shows a page’s sub-pages as cards |  |
| `src/scss/03-components/material/_cards.scss` | the styles: which card each of the Shell’s containers is |  |

The template is public: https://github.com/spynejs/application-shell-material. An app made from it has these same files.

What it rests on in `@spynejs/grammar`: `op:author-app-model-node`.

## As the page shows it

The page’s own words, in its own order, read from the page as it is drawn in the light colour scheme. They were written for someone looking at the page: “above”, “below” and “marked” mean the drawn page. A thing the page draws is named here in its place (`Button:`, `Field:`, `Switch:`), and a box that reports what the reader does is as it starts, empty. What depends on the reader’s own window is left out.

A page shows its sub-pages as cards. A card is a link: point at it, reach it with the keyboard, press it.

- [Button](https://material.spynejs.com/components/buttons.md): Five variants, five sizes, two shapes.

Following it opens the Button page. From here that is a move between two pages at the same level, so the pages fade. On a section’s page, where a card leads down a level, the card grows into its page.

### In the app model

```json
{
  "pageId": "components",
  "topicId": "buttons",
  "title": "Button",
  "meta": "Five variants, five sizes, two shapes.",
  "ctaText": "Open",
  "href": "#",
  "attrImageSrc": "imgs/gallery/buttons.svg",
  "attrImageAlt": "",
  "pageItems": []
}
```

### Which card it is

Material has three cards: elevated, filled and outlined. The template uses two, and which one a thing is follows from where it is. A card inside a page is outlined. The surface a section sits on, like the one around this, is elevated. So a card never casts a shadow onto a card.

Nothing new is proposed here. A card’s keys are the Shell’s own: it is a sub-page’s node in the model, and the page it opens is that node.

### A muted container

This section asked for its container with the variant muted. That is the Shell’s own option, from before the Material template. In this template its surface is the page’s own colour and it has no shadow, so only its padding shows.

```json
{
  "container": {
    "isEnabled": true,
    "classOptions": {
      "variant": "muted"
    }
  }
}
```

### No container

This section asked for none, so it sits straight on the page.

```json
{
  "container": {
    "isEnabled": false
  }
}
```
