# Components

Built-in and custom components.

These components work in every page without an import, with attributes and slots written as in [Markdown](/markdown#components).

## Built-in Components [#built-in-components]

### Callout [#callout]

A callout holds a note next to the text. `type` sets its color and icon:

```md
<Callout type="warn" title="Careful">
  This can't be undone.
</Callout>
```

<Callout title="type=&quot;info&quot;">The default, for a note.</Callout>

<Callout type="warn" title="type=&quot;warn&quot;">A trap, or a breaking change.</Callout>

<Callout type="error" title="type=&quot;error&quot;">Something that fails, or must not be done.</Callout>

<Callout type="success" title="type=&quot;success&quot;">A completed result.</Callout>

<Callout type="idea" title="type=&quot;idea&quot;">A tip.</Callout>

### CalloutProps

| Prop     | Type                       | Description                                                                         |
| -------- | -------------------------- | ----------------------------------------------------------------------------------- |
| `title?` | `string \| undefined`      | The title. The slot `title` takes other content.                                    |
| `type?`  | `CalloutType \| undefined` | Default: `info`                                                                     |
| `icon?`  | `string \| undefined`      | A custom icon in place of the one of the type. The slot `icon` takes other content. |

For markup in the title or the icon, use the `title` and `icon` slots instead of the props.

#### Containers and Alerts [#containers-and-alerts]

`admonitionsPlugin()` from `vuesho/markdown` renders the callouts of VitePress, Fumadocs and GitHub:

```ts title="vuesho.config.ts"
import { admonitionsPlugin } from "vuesho/markdown"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset(),
  admonitionsPlugin(), // [!code ++]
);
```

```md tab="VitePress"
::: warning Watch out
This API is experimental.
:::

::: tip Use `pnpm`
It's faster.
:::

::: details Changelog
The list of changes.
:::
```

```md tab="Fumadocs"
:::warning[Watch out]
This API is experimental.
:::

:::tip[Use `pnpm`]
It's faster.
:::
```

```md tab="GitHub"
> [!WARNING]
> This API is experimental.
```

The name sets the callout's `type`, like `tip` for `info` and `danger` for `error`. `::: details` renders as a `<details>` element, and a name the plugin doesn't know, like `::: code-group`, stays as text.

### Cards [#cards]

Cards link to other pages in a grid:

```md
<Cards>
  <Card title="Quick Start" href="/">
    Create a site from an empty folder.
  </Card>
  <Card title="Images" href="/markdown/images">
    Sizes, placeholders and optimization.
  </Card>
</Cards>
```

<Cards>
<Card title="Quick Start" href="/">
Create a site from an empty folder.
</Card>

<Card title="Images" href="/markdown/images">
Sizes, placeholders and optimization.
</Card>
</Cards>

### CardProps

| Prop           | Type                   | Description |
| -------------- | ---------------------- | ----------- |
| `title?`       | `string \| undefined`  |             |
| `href?`        | `string \| undefined`  |             |
| `icon?`        | `string \| undefined`  |             |
| `description?` | `string \| undefined`  |             |
| `external?`    | `boolean \| undefined` |             |

Like a callout, a card takes markup in its `title` and `icon` slots. Put a blank line between a `<template #slot>` and the text of the default slot, or the page fails to compile with `E-SLOT-PARAGRAPH`:

```md
<Card title="Deploying" href="/deploying">
  <template #icon>🚀</template>

Put the site online.
</Card>
```

<Card title="Deploying" href="/deploying">
<template #icon>
🚀
</template>

Put the site online.
</Card>

### Tabs [#tabs]

Tabs switch between alternatives in prose. `items` lists the labels, and each `<Tab>` takes one of them as its `value`:

```md
<Tabs :items="['Vue', 'React']">
  <Tab value="Vue">Write a `.vue` file.</Tab>
  <Tab value="React">Write a `.tsx` file.</Tab>
</Tabs>
```

<Tabs :items='["Vue","React"]'>
<Tab value="Vue">Write a `.vue` file.</Tab>

<Tab value="React">Write a `.tsx` file.</Tab>
</Tabs>

### TabsProps

| Prop            | Type                    | Description                                                                                                                              |
| --------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `groupId?`      | `string \| undefined`   | Tab groups with the same id share their selected value.                                                                                  |
| `persist?`      | `boolean \| undefined`  | Remembers the selected value in `localStorage`, under `groupId`.                                                                         |
| `updateAnchor?` | `boolean \| undefined`  | When true, selecting a tab sets the URL hash to the tab's id.                                                                            |
| `defaultValue?` | `string \| undefined`   |                                                                                                                                          |
| `items?`        | `string[] \| undefined` | Uses the simple mode with these items, instead of the advanced usage documented at https://radix-ui.com/primitives/docs/components/tabs. |
| `defaultIndex?` | `number \| undefined`   | Shortcut for `defaultValue` when `items` is provided. Default: `0`                                                                       |
| `label?`        | `string \| undefined`   | An additional label in the tab list when `items` is provided. The slot `label` takes other content.                                      |

For alternatives in code, [code tabs](/markdown#code-tabs) are shorter.

### Steps [#steps]

Steps number a sequence of headings. With `stepsPlugin()` from `vuesho/markdown`, a heading that ends with `[step]` becomes a step. New sites don't include the plugin, so add it first:

```ts title="vuesho.config.ts"
import { stepsPlugin } from "vuesho/markdown"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset(),
  stepsPlugin(), // [!code ++]
);
```

```md
#### Install the Package [step]

Run `npm i acme`.

#### Write a Page [step]

Create `content/index.md`.
```

<Steps>
<Step>
#### Install the Package [#install-the-package]

Run `npm i acme`.
</Step>

<Step>
#### Write a Page [#write-a-page]

Create `content/index.md`.
</Step>
</Steps>

Consecutive `[step]` headings of the same level form the steps, and a heading of that level or higher without `[step]` ends them. A step's ID ends with `-step`, like `install-the-package-step`. To set the ID yourself, add `[#id]` after `[step]`.

Without the plugin, write the same steps with `<Steps>` and `<Step>`:

```md
<Steps>
<Step>

#### Install the Package

Run `npm i acme`.

</Step>
<Step>

#### Write a Page

Create `content/index.md`.

</Step>
</Steps>
```

### Accordions [#accordions]

Accordions collapse content into panels that open on click. With an `id`, a link like `#vue-components` opens the panel:

```md
<Accordions>
  <Accordion title="Does a site need a server?">
    No. A site with only Markdown pages builds to static files.
  </Accordion>
  <Accordion title="Can a page use Vue components?" id="vue-components">
    Yes, any component in `src/components/content/`.
  </Accordion>
</Accordions>
```

<Accordions>
<Accordion title="Does a site need a server?">
No. A site with only Markdown pages builds to static files.
</Accordion>

<Accordion title="Can a page use Vue components?" id="vue-components">
Yes, any component in `src/components/content/`.
</Accordion>
</Accordions>

<Tabs :items='["Accordion","Accordions"]'>
<Tab value="Accordion">
### AccordionProps

| Prop     | Type                  | Description                                      |
| -------- | --------------------- | ------------------------------------------------ |
| `title?` | `string \| undefined` | The title. The slot `title` takes other content. |
| `id?`    | `string \| undefined` |                                                  |
| `value?` | `string \| undefined` |                                                  |
</Tab>

<Tab value="Accordions">
### AccordionsProps

| Prop            | Type                    | Description |
| --------------- | ----------------------- | ----------- |
| `defaultValue?` | `string[] \| undefined` |             |
| `multiple?`     | `boolean \| undefined`  |             |
</Tab>
</Tabs>

### Files [#files]

Files draw a tree of folders and files:

```md
<Files>
  <Folder name="content" default-open>
    <File name="index.md" />
    <File name="meta.json" />
  </Folder>
  <File name="vuesho.config.ts" />
</Files>
```

<Files>
<Folder name="content" defaultOpen>
<File name="index.md" />

<File name="meta.json" />
</Folder>

<File name="vuesho.config.ts" />
</Files>

<Tabs :items='["Folder","File"]'>
<Tab value="Folder">
### FolderProps

| Prop           | Type                   | Description                                   |
| -------------- | ---------------------- | --------------------------------------------- |
| `name`         | `string`               |                                               |
| `disabled?`    | `boolean \| undefined` |                                               |
| `defaultOpen?` | `boolean \| undefined` | Opens the folder by default. Default: `false` |
</Tab>

<Tab value="File">
### FileProps

| Prop    | Type                  | Description                                    |
| ------- | --------------------- | ---------------------------------------------- |
| `name`  | `string`              |                                                |
| `icon?` | `string \| undefined` | The icon. The slot `icon` takes other content. |
</Tab>
</Tabs>

With `filesPlugin()` from `vuesho/markdown`, a `files` code block draws the same tree from text, and `<auto-files>` draws a folder on disk. New sites don't include the plugin, so add it first:

```ts title="vuesho.config.ts"
import { filesPlugin } from "vuesho/markdown"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset(),
  filesPlugin(), // [!code ++]
);
```

In a `files` code block, a name that ends with `/` is an empty folder:

````md
```files
my-docs
├── content
│   ├── index.md
│   └── guides/
└── vuesho.config.ts
```
````

```files
my-docs
├── content
│   ├── index.md
│   └── guides/
└── vuesho.config.ts
```

`<auto-files>` lists the files in `dir` that match `pattern`, and `vuesho dev` updates the tree when they change:

```md
<auto-files dir="../../src/components" pattern="*.vue" default-open-all />
```

```
SlotBox.vue
```

### AutoFilesProps

Attributes of `<auto-files>` in Markdown.

| Prop              | Type                   | Description                                                                                                  |
| ----------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------ |
| `dir?`            | `string \| undefined`  | The folder to list, relative to the Markdown file.                                                           |
| `pattern`         | `string`               | A glob pattern for the files to list. Repeat it to combine patterns, or start one with `!` to exclude files. |
| `defaultOpenAll?` | `boolean \| undefined` | Opens every folder of the tree by default. Default: `false`                                                  |

### Type Table [#type-table]

A type table lists an object's fields, like a function's options or a component's props. A row opens to show its full type and description:

```md
<TypeTable
  :type="{
    dir: {
      type: 'string',
      description: 'The folder of the collection.',
      required: true,
    },
    depth: {
      type: 'number',
      description: 'How many levels of folders to list.',
      default: '1',
    },
  }"
/>
```

<TypeTable :type='{"dir":{"type":"string","description":"The folder of the collection.","required":true},"depth":{"type":"number","description":"How many levels of folders to list.","default":"1"}}' />

For Markdown in a field, use a slot named `<field>.<key>`:

```md
<TypeTable :type="{ dir: { type: 'string', required: true } }">
  <template #dir.description>The folder of the [collection](/markdown/collections).</template>
</TypeTable>
```

To generate type tables from your TypeScript types, see [Type Tables](/markdown/type-tables).

### Image Zoom [#image-zoom]

An image zoom opens the image at full size on click. Its other attributes, like `width` and `title`, go on the `<img>`:

```md
<ImageZoom src="/screenshots/light.png" alt="The Getting Started page" />
```

<ImageZoom src="/screenshots/light.png" alt="The Getting Started page" />

### ImageZoomProps

| Prop           | Type                             | Description                                                                                   |
| -------------- | -------------------------------- | --------------------------------------------------------------------------------------------- |
| `src?`         | `string \| undefined`            |                                                                                               |
| `alt?`         | `string \| undefined`            |                                                                                               |
| `width?`       | `Numberish \| undefined`         |                                                                                               |
| `height?`      | `Numberish \| undefined`         |                                                                                               |
| `sizes?`       | `string \| undefined`            |                                                                                               |
| `zoomInProps?` | `ImgHTMLAttributes \| undefined` | Props of the image when it is zoomed in.                                                      |
| `rmiz?`        | `UncontrolledProps \| undefined` | Props for the `Zoom` of `react-medium-image-zoom`. They are unused inside `<Lightbox />`.     |
| `caption?`     | `string \| undefined`            | The caption in `<Lightbox />`. The slot `caption` takes other content. Default: `` `title` `` |
| `priority?`    | `boolean \| undefined`           | Whether the image loads with priority.                                                        |

`Lightbox` from `vuesho/ui/components/image-zoom` opens the images inside it in one viewer, where the reader can move between them:

```md
<Lightbox>
  <ImageZoom src="/screenshots/light.png" alt="Light mode" title="Light" width="320" />
  <ImageZoom src="/screenshots/dark.png" alt="Dark mode" title="Dark" width="320" />
</Lightbox>

<script setup>
import { Lightbox } from "vuesho/ui/components/image-zoom";
</script>
```

<Lightbox>
<ImageZoom src="/screenshots/light.png" alt="Light mode" title="Light" width="320" />

<ImageZoom src="/screenshots/dark.png" alt="Dark mode" title="Dark" width="320" />
</Lightbox>

### Inline TOC [#inline-toc]

An inline TOC renders the table of contents inside the page, in a panel that opens on click. Its default slot is the label:

```md
<InlineTOC>On this page</InlineTOC>
```

<InlineTOC>On this page</InlineTOC>

## Custom Components [#custom-components]

A `.vue` file in `src/components/content/` is a component that every page can use, by its file name:

```vue title="src/components/content/Badge.vue"
<script setup lang="ts">
defineProps<{ text: string }>();
</script>

<template>
  <span class="badge">{{ text }}</span>
</template>

<style scoped>
.badge {
  padding: 2px 8px;
  border-radius: 9999px;
  background: var(--color-fd-primary);
  color: var(--color-fd-primary-foreground);
  font-size: 0.75rem;
}
</style>
```

```md title="content/index.md"
This feature is <Badge text="new" />.
```

A page loads only the components it uses. [Type Checking](/markdown/type-checking) types each component's props automatically.

A capitalized tag that the folder and the plugins don't provide fails with `E-UNKNOWN-COMPONENT`. A lowercase tag is an HTML element, except Vue's built-in components, like `<component>` and `<transition>`. A [collection](/markdown/collections#components) can have a components folder of its own.

### Replacing Elements [#replacing-elements]

A file named after an HTML element, like `table.vue`, replaces that element in Markdown pages. This component wraps every table in a frame:

```vue title="src/components/content/table.vue"
<template>
  <div class="table-frame">
    <table>
      <slot />
    </table>
  </div>
</template>
```
