Theme
Version
GitHub PyPI Discord
On this page

Preview

Component examples, layouts, and metadata for command-owned preview pages. Experimental, so these names and the citry ext run preview commands may change in a minor release.

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.

Experimental

The preview extension, everything citry.ext.preview exports, and the citry ext run preview commands are experimental. They may change in a minor release without a deprecation period.

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.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

Variant class

One named example with display metadata and ordinary Python inputs.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

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.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

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.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

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.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

PreviewComponent class

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

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

PreviewVariant class

Display metadata for one variant, without its Python params.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

PreviewMetadata class

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

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

PreviewItem class

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

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

PreviewGroup class

One component's metadata and ordered preview items.

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

View source

PreviewPage class

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

Experimental

Part of the experimental citry.ext.preview extension, which may change in a minor release without a deprecation period. See PreviewExtension.

Citry version: 0.9.0