Theme
Version
GitHub PyPI Discord
On this page

Preview

Component examples, layouts, and metadata for command-owned preview pages.

View source

PreviewExtension class

Bases: Extension

Declare component previews and expose them only through CLI-owned servers.

Install with Citry(extensions=[PreviewExtension]). Components configure examples through a nested Preview class. Ordinary application adapters receive no routes from this extension.

View source

validate_config_fields function

validate_config_fields(fields: Mapping[str, Any], component: type[Component] | None = None) -> None
View source

file_path function

file_path(component: type[Component] | None, field: str, path: str | Path) -> Path

Resolve a file beside its declaration, retaining inherited provenance.

View source

previews function

previews(selection: Selection | None = None) -> tuple[_Preview, ...]

Resolve an ordered selection with fresh variant inputs on each call.

View source

variant function

variant(slug: str, label: str, description: str = '', params: Mapping[str, Any] | None = None, viewport: Viewport | None = None) -> Variant

Declare one preview variant with metadata and component or template params.

View source

Variant class

One named example with display metadata and ordinary Python inputs.

Parameters

  • slug str - Stable lowercase name, using letters, digits, and single hyphens.
  • label str - Human-readable example label.
  • description str - Plain-text explanation of the example.
  • params Mapping[str, Any] - Inputs for the component or variables for its preview template.
  • viewport Viewport | None - Optional browser dimensions overriding component defaults.
View source

Viewport class

Browser dimensions and pixel scale used to capture one variant.

Parameters

  • width int - CSS width from 1 through 8192 pixels.
  • height int - CSS height from 1 through 8192 pixels.
  • device_scale_factor float - Finite pixel scale greater than zero, at most four.
View source

Layout class

Wrap preview content with one template or component class.

Exactly one source is required. The layout receives preview and a named content slot. Component classes must belong to the rendering app.

Parameters

  • template str | None - Trusted inline Citry template source.
  • template_file str | Path | None - UTF-8 template path relative to the declaring class.
  • component type[Component] | None - Component class accepting preview metadata and content.
View source

PreviewError class

Bases: ValueError

A preview declaration, selection, or rendering request is invalid.

View source

PreviewComponent class

Display metadata for one component, without its live class or inputs.

View source

PreviewMetadata class

Component and variant metadata supplied to an example or variant layout.

View source

PreviewItem class

Variant metadata paired with lazily rendered content for a page layout.

View source

PreviewPage class

Ordered component groups supplied to a single-preview or gallery layout.

Citry version: 0.5.1