Editors

Preview

A rendered example with its code under it, for a docs site, a style guide or a design system: what you write inside the tag is shown live, and the same Blade, as written, is shown under it in a tk:code with a copy button and a switch to see the example right to left.

Paid Overdue
Blade

A white box with the two badges in a row, and under it the two lines of Blade, colored, with a button to see the badges right to left and a copy button. In dark mode the box is dark gray.

Parts only for the example #

What sits between {{-- demo --}} and {{-- /demo --}} renders in the box but stays out of the code, so a value shown to make the example clear is not copied with it.

notify: true

Blade

Code of your own #

code replaces the captured Blade: here $checkout holds the file of the Livewire component behind the button, shown under a header with its file name and cut to 30 lines with an "Expand" button.

checkout.blade.php
Blade

Layout of the box #

By default the box lays its content out in a wrapping row. center puts a single item in the middle, and canvas: classes change the layout, the height or the background.

AL
Blade

Reference

tk:preview

Prop Type Default Description
code string the Blade written inside The code shown under the example.
language string html The language for Highlight.js.
title string | slot null The text at the start of the code header: a file name, a language.
copyable bool | string true The copy button in the code header. A string is its text.
maxLines int null Cuts longer code to this many lines, with an "Expand" button.
rtl bool true The button that switches the example to right to left.
center bool false Centers the content of the box.
source string the Blade written inside, base64 Filled in when the view is compiled; not meant to be passed. code wins over it.

Slots

Slot Description
default The example, rendered in the box; its Blade, as written, is the code shown under it.

Prefixes

Prefix Goes to
canvas: The box the example renders in.
code: The tk:code under it, and its own prefixes (code:copy:tooltip...).
rtl: The right-to-left button.

Customization

Classes and attributes on the tag go to the outer box; its border and rounding give way to classes passed on the tag. To reach an inner element, prefix the attribute (listed in the Reference above).

blade

Accessibility

The example is plain content in the page. The right-to-left button is named "Preview right to left" (translated), with a tooltip, and reports its state with aria-pressed. The code under it is a tk:code.

Behavior notes

  • The Blade is captured when the view is compiled, before Blade reads it, so it is the text as written in the file, with its common indentation removed. @php blocks and {{ }} show as written; nothing in it is evaluated twice.
  • A tk:preview written inside another one in the same file is not supported, and a tag with code or source (or :code, :source) is left as it is.
  • A <tk:preview> written inside a Blade comment or an @verbatim block is text, not a preview: nothing is captured there, and it does not take the closing tag of the next one.
  • The right-to-left button sets dir="rtl" on the box only, not on the page, and turns back with a second click. The box has wire:ignore.self, so a Livewire update keeps it right to left while the example inside it still updates.
  • No x-data wraps the example: components inside it keep their own state.
  • The box has data-toc-skip, so headings in an example stay out of a tk:toc of the page.