Skip to content
LoidoltTheme 0.11.1
Svelte 5

Component

CodeSnippet

One highlighted block of code, with an optional filename and a copy button.

import { CodeSnippet } from '@loidolt/theme-docs';

Example

npm install @loidolt/theme-docs shiki
Report.svelte
<script lang="ts">
  import { LineChart } from '@loidolt/theme-charts';
  let { data } = $props();
</script>

<LineChart title="Sheets per month" {data} dataTable="toggle" />

Notes

  • Distinct from CodeBlock in @loidolt/theme-svelte, which is a single selectable value such as a key or a command.

Props

Generated from the component source, so it cannot drift from the implementation.

CodeSnippet props
PropTypeDefaultNotes
code required string—
class string—
copiedLabel string'Copied'
copyable booleantrueOffer a copy button.
copyLabel string'Copy'
filename string—Shown above the code, and names it.
highlight booleantrueHighlight with the registered Shiki loader, when there is one.
label string—Names the code for assistive tech when there is no filename. Defaults to "‹lang› code".
lang string''Language for highlighting, e.g. ts, svelte, css.
ref bindableHTMLElement | nullnull

Plus the attributes of HTMLAttributes<HTMLElement>, forwarded to the root element.