<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-book/usage/ in the magma monorepo.
-->

# mds-book - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-book>` component, ordered from most common to most specialized. The examples assume a working knowledge of the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

#### A Book from Its Cover

The canonical form: the cover image and the catalogue data. The title and the author name the book for assistive technologies and are printed on the spine.

```html
<mds-book
  src="/covers/operazioni-straordinarie.webp"
  name="Operazioni straordinarie"
  author="Antonio D'Amico e Sara Orlando"
  publisher="Maggioli Editore"
></mds-book>
```

#### Pages and Binding from the Catalogue Record

Pass the page count and the binding of the record as they are: the book takes its true depth, so a booklet and a large manual do not look alike.

```html
<mds-book src="/covers/guida-rapida.webp" name="Guida rapida al GDPR" pages="64"></mds-book>

<mds-book
  src="/covers/codice-appalti.webp"
  name="Codice dei contratti pubblici"
  pages="1000"
  binding="hardcover"
></mds-book>
```

#### A Catalogue Grid

The book takes the width of its cell. Give the grid some gap: the turned books reach a little beyond their boxes.

```html
<div class="grid grid-cols-4 gap-1200">
  <mds-book src="/covers/1.webp" name="Creare la holding" author="Ennio Vial"></mds-book>
  <mds-book src="/covers/2.webp" name="Chief AI Officer" pages="480"></mds-book>
  <mds-book src="/covers/3.webp" name="Aste immobiliari e vendita forzata"></mds-book>
  <mds-book src="/covers/4.webp" name="Agenda dei servizi demografici 2027"></mds-book>
</div>
```

#### A Pose for the Layout

Pick the pose that suits where the book sits: `spine` in a catalogue, `front` beside a description, `lying` or `lying-turned` for a book on a desk in a hero or a banner.

```html
<mds-book src="/covers/manuale.webp" name="Manuale" pose="front"></mds-book>

<mds-book
  src="/covers/codice-appalti.webp"
  name="Codice dei contratti pubblici"
  binding="hardcover"
  pages="640"
  pose="lying-turned"
></mds-book>
```

#### A Fixed Format

With `format="auto"` (the default) the book takes the proportions of its image once it loads. Set the format when the catalogue knows it, so the book has its shape before the image arrives; write any format as `WxH` in centimetres, the width first.

```html
<mds-book src="/covers/modulistica.webp" name="Modulistica" format="a4"></mds-book>

<mds-book src="/covers/atlante.webp" name="Atlante dei comuni" format="29.7x21"></mds-book>
```

#### A Book Without a Cover Image

Without `src`, the component draws a cover with the title, the author and the publisher. Give it the colour of the series: `--mds-book-color` paints only the drawn cover, also when an image fails, so it can be set on every book of a library, the books with an image keep the colours of their cover.

```html
<mds-book
  name="Agenda dei servizi demografici 2027"
  publisher="Maggioli Editore"
  style="--mds-book-color: #f2a93b; --mds-book-text-color: #ffffff"
></mds-book>
```

#### A Document

A document is not bound: give it `binding="none"` and it is a stack of sheets, its pages showing on every side, its cover (the image, or the one the component draws) the sheet on top. A library of books and documents keeps one record shape: only the binding changes.

```html
<mds-book
  binding="none"
  name="Circolare n. 122"
  author="Direzione centrale entrate"
  publisher="INPS"
  pages="24"
></mds-book>
```

#### The Mark of the Publisher

Give the mark of the publisher instead of printing its name: it goes at the foot of the spine, and of the cover when the component draws it. Its shape is printed in the colour of the text, or in `--mds-book-publisher-color`; keep `publisher`, printed if the mark does not load.

```html
<mds-book
  name="Agenda dei servizi demografici 2027"
  author="Redazione Maggioli"
  publisher="Maggioli Editore"
  publisher-logo="/logos/maggioli-editore.svg"
  style="--mds-book-color: #f2a93b; --mds-book-text-color: #ffffff"
></mds-book>
```

#### A Solid Spine

When the left edge of the cover does not continue well onto the spine (a photo, a thin white border), give the spine and the board edges a colour of their own.

```html
<mds-book
  src="/covers/manuale.webp"
  name="Manuale"
  style="--mds-book-spine-color: #123a6b"
></mds-book>
```

#### A Book That Opens Its Product Page

The book is an image, not a control: wrap it in a link, with the link named by the book. Turning the book with a drag does not open the link; a click does.

```html
<a href="/catalogo/creare-la-holding">
  <mds-book src="/covers/creare-la-holding.webp" name="Creare la holding" author="Ennio Vial"></mds-book>
</a>
```
