Sections
Getting Started
Components
- DocTabs
- Callout
- ComponentPreview
- CommandMenu
- CopyButton
- DocsSidebar
- DocsTableOfContents
- PageHeader
- SiteHeader
- CopyCodeButton
- DocsCopyPage
- CodeBlockCommand
- CommandMenuItem
- CommandMenuKbd
- GitHubLink
- LucideIcon
- MainNav
- MobileNav
- ModeSwitcher
- PageHeaderDescription
- PageHeaderHeading
- SiteBody
- SiteConfig
- SiteFooter
- OgImage (Custom)
<script setup lang="ts">
import { ArrowUpIcon } from "lucide-vue-next";
</script>
<template>
<div class="flex flex-wrap items-center gap-2 md:flex-row">
<Button variant="outline">
Button
</Button>
<Button variant="outline" size="icon" aria-label="Submit">
<ArrowUpIcon />
</Button>
</div>
</template>The ComponentPreview component is a powerful MDC (Markdown Components) feature that allows you to display interactive Vue components alongside their source code in your documentation.
Usage
Use the ::component-preview syntax in your markdown files:
::component-preview
---
name: ButtonDemo
description: A basic button example
align: center
---
::Or using the shorthand inline syntax:
::component-preview{name="ButtonDemo" align="end"}How It Works
The ComponentPreview component automatically:
- Looks for the component in
components/demo/first - Falls back to
components/ui/if not found in demo - Renders the component interactively
- Displays the source code in a tabbed interface
Examples
Basic Preview
Component TabsDemo not found in components/demo or components/ui.
With Alignment
You can control the alignment of the preview:
::component-preview
---
name: ButtonDemo
align: start
---
::Hide Code
You can hide the code tab to show only the interactive preview:
::component-preview
---
name: ButtonDemo
hideCode: true
---
::Component Resolution
The component resolver follows this order:
components/demo/ComponentName.vuecomponents/demo/ComponentName/index.vuecomponents/ui/componentname/ComponentName.vuecomponents/ui/ComponentName.vue
API Reference
ComponentPreview
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | (Required) | The name of the component to preview |
align | "center" | "start" | "end" | "center" | Alignment of the rendered component inside the preview box |
description | string | undefined | An optional description for the component |
hideCode | boolean | false | If true, the "Code" tab and source code will be hidden |
class | HTMLAttributes["class"] | undefined | Custom CSS classes applied to the root wrapper |
Creating Demo Components
To create a demo component, add a .vue file in app/components/demo/:
<!-- app/components/demo/MyComponentDemo.vue -->
<template>
<div>
<MyComponent />
</div>
</template>Then reference it in your documentation:
::component-preview
---
name: MyComponentDemo
---
::Best Practices
- Use descriptive names: Name your demo components clearly (e.g.,
ButtonDemo,ButtonWithIcon) - Keep demos simple: Focus on demonstrating one feature or variant per demo
- Add descriptions: Use the
descriptionprop to explain what the demo shows - Organize demos: Group related demos in your documentation