Skip to content

GhostCodeBlock reference ​

Package: @ghostvue/themes. Status: experimental (stability policy).

Themed code block around @ghostvue/vue GhostCodeBlock: subtle surface, hairline border, muted header with the title and language, quiet Copy and fold buttons on the small control size, a CSS-painted check while copied, the failure text in the danger color under the header, the mono type token with a numeric line height so the fold shows exactly foldLines lines, and a fade over the last visible line while collapsed (removed under reduced transparency and forced colors). Same props, events, slots and exposed members as the headless component; behavior and accessibility come from it.

Generated from the component manifest. Edit the manifest or Vue source, then rebuild the docs.

All component references

Props ​

None declared.

Emits ​

NamePayloadDescription
copySettledGhostCodeBlockCopySettledEventForwarded copySettled event.

Models ​

PropEventTypeDescription
expandedupdate:expandedbooleanv-model:expanded binding for the fold state.

Slots ​

NameDescription
defaultForwarded default slot: highlighted markup inside the code part.
titleForwarded title slot.
actionsForwarded actions slot with copy and state.
copyForwarded copy slot with state.

Slot props: default ​

None declared.

Slot props: title ​

None declared.

Slot props: actions ​

None declared.

Slot props: copy ​

None declared.

Exposed members ​

NameTypeDescription
elementHTMLElement | nullRoot of the inner headless component.
copy() => Promise<boolean>Runs the inner component's copy, including the failure fallback.

Parts and data attributes ​

AttributeValueDescription
data-partrootHeadless root (ghost-code-block) inside a block div.ghost-themed-scope wrapper. The recipe reaches the header, copy, status, viewport, code and fold-toggle parts through child combinators only.

CSS variables ​

NameDescription
--ghost-type-family-monoCode font family.
--ghost-surface-subtle-bgBlock surface and the collapsed fade color.
--ghost-border-defaultBlock border and header separator.
--ghost-text-dangerFailure text color.

Accessibility ​

Role: generic. APG pattern: https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.

Required ARIA attributes: none.

Keyboard ​

None declared.

Verification ​

Each category is reviewed separately. Automated keyboard and axe results do not attest manual or assistive-technology review.

CategoryStatusEvidence
Automated keyboardNot reviewedNo declared key is mapped to a browser test yet.
Manual interactionNot reviewedNo review recorded.
Assistive technologyNot reviewedNo review recorded.

Examples ​

code-block/highlighted ​

Example source

Highlighted, copyable and foldable

A TypeScript file rendered from consumer-highlighted tokens with a file name header, Copy, horizontal scroll for a long line, and a fold after eight lines.

useCart.tsts
import { computed, ref } from 'vue'

// Totals stay in cents so rounding happens once, at display time.
export function useCart(currency = 'USD', locale = 'en-US', taxRate = 0.0825, freeShippingThreshold = 5_000) {
  const items = ref<CartItem[]>([])
  const subtotal = computed(() =>
    items.value.reduce((sum, item) => sum + item.cents * item.quantity, 0),
  )
  const format = new Intl.NumberFormat(locale, { style: 'currency', currency })
  const total = computed(() => format.format((subtotal.value * (1 + taxRate)) / 100))

  return { items, subtotal, total }
}

code-block/shell ​

Example source

Shell commands

Install commands whose $ prompts render but are left out of the copied text through copyText, with an icon in the copy slot.

Terminalsh
pnpm add @ghostvue/vue @ghostvue/themes
pnpm dev

code-block/actions ​

Example source

Header actions

An Open in playground link and an icon-only custom Copy button in the actions slot, with the built-in button removed and copySettled recording the last result.

useCounter.tsts Open in playground
import { ref } from 'vue'

export function useCounter(start = 0) {
  const count = ref(start)
  const increment = () => {
    count.value += 1
  }
  return { count, increment }
}

Not copied yet

Example source

Copy an invite link

useGhostClipboard on an ordinary button outside a code block, announcing the result in GhostVisuallyHidden and showing the failure next to the field.