Code Snippet

The collapsible “View Code” block used throughout these docs. It supports a togglable reveal, multiple language tabs, one-click copy, and pulling markup straight from the live demo it documents. Styles ship in framework/css/components/code-snippet.css and behavior in framework/js/components/code-snippet.js.

Collapsible (single language)

Click “View Code” to expand the block.

<div class="vd-code-snippet" data-collapsible>
  <button class="vd-code-snippet-toggle" aria-expanded="false">
    <span class="vd-code-snippet-toggle-icon"></span>
    <span>View Code</span>
  </button>
  <div class="vd-code-snippet-content">
    <div class="vd-code-snippet-body">
      <pre class="vd-code-snippet-pane is-active" data-lang="html"><code>...</code></pre>
    </div>
  </div>
</div>
Multiple language tabs

Provide more than one language to get HTML / CSS / JavaScript tabs.

<div class="vd-code-snippet" data-collapsible>
  <button class="vd-code-snippet-toggle" aria-expanded="false">
    <span class="vd-code-snippet-toggle-icon"></span>
    <span>View Code</span>
  </button>
  <div class="vd-code-snippet-content">
    <div class="vd-code-snippet-body">
      <pre class="vd-code-snippet-pane is-active" data-lang="html"><code>...</code></pre>
    </div>
  </div>
</div>
.my-element {
  color: var(--vd-color-primary);
  border-radius: var(--vd-radius-fib-5);
}
import { VdCodeSnippet } from "@vanduo-oss/vd3";

const code = "const x = 1;";
// Render a highlighted, copyable block — no init call needed:
// <VdCodeSnippet :code="code" language="javascript" />
Expanded by default

Add data-expanded="true" to render the snippet open on load.

import { VdCodeSnippet } from "@vanduo-oss/vd3";

const code = "const x = 1;";
// Render a highlighted, copyable block — no init call needed:
// <VdCodeSnippet :code="code" language="javascript" />
API Reference

Usage

<script setup lang="ts">
import { VdCodeSnippet } from "@vanduo-oss/vd3";
const code = "const x = 1;";
</script>

<template>
  <VdCodeSnippet :code="code" language="javascript" />
</template>

CSS Classes

ClassDescription
.vd-code-snippetRoot wrapper. Add data-collapsible to make it a togglable View Code block.
.vd-code-snippet-toggleThe “View Code” button that expands/collapses the content.
.vd-code-snippet-toggle-iconChevron indicator inside the toggle, rotated by state.
.vd-code-snippet-contentThe collapsible region holding the header and body.
.vd-code-snippet-headerRow holding the language tabs and the copy button.
.vd-code-snippet-tabsTablist wrapping one .vd-code-snippet-tab per language.
.vd-code-snippet-tabA language tab. Add is-active to mark the visible pane.
.vd-code-snippet-copyCopy-to-clipboard button for the active pane.
.vd-code-snippet-bodyContainer for the code panes.
.vd-code-snippet-paneOne <pre> per language (data-lang). is-active shows it.
.vd-code-snippet-singleModifier for a snippet with no language tabs.
.vd-code-snippet-inlineInline, non-collapsible code presentation.
.vd-code-snippet-line-numbersAdds a gutter with line numbers.

Component API (Vue 3)

PropDescription
:codeThe code string to display.
:languageHighlight language (default "html").
:copyableShow a copy button (default true).

Data Attributes

AttributeDescription
data-collapsibleMakes the snippet a collapsible View Code block.
data-expandedSet to "true" to render the snippet expanded on load.
data-langLanguage key on each tab and pane (e.g. html, css, javascript).
data-extractSelector on a pane — pulls its HTML from the live demo it documents.

Runtime notes

SurfaceDescription
<VdCodeSnippet>Self-contained Vue 3 component — highlights and (optionally) copies code. No init call or global runtime is required.
.vd-code-snippet markupThe collapsible “View Code” block is plain markup plus your own toggle logic (this site's DocCodeSnippet wraps it in Vue); vd3 ships no auto-init for it.